Parameter dependent tasks

140 views
Skip to first unread message

Danny Rohde

unread,
Sep 14, 2020, 9:39:45 PM9/14/20
to python-doit
Hello,

I have, I believe, a very simple use case: I want to create a task to build environment-specific docker images. I managed to put it together based on the tutorial and it largely works - except for the file dependencies.

It seems targets and actions happily accept the parameter, but I can't make the file dep paths dependent on the parameter. I'm pretty sure this is a fairly standard use case and that I'm missing something.

I've tried to look into the calculated dependencies, but have the same problem there to pass a parameter to calculate them based on the environment provided on the command line.

Below is what I'm trying to do. Can you please point me in the right direction to make the whole task (actions, target, file_dep) dynamic based on the parameter?

"""
def task_refresh_env():
"""Run script to refresh environment variables"""

def _create_env_files(task, environment, dependencies):
print(task, dependencies)
EnvironmentManagement.run(scope=environment, env_path='.envs/.global/.gitlab')

return {
'doc': "Generate .env files for Docker and Pycharm",
# 'file_dep': list(Path('.envs/.{environment}/').glob('.*')),
'file_dep': ['.envs/.{environment}/.django', '.envs/.{environment}/.traefik', ],
'targets': ['compose/{environment}/.env'],
'actions': [(_create_env_files,)],
'clean': True,
'params': [{'name': 'environment',
'short': 'e',
'type': str,
'choices': (('production', ''), ('staging', '')),
'default': 'production',
}],
'verbosity': 2,
'uptodate': [False], # for debugging
}
"""

Danny Rohde

unread,
Sep 15, 2020, 7:45:17 PM9/15/20
to python-doit
I've now solved it with automatically creating sub-tasks (https://pydoit.org/tasks.html#sub-tasks).

Going through the documentation, I think it could be a little bit clearer on when to use parameters and when to create tasks automatically. Also, it might be helpful to add the expected command output under the code blocks to make it easier to understand.

In case anyone has a better idea for the above use case, I'm open to hearing suggestions.

Thanks
Reply all
Reply to author
Forward
0 new messages