Skip to content

Commit 746ac5d

Browse files
authored
🧙‍♂️Initial Project Setup (#1)
1 parent f4e7176 commit 746ac5d

15 files changed

+153
-203
lines changed

.github/workflows/formatting.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "Formatting"
22

3-
on: [push]
3+
on: [push, pull_request]
44
jobs:
55
black:
66
runs-on: ${{ matrix.os }}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Integration Tests"
2+
3+
on: [push, pull_request]
4+
jobs:
5+
pytest:
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
matrix:
9+
python-version: ["3.11", "3.12"]
10+
os: [ubuntu-latest]
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install Dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install tox
21+
- name: Log into registry
22+
# GHCR_PAT is a personal access token for the Github Container Registry; You can create it using the following steps:
23+
# 1) Go to https://github.com/settings/tokens
24+
# 2) Create a new token (classic as of 2025-02-02)
25+
# 3) Select the following scopes: read:packages
26+
# GHCR_USR is the username for the Github Container Registry; it has to match the PAT and is the username of the Github account that created the PAT
27+
# You can update the tokens in the repository settings:
28+
# https://github.com/Hochfrequenz/TransformerBeeClient.py/settings/secrets/actions/GHCR_PAT
29+
# https://github.com/Hochfrequenz/TransformerBeeClient.py/settings/secrets/actions/GHCR_USR
30+
# Tokens will expire 2025-02-01
31+
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ secrets.GHCR_USR }} --password-stdin
32+
- name: Start containers
33+
run: docker-compose -f "integrationtests/docker-compose.yml" up -d
34+
- name: Run the Integration Tests via Tox
35+
run: |
36+
tox -e integrationtests

.github/workflows/python-publish.yml

+51-51
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,58 @@
55
# This workflow uploads a Python Package using Twine when a release is created.
66
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
77

8-
# name: Upload Python Package
8+
name: Upload Python Package
99

10-
# on:
11-
# release:
12-
# types: [created, edited]
10+
on:
11+
release:
12+
types: [ created, edited ]
1313

14-
# jobs:
15-
# tests:
16-
# if: startsWith(github.ref, 'refs/tags/v')
17-
# runs-on: ${{ matrix.os }}
18-
# strategy:
19-
# matrix:
20-
# python-version: ["3.12"]
21-
# os: [ubuntu-latest]
22-
# steps:
23-
# - uses: actions/checkout@v4
24-
# - name: Set up Python ${{ matrix.python-version }}
25-
# uses: actions/setup-python@v5
26-
# with:
27-
# python-version: ${{ matrix.python-version }}
28-
# - name: Install tox
29-
# run: |
30-
# python -m pip install --upgrade pip
31-
# pip install tox
32-
# - name: Run tox
33-
# run: |
34-
# tox
14+
jobs:
15+
tests:
16+
if: startsWith(github.ref, 'refs/tags/v')
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
python-version: [ "3.12" ]
21+
os: [ ubuntu-latest ]
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Install tox
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install tox
32+
- name: Run tox
33+
run: |
34+
tox
3535
36-
# build-n-publish:
37-
# name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
38-
# runs-on: ubuntu-latest
39-
# # Specifying a GitHub environment, # Specifying a GitHub environment, which is strongly recommended by PyPI: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
40-
# # you have to create an environment in your repository settings and add the environment name here
41-
# environment: release
42-
# permissions:
43-
# # IMPORTANT: this permission is mandatory for trusted publishing
44-
# id-token: write
45-
# needs: tests
46-
# steps:
47-
# - uses: actions/checkout@v4
48-
# - name: Set up Python
49-
# uses: actions/setup-python@v5
50-
# with:
51-
# python-version: ${{ matrix.python-version }}
52-
# - name: Install dependencies
53-
# run: |
54-
# python -m pip install --upgrade pip
55-
# pip install -r dev_requirements/requirements-packaging.txt
56-
# - name: Build wheel and source distributions
57-
# run: |
58-
# python -m build
59-
# - name: Publish distribution 📦 to PyPI
60-
# if: startsWith(github.ref, 'refs/tags/v')
61-
# uses: pypa/gh-action-pypi-publish@release/v1
36+
build-n-publish:
37+
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
38+
runs-on: ubuntu-latest
39+
# Specifying a GitHub environment, # Specifying a GitHub environment, which PyPI strongly recommends: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
40+
# you have to create an environment in your repository settings and add the environment name here
41+
environment: release
42+
permissions:
43+
# IMPORTANT: this permission is mandatory for trusted publishing
44+
id-token: write
45+
needs: tests
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Set up Python
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install -r dev_requirements/requirements-packaging.txt
56+
- name: Build wheel and source distributions
57+
run: |
58+
python -m build
59+
- name: Publish distribution 📦 to PyPI
60+
if: startsWith(github.ref, 'refs/tags/v')
61+
uses: pypa/gh-action-pypi-publish@release/v1
6262

