This repo holds a minimalist boilerplate for boostrapping a new python project. It is intended for use with pyenv for python version management and venv
and Poetry for dependency management.
- Confirm that you have installed pyenv and use it to install the version of python specified in the
.python-version
file at the root of this repo. - Create a new virtual environment in this repo. This will create a folder called
venv
at the root of this repo that will be ignored by.gitignored
python -m venv venv
- Before we can use Poetry to install the project dependencies, we must install Poetry itself, as well as make sure our versions of
pip
andsetuptools
are up to date
venv/bin/pip install -U pip setuptools
venv/bin/pip install poetry
- Activate your new virtual environment. There are two ways to do this. Simply run
poetry shell
Or, if you would rather not create a nested shell, you can do it manually by running
source venv/bin/activate
See Poetry's docs for details on these two approaches
5. Install dependencies as specified in pyproject.toml
:
poetry install
- Install the included pre-commit hooks using
pre-commit
pre-commit install
You should see a success message pre-commit installed at .git/hooks/pre-commit
7. To verify that dependencies were installed successfully, you can try running pylint
against /src/hello_world.py
. Assuming you haven't made any changes, you should see a success message
pylint src/hello_world.py
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
- To verify that you can execute python code, you can run the script
python src/hello_world.py
This repo contains a minimal setup for automating code quality checks. It uses
- Pylint for static code analysis (aka linting)
- Black for code formatting
- isort for
import
statement sorting - pre-commit for pre-commit git hooks
pyproject.toml
- The main configuration file that powers Poetry. Among other things, it tracks the dependencies required by your project. Note that you generally should not be editing this file directly to add dependencies. Instead, usepoetry add my-dependency-name
poetry.lock
- This file is generated by Poetry to keep a deterministic record of exact dependency versions installed by Poetry. Changes to it should always be tracked. This file is primarily used when installing dependencies in the context of CI/CD workflows.pylintrc
- This contains configuration for Pylint. The one seen here contains default and was generating by runningpylint --generate-rcfile > .pylintrc
.python-version
- This file tellspyenv
which verison of Python should be used when working in this project.pre-commit-config.yaml
- Configuration forpre-commit
. This file specifies hooks that will run Pylint, black, and isort and only allow commits if those checks are successful