pyconcrete icon indicating copy to clipboard operation
pyconcrete copied to clipboard

Compatibility with `imp.find_module` for celery

Open john-hadron opened this issue 7 years ago • 1 comments
trafficstars

First, thanks for the great library!

I added celery to the example project you had, and celery's autodiscover_tasks failed to discover my celery tasks.pye files.

Turns out that celery uses the builtin imp package to check if tasks.py exists in all django apps, at app/tasks.py. In particular, it uses imp.find_module() described here https://docs.python.org/2/library/imp.html#imp.find_module

Sadly, imp.find_module doesn't find .pye files, such as tasks.pye.

Celery code: https://github.com/celery/celery/blob/120770929f4a37c5373a378b75b5c41a99702af9/celery/utils/imports.py#L90

My workaround was to use pyconcrete-admin.py ... -i tasks.py and have tasks.py simply star import an encrypted module (as no one will try to find that one ;) ).

Again, no pressure, but it will be great if we could have a hook for that library as well.

I'm just signaling this here, with a keyword Celery in case anyone else tumbles on this issues.

john-hadron avatar Dec 29 '17 06:12 john-hadron

Per the document about Import Hook(MetaPath) mechanism (pyconcrete implementation) https://www.python.org/dev/peps/pep-0302/#integration-with-the-imp-module

Basically imp.find_module() can't integrate with Import Hook(MetaPath) by now. If we want to patch imp.find_module() at runtime, I am not sure it's a good idea, need to check all python version implementation about imp.find_module(), need more investigation.

Falldog avatar Jan 03 '18 08:01 Falldog