.github/workflows/unittests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "Unittests"
22

3-
on: [push]
3+
on: [push, pull_request]
44
jobs:
55
pytest:
66
runs-on: ${{ matrix.os }}

README.md

+10-143
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,17 @@
1-
# Python Template Repository including a `tox.ini`, Unittests&Coverage, Pylint & MyPy Linting Actions and a PyPI Publishing Workflow
1+
# transformer.bee Client (Python)
22

3-
<!--- you need to replace the `organization/repo_name` in the status badge URLs --->
3+
![Unittests status badge](https://github.com/Hochfrequenz/TransformerBeeClient.py/workflows/Unittests/badge.svg)
4+
![Coverage status badge](https://github.com/Hochfrequenz/TransformerBeeClient.py/workflows/Coverage/badge.svg)
5+
![Linting status badge](https://github.com/Hochfrequenz/TransformerBeeClient.py/workflows/Linting/badge.svg)
6+
![Black status badge](https://github.com/Hochfrequenz/TransformerBeeClient.py/workflows/Formatting/badge.svg)
47

5-
![Unittests status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Unittests/badge.svg)
6-
![Coverage status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Coverage/badge.svg)
7-
![Linting status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Linting/badge.svg)
8-
![Black status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Formatting/badge.svg)
8+
This library is a Python HTTP client for transformer.bee aka edifact-bo4e-converter.
99

10-
This is a template repository.
11-
It doesn't contain any useful code but only a minimal working setup for a Python project including:
10+
It allows you to convert EDIFACT messages to BO4E and vice versa by speaking to Hochfrequenz's transformer.bee service.
11+
Note that the actual conversion happens in the transformer.bee service/backend, this library only provides a convenient way to use its API.
1212

13-
- a basic **project structure** with
14-
- tox.ini
15-
- `pyproject.toml` where the project metadata and dependencies are defined
16-
- and a requirements.txt derived from it
17-
- an example class
18-
- an example unit test (using pytest)
19-
- ready to use **Github Actions** for
20-
- [pytest](https://pytest.org)
21-
- [code coverage measurement](https://coverage.readthedocs.io) (fails below 80% by default)
22-
- [pylint](https://pylint.org/) (only accepts 10/10 code rating by default)
23-
- [mypy](https://github.com/python/mypy) (static type checks where possible)
24-
- [black](https://github.com/psf/black) code formatter check
25-
- [isort](https://pycqa.github.io/isort/) import order check
26-
- [codespell](https://github.com/codespell-project/codespell) spell check (including an ignore list)
27-
- ready-to-use publishing workflow for pypi (see readme section below)
28-
29-
By default, it uses Python version 3.12.
30-
31-
This repository uses a [`src`-based layout](https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/).
32-
This approach has many advantages and basically means for developers, that all business logic lives in the `src` directory.
33-
34-
## How to use this Repository on Your Machine
35-
36-
This introduction assumes that you have tox installed already (
37-
see [installation instructions](https://tox.readthedocs.io/en/latest/installation.html)) and that a `.toxbase` environment
38-
has been created.
39-
`.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.
40-
41-
### Powershell restrictions on Windows
42-
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](https://learn.microsoft.com/de-de/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.3).
43-
44-
The quickest way to solve this problem: Open an Administrator Powershell (e.g. Windows PowerShell App)
45-
```ps
46-
Set-ExecutionPolicy -ExecutionPolicy AllSigned
47-
```
48-
and try again (with your regular user, not as admin).
49-
50-
### Creating the project-specifc dev environment.
51-
If all problems are solved and you're ready to start:
52-
1. clone the repository, you want to work in
53-
2. create the `dev` environment on your machine. To do this:
54-
a) Open a Powershell
55-
b) change directory to your repository
56-
and finally type
57-
58-
```bash
59-
tox -e dev
60-
```
61-
62-
You have now created the development environment (dev environment). It is the environment which contains both the usual requirements as well as the testing and linting tools.
63-
64-
### How to use with PyCharm
65-
66-
1. You have cloned the repository, you want to work in, and have created the virtual environment, in which the repository should be executed (`your_repo/.tox/dev`). Now, to actually work inside the newly created environment, you need to tell PyCharm (your IDE) that it should use the virtual environment - to be more precise: the interpreter of this dev environment. How to do this:
67-
a) navigate to: File ➡ Settings (Strg + Alt + S) ➡ Project: your_project ➡ Python Interpreter ➡ Add interpreter ➡ Existing
68-
b) Choose as interpreter: `your_repo\.tox\dev\Scripts\python.exe` (under windows)
69-
2. Set the default test runner of your project to pytest. How to do it:
70-
a) navigate to Files ➡ Settings ➡ Tools ➡ Python integrated tools ➡ Testing: Default test runner
71-
b) Change to "pytest"
72-
If this doesn't work anymore, see [the PyCharm docs](https://www.jetbrains.com/help/pycharm/choosing-your-testing-framework.html)
73-
3. Set the `src` directory as sources root. How to do this:
74-
right click on 'src' ➡ "Mark directory as…" ➡ sources root
75-
If this doesn't work anymore, see: [PyCharm docs](https://www.jetbrains.com/help/pycharm/content-root.html).
76-
4. Set the working directory of the unit tests to the project root (instead of the unittest directory). How to do this:
77-
a) Open any test file whose name starts with `test_` in unit tests/tests
78-
b) Right click inside the code ➡ More Run/Debug ➡ Modify Run Configuration ➡ Working directory
79-
c) Change to `your_repo` instead of `your_repo\unittests`
80-
By doing so, the import and other file paths in the tests are relative to the repo root.
81-
If this doesn't work anymore, see: [working directory of the unit tests](https://www.jetbrains.com/help/pycharm/creating-run-debug-configuration-for-tests.html)
82-
83-
### How to use with VS Code
84-
All paths mentioned in this section are relative to the repository root.
85-
86-
1. Open the folder with VS Code.
87-
2. **Select the python interpreter** ([official docs](https://code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter)) which is created by tox. Open the command pallett with `CTRL + P` and type `Python: 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.
88-
3. **Set up pytest and pylint**. Therefore we open the file `.vscode/settings.json` which should be automatically generated during the interpreter setup. If it doesn't exist, create it. Insert the following lines into the settings:
89-
90-
```json
91-
{
92-
"python.testing.unittestEnabled": false,
93-
"python.testing.nosetestsEnabled": false,
94-
"python.testing.pytestEnabled": true,
95-
"pythonTestExplorer.testFramework": "pytest",
96-
"python.testing.pytestArgs": ["unittests"],
97-
"python.linting.pylintEnabled": true
98-
}
99-
```
100-
101-
4. Create a `.env` file and insert the following line
102-
103-
For Windows:
104-
105-
```
106-
PYTHONPATH=src;${PYTHONPATH}
107-
```
108-
109-
For Linux and Mac:
110-
111-
```
112-
PYTHONPATH=src:${PYTHONPATH}
113-
```
114-
115-
This makes sure, that the imports are working for the unittests.
116-
At the moment I am not totally sure that it is the best practise, but it's getting the job done.
117-
118-
5. Enjoy 🤗
119-
120-
## Publishing on PyPI
121-
122-
This repository contains all necessary CI steps to publish any project created from it on PyPI.
123-
It uses the trusted publishers workflow as described in the [official Python documentation](https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/).
124-
It just requires some manual adjustments/settings depending on your project:
125-
126-
1. Fill out the metadata in the [`pyproject.toml`](pyproject.toml); Namely the package name and the dependencies which should be in sync with your `requirements.in`.
127-
2. Uncomment the lines in [`.github/workflows/python-publish.yml`](.github/workflows/python-publish.yml)
128-
3. Create a [new environment in your GitHub repository](https://github.com/Hochfrequenz/python_template_repository/settings/environments) and call it `release`.
129-
4. Set up a new trusted publisher [in your PYPI account](https://pypi.org/manage/account/publishing/).
130-
1. PyPI Project Name: The name which you defined in the `pyproject.toml` is the name of the project which you have to enter here.
131-
2. Owner: The GitHub organization name or GitHub username that owns the repository
132-
3. Repository name: The name of the GitHub repository that contains the publishing workflow
133-
4. 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`
134-
5. Environment name: The name of the GitHub Actions environment that the above workflow uses for publishing. Here in our case: `release`
135-
5. 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).
136-
6. 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.
137-
7. Now create another PyPI token with limited scope and update the Github repository secret accordingly.
13+
## Development
14+
For development of this library, follow the instructions in our [Python Template Repository](https://github.com/Hochfrequenz/python_template_repository).
13815

13916
## Contribute
140-
14117
You are very welcome to contribute to this template repository by opening a pull request against the main branch.
142-
143-
### GitHub Actions
144-
145-
- Dependabot auto-approve / -merge:
146-
- If the actor is the Dependabot bot (i.e. on every commit by Dependabot)
147-
the pull request is automatically approved and auto merge gets activated
148-
(using squash merge).
149-
Note that if you haven't enabled "auto merge" for your repository, the auto merge activation will fail.
150-
If you want to use a merge type other than "squash merge" you have to edit the workflow.

integrationtests/.pylintrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[pylint]
2+
# for the unittests disable some pylint warnings, e.g. we don't want to force devs to write docstrings for every test
3+
disable =
4+
C0114, # disable missing-module-docstring
5+
C0115, # disable missing-class-docstring
6+
C0116, # disable missing-function-docstring
7+
R0903, # disable too-few-public-methods
8+
W0621, # disable redefined-outer-name (this is for the use of pytest fixtures)
9+
R0801, # disable duplicate-code (we prefer our test to be explicit rather than perfectly redundancy free)
10+
[pylint."MESSAGES CONTROL"]
11+
max-line-length = 120

integrationtests/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
This file is here, because this allows for best de-coupling of tests and application/library logic.
3+
Further reading: https://docs.pytest.org/en/6.2.x/goodpractices.html#tests-outside-application-code
4+
"""

integrationtests/docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "3.7"
2+
3+
services:
4+
transformer:
5+
image: ghcr.io/enercity/edifact-bo4e-converter/edifactbo4econverter:v1.1.29
6+
environment:
7+
- StorageProvider=Directory
8+
ports:
9+
- ${TRANSFORMER_GRPC_PORT:-5020}:5000
10+
- ${TRANSFORMER_REST_PORT:-5021}:5001

integrationtests/test_myclass.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from transformerbeeclient.mymodule import MyClass
2+
3+
4+
class TestMyClass:
5+
"""
6+
A class with pytest unit tests.
7+
"""
8+
9+
def test_something(self):
10+
my_class = MyClass()
11+
assert my_class.do_something() == "abc"

src/mypackage/__init__.py

-3
This file was deleted.

src/transformerbeeclient/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
TransformerBeeClient is a Python client for the transformer.bee API.
3+
"""
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)