From 7d1bc19f23b6e7f1ed31b9ebac6e0bba7e3898e3 Mon Sep 17 00:00:00 2001 From: Numan Date: Fri, 6 Dec 2024 23:00:04 +0100 Subject: [PATCH 1/3] Change class name and update CI workflow for publishing --- .github/workflows/publish.yml | 21 +++++++-------------- README.md | 6 +++--- steuerid/__init__.py | 12 ++++++------ tests/test_invalid.py | 8 ++++---- tests/test_valid.py | 4 ++-- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bc33a71..9f2fb3d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,6 +1,8 @@ name: Publish Python distribution to PyPI -on: push +on: + push: + tags permissions: contents: read @@ -18,18 +20,11 @@ jobs: with: python-version: "3.x" - - name: Install Poetry - run: | - curl -sSL https://install.python-poetry.org | python - -y - - - name: Update PATH - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Update Poetry configuration - run: poetry config virtualenvs.create false - - name: Install dependencies - run: poetry install --sync --no-interaction + run: | + python -m pip install --upgrade pip + pip install poetry + poetry install --sync --no-interaction - name: Package project run: poetry build @@ -45,8 +40,6 @@ jobs: name: Upload release to PyPI runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes - needs: - build diff --git a/README.md b/README.md index 3bba7d1..3ebe0f5 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ Based on the [official ELSTER documentation](https://download.elster.de/download An example of how it can be used: ```python -from steuerid import SteuerIdValidator +from steuerid import SteuerId -validation_result = SteuerIdValidator.validate("02476291358") +validation_result = SteuerId.validate("02476291358") print(validation_result) # (True, None) -> the provided input is a valid steuer id -validation_result = SteuerIdValidator.validate("x1234567890") +validation_result = SteuerId.validate("x1234567890") print(validation_result) # (False, OnlyDigitsAllowedException) -> invalid input, only digits are allowed ``` diff --git a/steuerid/__init__.py b/steuerid/__init__.py index ed4292a..8e63a55 100644 --- a/steuerid/__init__.py +++ b/steuerid/__init__.py @@ -14,7 +14,7 @@ STEUER_ID_LENGTH = 11 STEUERID_PRODUCTION_ENV = "STEUERID_PRODUCTION" -class SteuerIdValidator: +class SteuerId: @staticmethod def _validate_structure(steuer_id: str) -> None: """ @@ -129,7 +129,7 @@ def _validate_checksum_digit(steuer_id: str) -> None: Raises: InvalidChecksumDigit """ - if steuer_id[-1] != str(SteuerIdValidator._get_checksum_digit(steuer_id)): + if steuer_id[-1] != str(SteuerId._get_checksum_digit(steuer_id)): raise InvalidChecksumDigitException @staticmethod @@ -148,10 +148,10 @@ def validate(steuer_id: str) -> tuple[bool, None] | tuple[bool, SteuerIDValidati the Exception object. """ try: - SteuerIdValidator._validate_structure(steuer_id) - SteuerIdValidator._validate_test_id(steuer_id) - SteuerIdValidator._validate_digit_repetitions(steuer_id) - SteuerIdValidator._validate_checksum_digit(steuer_id) + SteuerId._validate_structure(steuer_id) + SteuerId._validate_test_id(steuer_id) + SteuerId._validate_digit_repetitions(steuer_id) + SteuerId._validate_checksum_digit(steuer_id) # input is a valid steuer id return True, None diff --git a/tests/test_invalid.py b/tests/test_invalid.py index 352c5f1..c0915b5 100644 --- a/tests/test_invalid.py +++ b/tests/test_invalid.py @@ -1,6 +1,6 @@ import pytest -from steuerid import SteuerIdValidator +from steuerid import SteuerId from steuerid import STEUERID_PRODUCTION_ENV from steuerid.exceptions import * @@ -22,14 +22,14 @@ class TestInvalidSteuerId: ] ) def test_invalid_with_exception(self, steuer_id, expected_exception): - is_valid, ex = SteuerIdValidator.validate(steuer_id) + is_valid, ex = SteuerId.validate(steuer_id) assert not is_valid assert isinstance(ex, expected_exception) def test_no_test_id_allowed(self, monkeypatch): monkeypatch.setenv(STEUERID_PRODUCTION_ENV, "True") - is_valid, ex = SteuerIdValidator.validate("01234567899") + is_valid, ex = SteuerId.validate("01234567899") assert not is_valid assert isinstance(ex, SteuerTestIdNotAllowedException) @@ -54,5 +54,5 @@ def test_no_test_id_allowed(self, monkeypatch): '123/456/78911', ]) def test_invalid_general(self, steuer_id): - is_valid, _ = SteuerIdValidator.validate(steuer_id) + is_valid, _ = SteuerId.validate(steuer_id) assert not is_valid diff --git a/tests/test_valid.py b/tests/test_valid.py index 9b559aa..2447fb6 100644 --- a/tests/test_valid.py +++ b/tests/test_valid.py @@ -1,6 +1,6 @@ import pytest -from steuerid import SteuerIdValidator +from steuerid import SteuerId class TestValidSteuerId: @pytest.mark.parametrize("steuer_id", [ @@ -24,5 +24,5 @@ class TestValidSteuerId: '12345678920', ]) def test_valid_general(self, steuer_id): - is_valid, _ = SteuerIdValidator.validate(steuer_id) + is_valid, _ = SteuerId.validate(steuer_id) assert is_valid From da3cb36af44303d4d48fd86766d8dad6a0f0885f Mon Sep 17 00:00:00 2001 From: Numan Date: Fri, 6 Dec 2024 23:12:03 +0100 Subject: [PATCH 2/3] publish on all tags --- .github/workflows/publish.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9f2fb3d..99a764a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,7 +2,8 @@ name: Publish Python distribution to PyPI on: push: - tags + tags: + - '*' permissions: contents: read From 0f7588bfcef70f7305b1d63a88451f2702db5611 Mon Sep 17 00:00:00 2001 From: Krzysztof Tomasz Zembrowski Date: Sat, 7 Dec 2024 05:42:10 +0100 Subject: [PATCH 3/3] fix: links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ebe0f5..2fda767 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Tests](https://github.com/NumanIjaz/steuer-id/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/NumanIjaz/steuer-id/actions/workflows/run-tests.yml) +[![Tests](https://github.com/NumanIjaz/steuerid/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/NumanIjaz/steuer-id/actions/workflows/run-tests.yml) [![Python versions](https://img.shields.io/pypi/pyversions/steuerid)](https://pypi.org/project/steuerid/) # Steuer-ID @@ -51,7 +51,7 @@ pytest - [Numan Ijaz](https://github.com/NumanIjaz) - [Krzysztof Tomasz Zembrowski](https://github.com/zembrowski) -- [All Contributors](https://github.com/NumanIjaz/steuer-id/contributors) +- [All Contributors](https://github.com/NumanIjaz/steuerid/contributors) ## License