Reputation: 988
I have a monorepo and I want to have tasks at different levels (in the directory tree).
When I run pyinvoke at a deeper level, I want to have access to the tasks in the higher levels + the tasks in the current level. They can (should) be in different namespaces.
i.e.
repo_top-|
|_ tasks-|
| |_ __init__.py
| |_ install
|_apps-|
|_ tasks-|
| |_ __init__.py
|_ lambdas
If I am in the repo_top/apps directory (or lower) I should be able to say
invoke --list
and see a listing of the tasks in repo_top/tasks
AND repo_top/apps/tasks
I have it so
inv --list
Available tasks:
install.bootstrap-devx
inv --list
Available tasks:
lambdas.python-build-lambda
I've tried a few things but so far have not figured out how to make it so I see all the tasks if I am in the apps directory or lower.
What I want to see if I execute it in repo_top/apps
is something like:
inv --list
Available tasks:
install.bootstrap-devx
lambdas.python-build-lambda
Upvotes: 1
Views: 175
Reputation: 988
I did find a "hack" to make this work.
Create symbolic link to a unique file name at the higher levels
repo_top/
├── tasks/
│ ├── __init__.py
│ └── install.py
├── top_tasks (symbolic link to tasks)
└── apps/
└── tasks/
├── __init__.py
└── lambdas.py
In apps/tasks/lambdas.py (or any pyinvoke module including __init__py
) you can do something like:
project_top_dir = Path(__file__).parents[2]
sys.path.append(str(project_top_dir))
from top_tasks.utils import *
And all the modules in the top level tasks
directory will be available to that module. You could also do a more specific import other than *
You can do this in deeper trees as well if you want.
Upvotes: 0