Vince's obnoxiously opinionated Python library cookie cutter
This assumes the following; that you:
- Are using Python 3.9
- Already have
cookiecutter
installed - Already have
poetry
installed - Are going to use VSCode
1
and 4
can be changed after you run this, but the other two are hard reqs.
The following tools are default installed and configured:
bandit
for checking source code bugsblack
so we can all stop arguing about code formattingisort
so we can all stop arguing about import ordermypy
for static analysisnox
to run tests and be a general task runnerpre-commit
to ensure pushed code doesn't suckpylint
for enforcing style rulespytest
to run the testspytest-cov
to measure test coveragepytest-it
so we can write tests spec-stylesafety
to check that our dependencies don't have CVEs
The output is a project directory with the library code in src
code layout. That is, the source packages you write are all under a src
directory. This also assumes you're writing type-stubs along-side your modules.
The tests live in their own directory and follow the same package name convention. There is also a tests/utils.py
module that provides some convenience wrappers around pytest-it
decorators (I think my version is more literate when reading the test source code).
my-project
├── .gitignore
├── .pre-commit-config.yaml
├── .vscode
│ └── settings.json
├── COPYING
├── LICENSE
├── README.rst
├── noxfile.py
├── poetry.lock
├── pyproject.toml
├── src
│ └── my_project
│ ├── __init__.py
│ └── __init__.pyi
└── tests
├── __init__.py
├── my_project
│ └── __init__.py
└── utils.py
5 directories, 14 files
cd your/projects/dir
cookiecutter https://github.com/vforgione/cookiecutter-py-lib
# or
cookiecutter https://gitlab.com/vforgione/cookiecutter-py-lib
User Configuration:
author_name
is your name; full, handle, whateverauthor_email
is your email addressproject_name
is the Title Case Name of Your Projectproject_slug
is a generated value; e.g.My Project
becomesmy-project
package_name
is a generated value; e.g.My Project
becomesmy_project
short_description
is a short description of the projectlicense
is a choice of the MIT license or the GNU GPL v3.0 license
A note about licenses: I use MIT when I don't care about keeping the work out of the hands of filthy corporate types. GNU GPL v3.0 is the license to choose to ensure that the code is forever open.