Common invoke tasks wrapper/library
pip install prettyrepo==0.0.0
This is a cookie-cutter project for the way I like to set up a Python repo.
Components:
LICENSE.md
file and CHANGELOG.md
changelog templatePipfile
and Pipfile.lock
)setup.py
, setup.cfg
, MANFIEST.in
for packaging.flake8
file.gitignore
set up to include runConfigurations
to share PyCharm IDE configpytest.ini
to configure xunit XML outputpytest-flake8
to run flake8 as part of the unit testing and get JUnit XML output.coveragerc
.rst
README
and docs directory for sphinx documentationsemver.txt
to drive the versiontox
to test installation of the package on multiple python versions
Dockerfile
to run tox in a dockerized environment rather than manage multiple installations in the test environment.gitlab-ci.yml
for CI using the GitLab runner
pytest --flake8
with some config to get xunit xml output which it uploads so it can be viewed in the pipeline report^TOTAL.+?(\d+.\d+\%)$
Maybe one day part of this repo will be to help automate actually setting things up.
pipenv run pip freeze > docs/requirements.txt
c814c69... Add badges
All of the functionality as invoke with a smidge more flexibility (maybe just for me?) than something like invocations.
In general, this project (as well as invoke), give an OS-agnostic solution for automating common commands during development (cleaning build files, running unit tests, etc.). Similar to how a Makefile might be used, prettyrepo makes it so that with a small set of commands you can run any typical task. Furthermore, you can have configurable arguments for each of those tasks being run (see example).
This project introduces a TaskManager
so every available task can be tweaked as desired and persistent for a project. Reference tasks.py for this project's own tasks file.
from invoke import task
from prettyrepo import TaskManager
from prettyrepo.utils import run_unittest
from prettyrepo.utils import get_python_cleans
# Create a TaskManager that knows the root of your project
mgr = TaskManager(source_root='prettyrepo', tasks_module=__name__)
# Add tasks from the "task library" or a simple command (by specifying the cmd kwarg)
mgr.add_task('clean', cleans=get_python_cleans())
mgr.add_task('test', lib='unittest', dir_='tests')
mgr.add_task('cov', aliases=['cover'], lib='coverage', func=run_unittest, dir_='tests')
mgr.add_task('lint', aliases=['flake8'], cmd='flake8 prettyrepo', doc='Run flake8 lints.')
# You can use the normal invoke task decorator in conjunction with prettyrepo tasks.
@task(name='bleh', help={'times': 'number of times to say blah'})
def blah(_, times=1):
"""Say blah."""
print('\n'.join(['blah']*times))
ns = mgr.namespace
With this in your tasks.py
file in the root of your repository, you can run
inv <command> [-h] [<command options...>]
Where -h
is available to show the help message. For example, running inv clean -h
yields:
Docstring:
Clean unnecessary files.
Options:
-l INT, --level=INT the level of "cleanliness" [0-2], default 1
-v INT, --verbosity=INT how verbose information to log to the console [0-3], default 1
Where -l
and -v
can be used to specify what the clean task does (the higher the level, the more files it removes - i.e. venv, dist files; the higher the verbosity, the more info it logs):
c77323a... add cookie cutter files