ESTA Python Template
This is a template for Python-based projects. It allows to generate an exemplary setup and project structure including neat stuff like pre-commit-hooks, automated testing, type checking, CI/CD using Tekton, etc. The generated code is intended to be tailored to project needs.
Usage
Creating new projects
The expected way to use this template is to install the necessary prerequisites using Automated WSL and Docker Setup. You can then just run the following in WSL to generate a new ESTA Python project:
copier copy ssh://git@codessh.sbb.ch:7999/kd_esta_blueprints/esta-python-template.git my_project
This will create a new directory called my_project and generate a new project inside it.
If you already have an empty directory - for example from a new git repository - you can cange into that directory and run:
copier copy ssh://git@codessh.sbb.ch:7999/kd_esta_blueprints/esta-python-template.git .
Updating existing projects
In order to receive updates provided by this template, you can run the following command in your project directory:
copier update --skip-answered
Install Python
If not already installed, install Python. The recommended way is to use pyenv, which allows multiple parallel Python installations which can be automatically selected per project you're working on.
# Install Python if necessary
pyenv install 3.12
pyenv shell 3.12
Note
: If you start from scratch with Python development you might find Automated WSL and Docker Setup useful.
Install Copier
If not already installed get Copier.
The easiest way is to install it in an existing WSL installation is using pipx:
pipx install copier
Order a Bitbucket Repository
Order a Bitbucket repository from the CLEW Portal https://self.sbb-cloud.net/tools/bitbucket/repository and clone it.
(Optional) Order a Docker Repository
If you want to package your code in a Docker container order a "Docker" repository on Artifactory from the CLEW Portal: https://self.sbb-cloud.net/tools/artifactory.
(Optional) Order a PyPI Repository
If you want to share your code as Python library order a "Python" repository on Artifactory from the CLEW Portal: https://self.sbb-cloud.net/tools/artifactory.
(Optional) Order a Helm Repository
If you want to deploy your code using Helm, order a "Helm" repository on Artifactory from the CLEW Portal: https://self.sbb-cloud.net/tools/artifactory.
Note: When rendering the template, use the "local" Helm repository, e.g. "my-project.helm.local"!
Render Template
Now you can go to the freshly cloned repository and render the template by running Copier. You will be prompted to provide the required information. Once you rendered the template, follow the setup instructions in the rendered template.
copier copy ssh://git@codessh.sbb.ch:7999/kd_esta_blueprints/esta-python-template.git .
Developer's Guide
- Development of esta-python happens in this repository following a standard lean gitflow.
- Release: a release is a merge on main. This will trigger the corresponding Tekton-Pipeline which pushes a rendered version of the template to https://code.sbb.ch/projects/KD_ESTA_BLUEPRINTS/repos/esta-python/browse
Setup
- Install Python (see instructions above).
- Install Poetry according to https://python-poetry.org/docs/#installation.
- Setup your environment:
# Create venv and install all dependencies
make
# Cleanup venv
make clean
# Render template into current HEAD of esta-python
# Helpful when you want to see the diff to esta-python.
make render-in-esta-python
# Cleanup
make remove-rendered-template