A template for a python package.
Project description
Description
A production ready python library template
- Metadata and dependency information is stored in the pyproject.toml for compatibility with both pip and poetry.
- Flake8, pylint, isort, and pytest configurations are defined to be compatible with the black autoformatter.
- Pylint settings are based on the Google Python Style Guide and adapted for black compatibility.
- Linting tools run automatically before each commit using pre-commit, black, and isort.
- Test coverage reports are generated during every commit and pull request using coverage and pytest-cov. All reports are automatically uploaded and archived on codecov.io.
- Unit tests are written using pytest and static type checking is provided by mypy.
- Package releases to PyPI with dynamic versioning provided by bump2version begin automatically whenever a new tag is created in github.
- Sphinx documentation is automatically generated and deployed to github pages during every release.
- Release notes are automatically generated during every release using github actions.
Source code documentation
Installation
To install the package using pip:
pip install pytemplates_pypackage
To add the package as a dependency using poetry:
poetry add pytemplates_pypackage
Usage
From a .py file:
import pytemplates_pypackage
print(pytemplates_pypackage.__version__)
pytemplates_pypackage.greet(user="Jacob")
from pytemplates_pypackage import wish_farewell
wish_farewell(user="Jacob")
Developer Setup
Install the package using poetry:
poetry install
Install optional dependencies using the --extras flag:
poetry install --extras={environment}
Environments
test = [
"pytest",
"pytest-cov",
]
lint = [
"black",
"isort",
"flake8",
"pylint",
"mypy",
"pre-commit",
]
docs = [
"Sphinx",
"sphinx-rtd-theme",
]
# Includes all optional dependencies
dev = [
"pytest",
"pytest-cov",
"black",
"isort",
"flake8",
"pylint",
"mypy",
"pre-commit",
"Sphinx",
"sphinx-rtd-theme",
"bump2version",
]
Commands
-
make clean- Remove all build, testing, and static documentation files. -
make lint- Run the linting tools. Includes pre-commit hooks, black, isort, flake8, pylint, and mypy. -
make test- Run the tests using pytest. -
make check- Run the lint and test commands, followed by the clean command. -
make gen-docs- Generate Sphinx HTML documentation. -
make docs- Generate Sphinx HTML documentation and serve it to the browser. -
make pre-release increment={major/minor/patch}- Bump the version and create a release tag. Should only be run from the main branch. Passes the increment value to bump2version to create a new version number dynamically. The new version number will be added to _version_.py and pyproject.toml and a new commit will be logged. The tag will be created from the new commit.
Workflows
-
lint- Run the linting tools on every push/pull_request to the main branch. Includes pre-commit hooks, black, isort, flake8, pylint, and mypy. -
test- Run the tests on every push/pull_request to the main branch. Writes a coverage report using pytest-cov and uploads it to codecov.io. -
release- Build a package distribution, create a github release, and publish the distribution to PyPI whenever a new tag is created. Linting and testing steps must pass before the release steps can begin. Sphinx documentation is automatically published to the docs branch and hosted on github pages.
Releases
A release should consist of the following three steps from a clean, up to date, copy of the main branch:
-
make pre-release increment={major/minor/patch}- Commit the version number bump and create a new tag locally. The version number follows semantic versioning standards (major.minor.patch) and the tag is simply the version number prepended with a 'v'. -
git push- Update the main branch with only the changes from the version bump. Wait until the test and lint workflows have completed successfully before starting the release workflow. -
git push --tags- Publish the new tag to kick off the release workflow.
File Tree
.
├── docs/
├── LICENSE
├── Makefile
├── poetry.lock
├── pyproject.toml
├── README.md
├── src
│ └── pytemplates_pypackage
│ ├── core
│ │ ├── __init__.py
│ │ ├── module1.py
│ │ └── module2.py
│ ├── __init__.py
│ └── __version__.py
└── tests
├── __init__.py
├── test_module1.py
└── test_module2.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytemplates_pypackage-0.0.9.tar.gz.
File metadata
- Download URL: pytemplates_pypackage-0.0.9.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b4dd38c539d1fe6d4b5c9bc9f5c78166f798504bd30d17e39bfdf15382130a8
|
|
| MD5 |
5a5e3101f6020d58f968d1d6c3637379
|
|
| BLAKE2b-256 |
85b0cfa386d333cd64bc8e45427f4d9b20e49079d6e900cd2df8f239320e5d6d
|
File details
Details for the file pytemplates_pypackage-0.0.9-py3-none-any.whl.
File metadata
- Download URL: pytemplates_pypackage-0.0.9-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42c6827d9e02af303de61b1aee8d04558546bce59eee0d98c4961ba032c329ee
|
|
| MD5 |
413f36d289b6d3d3a72101d941f55c80
|
|
| BLAKE2b-256 |
5910838d700362acf913e2a9200531a19ef2ba16fc6b33c0bc0ca1d49e300085
|