Basic python project setup
This project assumes using Unix-like operating system with Python, git and GNU Make installed. It assumes using
the default python for the machine, this can be changed by setting the PYTHON
variable. To setup a project, copy
all the files to desired directory and run make dev
.
It assumes the following dev environment:
- Makefile is used for automation of the dev workflow. The
make
command runs all the code checks. - Git is used for version control, if it is not initialized,
make dev
will rungit init
. - Python's venv + pip manage the virtual environments and dependencies.
The environment can be loaded using the
. scripts/shell.sh
command. - The .env file holds environment variables, and is loaded using python-dotenv.
- pre-commit runs pre-commit-hooks for validating each commit.
- pytest is used for running the unit tests. It is set up to fail fast and run the previously failed tests first. pytest-cov generates the test coverage report.
- The code is auto-formatted using black and isort.
- flake8 is used as code linter, but it ignores the stylistic issues that are fixed by Black.
- mypy is used for static code analysis and type checking.
- Each of the steps is configured to fail fast in case of any error.
How to use it.
-
Click the "Use this template" button in GitHub to create a new repository
OR
copy all the files to your local machine, to the directory where you want to start a new project.
-
Run
make dev
to setup the dev environment. If you want to use a specific version of python, usemake dev PYTHON=python3.8
, wherePYTHON=
should point to the name of the Python executable or path leading to it.
Additionally:
- Any time you edit
requirements.txt
orrequirements-dev.txt
, runmake update
to update all the dependencies. - To test the code run
make
ormake allchecks
is you want to be more specific. For running individually the black and isort, linter, mypy, or unit tests, usemake stylecheck
,make lint
,make typecheck
,make test
respectively. If you want to manually fix code formatting, runmake stylefix
.make coverage
would generate the test coverage report. To manually run the pre-commit hooks, runmake precommit
.