Contributing#
Environment Setup#
pipx
This documentaion uses pipx to
install and manage non-project command line tools like hatch
and
pre-commit
. If you don't already have pipx
installed, make sure to
see their documentation.
If you prefer not to use pipx
, you can use pip
instead.
-
Install hatch
pre-commit
Hatch will attempt to set up pre-commit hooks for you using pre-commit. If you don't already, make sure to install pre-commit as well:
pipx install pre-commit
-
Build the Virtual Environment
-
If you need to, you can link a hatch virtual environment to your IDE. They can be located by name with the
env find
command: -
Activate the Virtual Environment
Using Hatch#
Hatch Cheat Sheet#
Command Description | Command | Notes |
---|---|---|
Run Tests | hatch run cov |
Runs tests with pytest and coverage |
Run Formatting | hatch run lint:fmt |
Runs ruff code formatter |
Run Linting | hatch run lint:all |
Runs ruff and mypy linters / type checkers |
Run Type Checking | hatch run lint:typing |
Runs mypy type checker |
Update Requirements Lock Files | hatch run gen:reqs |
Updating lock file using pip-compile |
Upgrade Dependencies | hatch run gen:reqs-update |
Updating lock file using pip-compile and --update flag |
Serve the Documentation | hatch run docs:serve |
Serve the documentation using MkDocs |
Run the pre-commit Hooks |
hatch run lint:precommit |
Runs the pre-commit hooks on all files |
Hatch Explanation#
Hatch is a Python package manager. Its most basic use is as a standardized build-system. However, hatch also has some extra features which this project takes advantage of. These features include virtual environment management and the organization of common scripts like linting and testing. All the operations in hatch take place in one of its managed virtual environments.
Hatch has a variety of environments, to see them simply ask hatch:
Standalone
βββββββ³ββββββββββ³βββββββ³βββββββββββββββββββ³ββββββββββββββββββββββββββββββ³βββββββ
β Naβ¦ β Type β Feaβ¦ β Dependencies β Environment variables β Scrβ¦ β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β deβ¦ β pip-coβ¦ β all β β β cov β
β β β β β β test β
βββββββΌββββββββββΌβββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββΌβββββββ€
β doβ¦ β pip-coβ¦ β β markdown-callouβ¦ β β buiβ¦ β
β β β β markdown-exec β β gh-β¦ β
β β β β mkdocs β β serβ¦ β
β β β β mkdocs-click β β β
β β β β mkdocs-exclude-β¦ β β β
β β β β mkdocs-gen-files β β β
β β β β mkdocs-literateβ¦ β β β
β β β β mkdocs-material β β β
β β β β mkdocs-section-β¦ β β β
β β β β mkdocstrings β β β
β β β β mkdocstrings-pyβ¦ β β β
β β β β pymdown-extensiβ¦ β β β
βββββββΌββββββββββΌβββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββΌβββββββ€
β gen β virtual β β β β relβ¦ β
βββββββΌββββββββββΌβββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββΌβββββββ€
β liβ¦ β pip-coβ¦ β β mypy>=1.6.1 β β all β
β β β β ruff~=0.1.7 β β fmt β
β β β β β β preβ¦ β
β β β β β β styβ¦ β
β β β β β β typβ¦ β
βββββββΌββββββββββΌβββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββΌβββββββ€
β teβ¦ β pip-coβ¦ β all β freezegun~=1.2.1 β PUSHOVER_PUSH_TOKEN=placehβ¦ β cov β
β β β β pytest-cov~=4.0β¦ β PUSHOVER_PUSH_USER=placehoβ¦ β test β
β β β β pytest-mock~=3.β¦ β β β
β β β β pytest-vcr~=1.0β¦ β β β
β β β β pytest-xdist~=3β¦ β β β
β β β β pytest~=7.3.1 β β β
βββββββ΄ββββββββββ΄βββββββ΄βββββββββββββββββββ΄ββββββββββββββββββββββββββββββ΄βββββββ
Matrices
ββ³βββββ³ββββ³βββ³βββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββ³β
ββ Tβ¦ β β¦ β β Dependencβ¦ β Environment variables ββ
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
ββ pβ¦ β β¦ β β freezegunβ¦ β PUSHOVER_PUSH_TOKEN={env:PUSHOVER_PUSH_TOKEN:plaβ¦ ββ
ββ β β¦ β β pytest-coβ¦ β PUSHOVER_PUSH_USER={env:PUSHOVER_PUSH_USER:placeβ¦ ββ
ββ β β¦ β β pytest-moβ¦ β ββ
ββ β β¦ β β pytest-vcβ¦ β ββ
ββ β β¦ β β pytest-xdβ¦ β ββ
ββ β β β pytest~=7β¦ β ββ
ββ΄βββββ΄ββββ΄βββ΄βββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββ΄β
That above command will tell you that there are five environments that you can use:
default
docs
gen
lint
test
Each of these environments has a set of commands that you can run. To see the commands for a specific environment, run:
Standalone
βββββββββββ³ββββββββββββββ³βββββββββββ³ββββββββββ
β Name β Type β Features β Scripts β
β‘βββββββββββββββββββββββββββββββββββββββββββββ©
β default β pip-compile β all β cov β
β β β β test β
βββββββββββ΄ββββββββββββββ΄βββββββββββ΄ββββββββββ
Here we can see that the default
environment has the following commands:
cov
test
The one that we're interested in is cov
, which will run the tests
for the project.
Since cov
is in the default environment, we can run it without
specifying the environment. However, to run the serve
command in the
docs
environment, we need to specify the environment:
You can see what scripts are available using the env show
command
Standalone
ββββββββ³ββββββββββββββ³ββββββββββββββββββββββββ³ββββββββββββ
β Name β Type β Dependencies β Scripts β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β docs β pip-compile β markdown-callouts β build β
β β β markdown-exec β gh-deploy β
β β β mkdocs β serve β
β β β mkdocs-click β β
β β β mkdocs-exclude-search β β
β β β mkdocs-gen-files β β
β β β mkdocs-literate-nav β β
β β β mkdocs-material β β
β β β mkdocs-section-index β β
β β β mkdocstrings β β
β β β mkdocstrings-python β β
β β β pymdown-extensions β β
ββββββββ΄ββββββββββββββ΄ββββββββββββββββββββββββ΄ββββββββββββ
Committing Code#
This project uses pre-commit to run a set of checks on the code before it is committed. The pre-commit hooks are installed by hatch automatically when you run it for the first time.
This project uses semantic-versioning standards, managed by semantic-release.
Releases for this project are handled entirely by CI/CD via pull requests being
merged into the main
branch. Contributions follow the gitmoji standards
with conventional commits.
While you can denote other changes on your commit messages with gitmoji, the following commit message emoji prefixes are the only ones to trigger new releases:
Emoji | Shortcode | Description | Semver |
---|---|---|---|
π₯ | :boom: | Introduce breaking changes. | Major |
β¨ | :sparkles: | Introduce new features. | Minor |
π | :bug: | Fix a bug. | Patch |
π | :ambulance: | Critical hotfix. | Patch |
π | :lock: | Fix security issues. | Patch |
Most features can be squash merged into a single commit on a pull-request. When merging multiple commits, they will be summarized into a single release.
If you're working on a new feature, your commit message might look like:
Bug fix commits would look like this:
If you're working on a feature that introduces breaking changes, your commit message might look like:
Other commits that don't trigger a release might look like this:
π Documentation Update Description
π· CI/CD Update Description
π§ͺ Testing Changes Description
π Moving/Renaming Description
β¬οΈ Dependency Upgrade Description
Pre-Releases#
semantic-release supports pre-releases. To trigger a pre-release, you
would merge your pull request into an alpha
or beta
branch.
Specific Release Versions#
In some cases you need more advanced control around what kind of release you
need to create. If you need to release a specific version, you can do so by creating a
new branch with the version number as the branch name. For example, if the
current version is 2.3.2
, but you need to release a fix as 1.2.5
, you
would create a branch named 1.2.x
and merge your changes into that branch.
See the semantic-release documentation for more information about branch based releases and other advanced release cases.