django-twc-package
is the template for a Django package at The Westervelt Company. This template is a starting point for creating a new Django package that can be installed and used in other projects.
It is tailored to the needs of The Westervelt Company, but unlike our Django project template django-twc-project
, it is much more generic and thus should be useful for a wider audience.
This template is built using Copier and includes the following features:
- Modern Python project with only a
pyproject.toml
file mypy
anddjango-stubs
for static type checkingpytest
for testingcoverage
andpytest-cov
for test coveragemodel_bakery
for easy model creation in testspytest-django
for Django pytest helperspytest-randomly
andpytest-reverse
for keeping tests honestpytest-xdist
for parallel testing, because ain't nobody got time for a slow test suite
nox
for testing across multiple versions of Python and Django, linting, and formattingbumpver
for version bumping- Package can be configured for either Semantic Versioning or CalVer via Copier prompts
just
for running common development tasks- Automatic linting and formatting via
pre-commit
blacken-docs
becauseruff
doesn'tdjango-upgrade
for keeping Django up to date automaticallydjlint
for linting and formatting Django templatesruff
for blazingly fast formatting and lintingprettier
for formatting CSS, JavaScript, TypeScript, and YAMLvalidate-pyproject
for ensuring thatpyproject.toml
is validpretty-format-toml
vialanguage-formatters-pre-commit-hooks
for TOML formatting
- Documentation built with
Sphinx
,MyST-Parser
, and thefuro
theme- Includes a
.readthedocs.yml
file for deploying documentation to Read the Docs
- Includes a
- CI/CD with GitHub Actions
- Testing across multiple versions of Python and Django
- Type checking
- Code coverage
- Automatic publishing to PyPI when a new release is created
- Includes a check for the most recent test run on the
main
branch, ensuring that the package is only published if the tests pass - Published to PyPI using their new Trusted Publishers publishing mechanism
- Includes a check for the most recent test run on the
- Dependabot for automatic action version updates
To use this template, you will need to install Copier and then run the following command:
copier copy --trust gh:westerveltco/django-twc-package <destination>
Note
The --trust
flag is used to because this template uses copier-template-extensions
to simplify some of the Jinja templating. You cannot use this template without trusting it. Please review the files within the extensions
directory to see what is being done.
After running the above command, you will be prompted to fill in some information about your package. Once you have filled in the necessary information, Copier will generate the package for you.
Once the package has been generated, you should create or update the tests/conftest.py
file to include the following:
from __future__ import annotations
import logging
from django.conf import settings
from .settings import DEFAULT_SETTINGS
pytest_plugins = [] # type: ignore
def pytest_configure(config):
logging.disable(logging.CRITICAL)
settings.configure(
**DEFAULT_SETTINGS,
**TEST_SETTINGS,
)
TEST_SETTINGS = {}
tests.settings.DEFAULT_SETTINGS
contains some common default settings, specifically chosen to ensure a speedy test suite. Any settings that are specific to your package should be added to tests.conftest.TEST_SETTINGS
. By keeping these separate, it should allow for future updates to this template to be easily merged into your package.
Examples are provided in the examples
directory.
As this template is mainly for internal use at The Westervelt Company, we do not generally accept contributions from external sources. However, if you have any suggestions or issues, please feel free to open an issue or pull request.
django-twc-package
is licensed under the MIT License. See the LICENSE file for more information.