# 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](https://confluence.sbb.ch/display/EAPKB/Automated+WSL+and+Docker+Setup). You can then just run the following in WSL to generate a new ESTA Python project: ```shell 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: ```shell 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: ```shell copier update --skip-answered ``` ### Install Python If not already installed, install Python. The recommended way is to use [pyenv](https://github.com/pyenv/pyenv), which allows multiple parallel Python installations which can be automatically selected per project you're working on. ```shell # 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](https://confluence.sbb.ch/spaces/WSL/pages/2260505495/Automated+WSL+and+Docker+Setup) useful. ### Install Copier If not already installed get [Copier](https://copier.readthedocs.io/en/stable/). The easiest way is to install it in an existing WSL installation is using `pipx`: ```shell pipx install copier ``` ### Order a Bitbucket Repository Order a Bitbucket repository from the CLEW Portal 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: . ### (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: . ### (Optional) Order a Helm Repository If you want to deploy your code using Helm, order a "Helm" repository on Artifactory from the CLEW Portal: . **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. ```shell 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 ### Setup - Install Python (see instructions above). - Install Poetry according to . - Setup your environment: ```shell # 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 ```