Skip to content

Commit edeee0a

Browse files
authored
🧙‍♀️ Initial Setup (#1)
1 parent e423661 commit edeee0a

19 files changed

+5772
-166
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/python-publish.yml

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,57 @@
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
35-
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
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
6235
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

domain-specific-terms.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# contains 1 lower case word per line which are ignored in the spell_check
2+
autor

pyproject.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[project]
2-
name = "your-favourite-package-name"
3-
description = "Description of your package"
2+
name = "bamx"
3+
description = "Python interface XML documents for MIG and AHBs, published by BDEW "
44
license = { text = "MIT" }
55
requires-python = ">=3.11"
6-
authors = [{ name = "your name", email = "[email protected]" }]
7-
keywords = ["your", "important", "keywords"]
6+
authors = [{ name = "Hochfrequenz Unternehmensberatung GmbH", email = "[email protected]" }]
7+
keywords = ["BDEW", "XML", "AHB", "MIG", "Marktkommunikation"]
88
classifiers = [
99
"Development Status :: 4 - Beta",
1010
"Environment :: Console",
@@ -20,8 +20,8 @@ dependencies = [] # add all the dependencies here
2020
dynamic = ["readme", "version"]
2121

2222
[project.urls]
23-
Changelog = "https://github.com/Hochfrequenz/python_template_repository/releases"
24-
Homepage = "https://github.com/Hochfrequenz/python_template_repository"
23+
Changelog = "https://github.com/Hochfrequenz/bdew_ahb_mig_xml-python/releases"
24+
Homepage = "https://github.com/Hochfrequenz/bdew_ahb_mig_xml-python"
2525

2626
[tool.black]
2727
line-length = 120
@@ -38,7 +38,7 @@ max-line-length = 120
3838
truethy-bool = true
3939

4040
[tool.mypy]
41-
disable_error_code = ["no-untyped-def", "no-untyped-call"]
41+
disable_error_code = []
4242

4343
[build-system]
4444
requires = ["hatchling>=1.8.0", "hatch-vcs", "hatch-fancy-pypi-readme"]
@@ -52,7 +52,7 @@ fragments = [{ path = "README.md" }]
5252
source = "vcs"
5353

5454
[tool.hatch.build.hooks.vcs]
55-
version-file = "src/_your_package_version.py"
55+
version-file = "src/_bamx_version.py"
5656
template = '''
5757
version = "{version}"
5858
'''
File renamed without changes.

src/bamx/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""contains model classes representing MIGs and AHBs"""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""classes that represent MIGs"""
2+
3+
from dataclasses import dataclass
4+
from datetime import date
5+
6+
7+
@dataclass(frozen=True, eq=True, order=True, unsafe_hash=True, kw_only=True)
8+
class MessageImplementationGuide:
9+
"""
10+
message implementation guide (MIG)
11+
"""
12+
13+
veroeffentlichungsdatum: date
14+
"""
15+
publishing date
16+
"""
17+
autor: str
18+
"""author, most likely 'BDEW'"""
19+
20+
versionsnummer: str
21+
"""e.g. '1.1c'"""
File renamed without changes.

src/bamx/reader/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""classes for reading xml documents"""
2+
3+
from .migreader import MigReader
4+
5+
__all__ = ["MigReader"]

src/bamx/reader/migreader.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
This a docstring for the module.
3+
"""
4+
5+
import xml.etree.ElementTree as ET
6+
from datetime import date, datetime
7+
from pathlib import Path
8+
9+
from bamx.models.messageimplementationguide import MessageImplementationGuide
10+
11+
12+
class MigReader:
13+
"""
14+
Accesses information from an XML based message implementation guide
15+
"""
16+
17+
def __init__(self, xml_path: Path):
18+
"""
19+
initialize by providing the path to the XML file
20+
"""
21+
self._xml_path = xml_path
22+
self._element_tree = ET.parse(self._xml_path)
23+
24+
def get_publishing_date(self) -> date:
25+
"""
26+
returns the publishing date of the message implementation guide
27+
"""
28+
raw_value = self._element_tree.getroot().attrib["Veroeffentlichungsdatum"] # e.g. '24.10.2023'
29+
result = datetime.strptime(raw_value, "%d.%m.%Y").date()
30+
return result
31+
32+
def get_author(self) -> str:
33+
"""
34+
returns the author of the message implementation guide
35+
"""
36+
return self._element_tree.getroot().attrib["Author"]
37+
38+
def get_version(self) -> str:
39+
"""
40+
returns the version of the message implementation guide
41+
"""
42+
return self._element_tree.getroot().attrib["Versionsnummer"]
43+
44+
def read(self) -> MessageImplementationGuide:
45+
"""
46+
read the entire file and convert it to a MessageImplementationGuid instance
47+
"""
48+
result = MessageImplementationGuide(
49+
veroeffentlichungsdatum=self.get_publishing_date(),
50+
autor=self.get_author(),
51+
versionsnummer=self.get_version(),
52+
)
53+
return result

0 commit comments

Comments
 (0)