This tool auto generates (customizable) pydantic v2 Code to implement the BO4E-Schemas.
Project description
Python Template Repository including a tox.ini
, Unittests&Coverage, Pylint & MyPy Linting Actions and a PyPI Publishing Workflow
This is a template repository. It doesn't contain any useful code but only a minimal working setup for a Python project including:
- a basic project structure with
- tox.ini
- requirements.in
- and a requirements.txt derived from it
- an example class
- an example unit test (using pytest)
- ready to use Github Actions for
- pytest
- code coverage measurement (fails below 80% by default)
- pylint (only accepts 10/10 code rating by default)
- mypy (static type checks where possible)
- black code formatter check
- isort import order check
- codespell spell check (including an ignore list)
- ready-to-use publishing workflow for pypi (see readme section below)
By default, it uses Python version 3.12.
How to use this Repository on Your Machine
This introduction assumes that you have tox installed already (
see installation instructions) and that a .toxbase
environment
has been created.
.toxbase
is a project independent virtual environment-template for all the tox environments on your machine. If anything is weird during the tox installation or after the installation, try turning your computer off and on again before getting too frustrated.
Also on new windows machines it is possible that the execution policy is set to restricted and you are not allowed execute scripts. You can find detailed information here.
If this is the case, clone this repository and create the dev
environment on your machine.
tox -e dev
How to use with PyCharm
- Create a new project using existing sources with your local working copy of this repository as root directory. Choose
the path
your_repo/.tox/dev/
as path of the "previously configured interpreter". - Set the default test runner of your project to pytest.
- Set the
src
directory as sources root (via right click, docs). - Set the working directory of the unit tests to the project root (instead of the unittest directory).
How to use with VS Code
- Open the folder with VS Code.
- Select the python interpreter (official docs) which is created by tox. Open the command pallett with
CTRL + P
and typePython: Select Interpreter
. Select the interpreter which is placed in.tox/dev/Scripts/python.exe
under Windows or.tox/dev/bin/python
under Linux and macOS. - Setup pytest and pylint. Therefore we open the file
.vscode/settings.json
which should be automatically generated during the interpreter setup. Insert the following lines into the settings:
{
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"pythonTestExplorer.testFramework": "pytest",
"python.testing.pytestArgs": ["unittests"],
"python.linting.pylintEnabled": true
}
- Create a
.env
file and insert the following line
For Windows:
PYTHONPATH=src;${PYTHONPATH}
For Linux and Mac:
PYTHONPATH=src:${PYTHONPATH}
This makes sure, that the imports are working for the unittests. At the moment I am not totally sure that it is the best practise, but it's getting the job done.
- Enjoy 🤗
Publishing on PyPI
This repository contains all necessary CI steps to publish any project created from it on PyPI. It uses the trusted publishers workflow as described in the official Python documentation. It just requires some manual adjustments/settings depending on your project:
- Fill out the metadata in the
pyproject.toml
; Namely the package name and the dependencies which should be in sync with yourrequirements.in
. - Uncomment the lines in
.github/workflows/python-publish.yml
- Create a new environment in your GitHub repository and call it
release
. - Set up a new trusted publisher in your PYPI account.
- PyPI Project Name: The name which you defined in the
pyproject.toml
is the name of the project which you have to enter here. - Owner: The GitHub organization name or GitHub username that owns the repository
- Repository name: The name of the GitHub repository that contains the publishing workflow
- Workflow name: The filename of the publishing workflow. This file should exist in the .github/workflows/ directory in the repository configured above. Here in our case:
python-publish.yml
- Environment name: The name of the GitHub Actions environment that the above workflow uses for publishing. Here in our case:
release
- PyPI Project Name: The name which you defined in the
- Now create a release by clicking on "Create new release" in the right Github sidebar (or visit
github.com/your-username/your-reponame/releases/new
). This should trigger the workflow (see the "Actions" tab of your repo). - Check if the action failed. If it succeeded your PyPI account should now show the new project. It might take some minutes until the package can be installed via
pip install packagename
because the index has to be updated. - Now create another PyPI token with limited scope and update the Github repository secret accordingly.
Contribute
You are very welcome to contribute to this template repository by opening a pull request against the main branch.
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
File details
Details for the file bo4e_python_generator-0.0.13.tar.gz
.
File metadata
- Download URL: bo4e_python_generator-0.0.13.tar.gz
- Upload date:
- Size: 24.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee65106b756dfa4ae1ed325fca1d488e4b7f81338cf6786ec337843886222bb5 |
|
MD5 | d3b566033b3b64dd26532df10c3adfd9 |
|
BLAKE2b-256 | 964726b25b9b70b266803fe323d4fb8a10cc33d7827b54daccd437632b2a3b09 |
File details
Details for the file bo4e_python_generator-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: bo4e_python_generator-0.0.13-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d3488838a004f08a21f217c6a9d727947ad207255850773256527485bd43a03 |
|
MD5 | c77dd4863dec110cf5ca6b3431c2dead |
|
BLAKE2b-256 | 7fc9b8b1d25b5058febd4832d3363fcd454a5d7c1701a6e58f0ab905e01989a8 |