A production ready python library template.
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, and isort 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.
- Documentation is built using mkdocs and mkdocstrings. Docs are automatically 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
To begin local development, clone the PyTemplates/typer_cli repository and use one of the following methods to build it. Commands should be executed from inside of the project home folder.
Using poetry
poetry install
Install optional dependencies using the --extras flag:
poetry install --extras=environment
Using pip
pip install .
Install optional dependencies using square brackets:
pip install .[environment]
Environments
test = [
"pytest",
"pytest-cov",
]
lint = [
"black",
"isort",
"flake8",
"pylint",
"mypy",
"pre-commit",
]
docs = [
"mkdocs",
"mkdocstrings",
"mkdocstrings-python",
"mkdocs-material",
]
# Includes all optional dependencies
dev = [
"pytest",
"pytest-cov",
"black",
"isort",
"flake8",
"pylint",
"mypy",
"pre-commit",
"mkdocs",
"mkdocstrings",
"mkdocstrings-python",
"mkdocs-material",
"bump2version",
]
Commands
-
make clean- Remove all build, testing, and static documentation files. -
make test- Run the tests using pytest. -
make lint- Run the linting tools. Includes pre-commit hooks, black, isort, flake8, pylint, and mypy. -
make check- Run the test and lint commands. -
make gen-docs- Generate HTML documentation. -
make docs- Generate 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
-
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. Tests run against python versions 3.8 and 3.9. Optional manual trigger in the github actions tab. -
lint- Run the linting tools on every push/pull_request to the main branch. Includes pre-commit hooks, black, isort, flake8, pylint, and mypy. Optional manual trigger in the github actions tab. -
docs- Build the documentation, publish to the docs branch, and release to github pages. Runs on a manual trigger in the github actions tab. -
release- Build a wheel distribution, build a docker image, create a github release, and publish to PyPI and Docker Hub whenever a new tag is created. Linting and testing steps must pass before the release steps can begin. Documentation is automatically published to the docs branch and hosted on github pages. All github release tags, docker image tags, and PyPI version numbers are in agreement with one another and follow semantic versioning standrads.
Releases
A release should consist of the following two steps from a tested, linted, and 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 the version number prepended with a 'v'. -
git push --follow-tags- Update the main branch with only the changes from the version bump. Publish the new tag and kick off the release workflow.
File Tree
.
├── docs
│ ├── code_reference
│ │ ├── module1.md
│ │ └── module2.md
│ ├── developer_guide
│ │ ├── commands.md
│ │ ├── developer_setup.md
│ │ ├── releases.md
│ │ └── workflows.md
│ ├── extras
│ │ ├── credits.md
│ │ └── file_tree.md
│ ├── index.md
│ └── user_guide
│ ├── installation.md
│ └── usage.md
├── LICENSE
├── Makefile
├── mkdocs.yml
├── 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
Credits
Other python package templates
- https://github.com/waynerv/cookiecutter-pypackage
- https://github.com/AllenCellModeling/cookiecutter-pypackage
Actions
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.2.1.tar.gz.
File metadata
- Download URL: pytemplates_pypackage-0.2.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
562ca663fb97dd1d6aaa1d8f2910feea82ad3b2e01d8c0042cf8da1953ff7033
|
|
| MD5 |
515105372cf313878fa0568509e3ef26
|
|
| BLAKE2b-256 |
83097ce9a6699d1c57bce50baa23fb6dd6b15c56a483049081df67822e0ffed7
|
File details
Details for the file pytemplates_pypackage-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pytemplates_pypackage-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.3 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 |
d85b0921cb1452819b882c7cf2bbe5a0bafd5fb60bd2584032e0fc73e9fbc77d
|
|
| MD5 |
ad363bedcaddc57ecaaec61365893606
|
|
| BLAKE2b-256 |
e143acfd3b06ea8c524c3a148e425ce3fde1e991b82f1c1e03a1fdf71e842441
|