A professional Python project template built step-by-step.
Project description
1. Setup environments:
conda create -n template python==3.9
conda activate template
To normally run the project, install package dependencies first:
pip install pip-tool
by compiling dev-requirements.in to avoid package installation dependencies:
pip-compile --strip-extras requirements/dev-requirements.in # --strip-extras flag controls <package>[extra] brackets are written into output dev-requirements.txt or not
Then, install dependencies:
pip install -r requirements/dev-requirements.txt
2. Install and build package:
2.1. To install the project and its dependencies into your current Python environment:
Note that, you use this when you want to make your project's code importable, runnable and testable on your own machine:
pip install -e .[dev,test]
2.2. To distribute and create self-contained package files (.whl, .tar.gz)
Note that, you use this when use want to release your package. You are ready to share your code with others. When you are finally ready to distribute your project to others, you can run the command that builds the .whl file you were originally looking for.
pip install build
Run the build command:
python -m build
This will create a /dist directory, and inside you will dinf your new .whl file, ready to be uploaded to PyPi.
3. Journey to a beautiful python template project:
- First, use pip-compile to automatically generate requirements.txt dependencies from a high-level requirements.in file. This uses in step setup environment for running the code in development mode.
- Second, use pyproject.toml for building and installing our whole project to a package (that files also includes all the tools' configuration as well)
- Third, related to version control, when we want to commit/push current implementation, the code needa pass our pre-commit hooks (we could test our hooks by running commands:
pre-commit run --all-files --verbose) - Fourth, calculating the test coverage using
pytest --cov=src tests/, the table will show:
Coverage Table Explanation:Name Stmts Miss Cover ----------------------------------------------------- src/my_package/calculator.py 19 0 100% src/my_package/cli.py 32 32 0% ----------------------------------------------------- TOTAL 79 60 24%Stmts: Total executable code lines in each fileMiss: Number of lines NOT executed during testsCover: Percentage of lines that were tested (Stmts - Miss) / Stmts * 100- Professional goal: Aim for 80%+ coverage, 90%+ is excellent
- Use
pytest --cov=src --cov-report=term-missing tests/to see which specific lines need testing
- Fifth, CI/CD (Continuous Integration/Continuous Deployment) automates testing, building, and deployment processes to ensure code quality and reliable releases. See CI/CD workflow documentation for details.
- Sixth, test coverage rate:
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 pyproject_boilerplate-0.1.1.tar.gz.
File metadata
- Download URL: pyproject_boilerplate-0.1.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccc8a3a9a4ba9b41073e4ad68d62a472dc738281a2fb072f0d54e252ecfd98e9
|
|
| MD5 |
07e91acf18ef938afcca970206f3a5af
|
|
| BLAKE2b-256 |
91bdd34211044230762c991cc7cfd830ee901285d045ce886ab850423ff3b057
|
File details
Details for the file pyproject_boilerplate-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyproject_boilerplate-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bd96e56e645b72dea32e83f4f9798356719c9d9f50bfe2954b743809b407a54
|
|
| MD5 |
e0c1fb12650bb34010b140256e86b6be
|
|
| BLAKE2b-256 |
b57c2d77af0b078808f02aa36470da3e6abc803cb681b58795bb6b78065382d6
|