Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧙‍♀️ Initial Setup #1

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

103 changes: 51 additions & 52 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,57 @@
# This workflow uploads a Python Package using Twine when a release is created.
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# name: Upload Python Package
name: Upload Python Package

# on:
# release:
# types: [created, edited]
on:
release:
types: [ created, edited ]

# jobs:
# tests:
# if: startsWith(github.ref, 'refs/tags/v')
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# python-version: ["3.12"]
# os: [ubuntu-latest]
# steps:
# - uses: actions/checkout@v4
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}
# - name: Install tox
# run: |
# python -m pip install --upgrade pip
# pip install tox
# - name: Run tox
# run: |
# tox

# build-n-publish:
# name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
# runs-on: ubuntu-latest
# # Specifying a GitHub environment, # Specifying a GitHub environment, which is strongly recommended by PyPI: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
# # you have to create an environment in your repository settings and add the environment name here
# environment: release
# permissions:
# # IMPORTANT: this permission is mandatory for trusted publishing
# id-token: write
# needs: tests
# steps:
# - uses: actions/checkout@v4
# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -r dev_requirements/requirements-packaging.txt
# - name: Build wheel and source distributions
# run: |
# python -m build
# - name: Publish distribution 📦 to PyPI
# if: startsWith(github.ref, 'refs/tags/v')
# uses: pypa/gh-action-pypi-publish@release/v1
jobs:
tests:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [ "3.12" ]
os: [ ubuntu-latest ]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tox
run: |
tox

build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
# Specifying a GitHub environment, # Specifying a GitHub environment, which is strongly recommended by PyPI: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
# you have to create an environment in your repository settings and add the environment name here
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
needs: tests
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r dev_requirements/requirements-packaging.txt
- name: Build wheel and source distributions
run: |
python -m build
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions domain-specific-terms.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# contains 1 lower case word per line which are ignored in the spell_check
autor
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[project]
name = "your-favourite-package-name"
description = "Description of your package"
name = "bamx"
description = "Python interface XML documents for MIG and AHBs, published by BDEW "
license = { text = "MIT" }
requires-python = ">=3.11"
authors = [{ name = "your name", email = "your@email.address" }]
keywords = ["your", "important", "keywords"]
authors = [{ name = "Hochfrequenz Unternehmensberatung GmbH", email = "info+github@hochfrequenz.de" }]
keywords = ["BDEW", "XML", "AHB", "MIG", "Marktkommunikation"]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
Expand All @@ -20,8 +20,8 @@ dependencies = [] # add all the dependencies here
dynamic = ["readme", "version"]

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

[tool.black]
line-length = 120
Expand All @@ -38,7 +38,7 @@ max-line-length = 120
truethy-bool = true

[tool.mypy]
disable_error_code = ["no-untyped-def", "no-untyped-call"]
disable_error_code = []

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

[tool.hatch.build.hooks.vcs]
version-file = "src/_your_package_version.py"
version-file = "src/_bamx_version.py"
template = '''
version = "{version}"
'''
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/bamx/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""contains model classes representing MIGs and AHBs"""
21 changes: 21 additions & 0 deletions src/bamx/models/messageimplementationguide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""classes that represent MIGs"""

from dataclasses import dataclass
from datetime import date


@dataclass(frozen=True, eq=True, order=True, unsafe_hash=True, kw_only=True)
class MessageImplementationGuide:
"""
message implementation guide (MIG)
"""

veroeffentlichungsdatum: date
"""
publishing date
"""
autor: str
"""author, most likely 'BDEW'"""

versionsnummer: str
"""e.g. '1.1c'"""
File renamed without changes.
5 changes: 5 additions & 0 deletions src/bamx/reader/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""classes for reading xml documents"""

from .migreader import MigReader

__all__ = ["MigReader"]
53 changes: 53 additions & 0 deletions src/bamx/reader/migreader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
This a docstring for the module.
"""

import xml.etree.ElementTree as ET
from datetime import date, datetime
from pathlib import Path

from bamx.models.messageimplementationguide import MessageImplementationGuide


class MigReader:
"""
Accesses information from an XML based message implementation guide
"""

def __init__(self, xml_path: Path):
"""
initialize by providing the path to the XML file
"""
self._xml_path = xml_path
self._element_tree = ET.parse(self._xml_path)

def get_publishing_date(self) -> date:
"""
returns the publishing date of the message implementation guide
"""
raw_value = self._element_tree.getroot().attrib["Veroeffentlichungsdatum"] # e.g. '24.10.2023'
result = datetime.strptime(raw_value, "%d.%m.%Y").date()
return result

def get_author(self) -> str:
"""
returns the author of the message implementation guide
"""
return self._element_tree.getroot().attrib["Author"]

def get_version(self) -> str:
"""
returns the version of the message implementation guide
"""
return self._element_tree.getroot().attrib["Versionsnummer"]

def read(self) -> MessageImplementationGuide:
"""
read the entire file and convert it to a MessageImplementationGuid instance
"""
result = MessageImplementationGuide(
veroeffentlichungsdatum=self.get_publishing_date(),
autor=self.get_author(),
versionsnummer=self.get_version(),
)
return result
23 changes: 0 additions & 23 deletions src/mypackage/mymodule.py

This file was deleted.

4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ deps =
# add your fixtures like e.g. pytest_datafiles here
setenv = PYTHONPATH = {toxinidir}/src
commands =
pylint mypackage
pylint bamx
pylint unittests --rcfile=unittests/.pylintrc
# add single files (ending with .py) or packages here

Expand All @@ -37,7 +37,7 @@ deps =
{[testenv:tests]deps}
-r dev_requirements/requirements-type_check.txt
commands =
mypy --show-error-codes src/mypackage --strict
mypy --show-error-codes src/bamx --strict
mypy --show-error-codes unittests --strict
# add single files (ending with .py) or packages here

Expand Down
2 changes: 2 additions & 0 deletions unittests/example_files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The files in this directory have been copied from [the BDEW website](https://www.bdew.de/service/anwendungshilfen/edienergy-xml-beispieldateien/).
The copyright remains with the BDEW.
Loading