taskiq-python/taskiq

Tasks pattern includes .tox and other directories

stinovlas opened this issue · 0 comments

I wanted to use task autodetection, but it failed because the worker tried to load packages from .tox in my working directory:

taskiq worker --fs-discover --tasks-pattern 'mypackage/**/*.py' mypackage.tasks:broker

This actually fails with uncaught exception, because .tox.py311.lib.python3.11.site-packages.mypackage.tasks is not a valid module path.

The problems seems to be that taskiq.cli.utils.import_tasks uses rglob to generate files list. There is no way for me to exclude directories I don't want to be traversed. Using Path().glob(pattern) instead of Path().rglob(pattern) looks like a reasonable fix – that way everyone can choose whether they want to prefix their pattern with **/ or not.

This would be a breaking change. It makes sense, but is breaking nonethless. I would personally be for implementing it, but the call is @s3rius's, not mine. If we are changing it anyway, I'd also suggest the possibility to add multiple task patterns (by repeating the option) and search all of them.

If you agree with the proposal, I'll handle the implementation.