Skip to content

add task attribute 'inherits' to take over declarations of other tasks - #493

Open
SahilRajputdotexe wants to merge 1 commit into
pydoit:masterfrom
SahilRajputdotexe:feat/task-inherits
Open

SahilRajputdotexe wants to merge 1 commit into
pydoit:masterfrom
SahilRajputdotexe:feat/task-inherits

Conversation

@SahilRajputdotexe

Copy link
Copy Markdown

Tasks that share file dependencies, options or up-to-date checks currently have to repeat them in every task. This adds an inherits attribute (a list or tuple of task names) so a task can take on the declarations of other tasks.

def task_lint():
    return {
        'actions': ['flake8 src'],
        'file_dep': ['setup.cfg'],
        'params': [{'name': 'level', 'long': 'level', 'default': 'warning'}],
    }

def task_test():
    return {
        'actions': ['pytest tests'],
        'inherits': ['lint'],
    }

test now also depends on setup.cfg and accepts --level.

What gets inherited: file_dep and calc_dep are combined, task_dep and setup keep the task's own entries first and then the parents', uptodate checks are added (an inherited config_changed is recorded for the inheriting task), params, getargs and meta are merged by name with the task's own entry winning, and doc and verbosity come from the first parent that has one when the task has none. actions, targets, clean, teardown, title, io, watch and pos_arg are never inherited and parents are never modified. Parents can be sub-tasks or group tasks, chains work, and list, info, help, TaskControl and create_after tasks all see the resolved tasks.

An unknown name raises InvalidTask and a cycle raises InvalidDodoFile.

I did not find an existing issue for this. I added docs in doc/tasks.rst, a sample and a CHANGES entry.

Tests are in tests/test_task_inherits.py. rut, doit pyflakes and doit codestyle pass locally apart from one macOS path-case failure in test_action.py that is unrelated, and the full CI matrix passes on my fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant