Skip to content

Tasks pattern includes .tox and other directories #256

@stinovlas

Description

@stinovlas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions