Parcourir la source

celery command can now take extensions using setuptools entrypoint 'celery.commands'

Ask Solem il y a 12 ans
Parent
commit
d0a5b91373
1 fichiers modifiés avec 14 ajouts et 1 suppressions
  1. 14 1
      celery/bin/celery.py

+ 14 - 1
celery/bin/celery.py

@@ -41,7 +41,6 @@ command_classes = (
     ('Utils', ['purge', 'list', 'migrate', 'call', 'result', 'report'], None),
 )
 
-
 class Error(Exception):
 
     def __init__(self, reason, status=EX_FAILURE):
@@ -59,6 +58,20 @@ def command(fun, name=None, sortpri=0):
     return fun
 
 
+def get_extension_commands(namespace='celery.commands'):
+    try:
+        from pkg_resources import iter_entry_points
+    except ImportError:
+        return
+
+    for ep in iter_entry_points(namespace):
+        for attr in ep.attrs:
+            command(symbol_by_name(':'.join([ep.module_name, attr])),
+                    name=ep.name)
+get_extension_commands()
+
+
+
 class Command(BaseCommand):
     help = ''
     args = ''