diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..89672f9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: [main, develop] + pull_request: + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -e ".[dev]" + - run: python -m ruff check src test example_usage.py + - run: python -m pytest --cov + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - run: python -m pip install build twine + - run: python -m build + - run: python -m twine check --strict dist/* + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ diff --git a/.gitignore b/.gitignore index d25a420..e42b3b4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ htmlcov/ # Other *.zip + +# Build output +build/ +dist/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 1738090..c1c0762 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,12 +10,15 @@ ProfielCheckPython is a conversion of the C# library `daas.fn` 1.0.1.0 by Rolf W A first Python conversion (2025) was an intermediate step and was not released separately; its own deviations from the C# code are listed at the end of the 2.0.0 section. +## [Unreleased] + ## [2.0.0] - 2026-10-19 ### API: from C# to Python | C# (`daas.fn`) | Python 2.0.0 | |---|---| +| Namespace `daas.fn` | Package `prflcheck` (folder `src/prflcheck/`): `from prflcheck import Profiel` | | `new Profiel(profielData)`, `new Profiel(naam, profielData)` | `Profiel.from_string(text)` or `Profiel.from_file(path)` | | `new Profiel(id, damtype, damhoogte, richting, kruinhoogte, voorland, damwandmodule, memo, profielpunten)` | `Profiel.from_punten(punten, voorland=..., id=..., damtype=..., damwand=..., ...)` | | `profiel.Controleer()` | `profiel.check()` | @@ -75,6 +78,11 @@ its own deviations from the C# code are listed at the end of the 2.0.0 section. - Test suite with pytest (256 tests, 100% branch coverage), including boundary tests for every validation limit and round-trip tests for v3 and v4. Linting with ruff. - `example_usage.py`, README, this changelog, and `LICENSE` (EUPL-1.2). +- **Installable package:** `pyproject.toml` (build backend hatchling), so `pip install .` + works and a wheel and source distribution can be built for PyPI under the name + `prflcheck`. The version number is read from `prflcheck.__version__`. The settings of + pytest, coverage and ruff are in `pyproject.toml`, the development tools in the `dev` extra + (`pip install -e ".[dev]"`). GitHub Actions runs the tests and builds the package. ### Changed @@ -128,3 +136,6 @@ C# library `daas.fn` for .NET Framework by Rolf Waterman, © HKV Services 2016, `Profiel.cs`, `ProfielPunt.cs`, `ProfielDeel.cs`, `ProfielCheck.cs`, `ProfielEnums.cs`, `ConvertString.cs` and `EnumeratorExtensions.cs`. Reads and writes Hydra/Ringtoets profiles (version 3 and 4) and validates them with `Controleer()`. + +[Unreleased]: https://github.com/MariovdBerg/ProfielCheckPython/compare/v2.0.0...HEAD +[2.0.0]: https://github.com/MariovdBerg/ProfielCheckPython/releases/tag/v2.0.0 diff --git a/README.md b/README.md index 3db7b89..2fe0de2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # ProfielCheckPython -A Python port of the HKV C# library for reading, writing and validating Hydra/Ringtoets +A Python port of the HKV C# library for reading, writing and validating Hydra-NL/HydraRing profiles (`.prfl`): cross-sections of a dike with an optional foreland (voorland) and dam. **Authors:** Rolf Waterman (original C# code), Mario van den Berg, Claude **Copyright:** © 2025-2026 HKV lijn in water B.V.; original C# code © 2016, 2017 HKV Services -**License:** [EUPL-1.2](LICENSE) -**Version:** 2.0.0 (see [CHANGELOG.md](CHANGELOG.md); not compatible with the C# library or 1.0.1.0) +**License:** [EUPL-1.2](https://github.com/MariovdBerg/ProfielCheckPython/blob/main/LICENSE) +**Version:** 2.0.0 (see [CHANGELOG.md](https://github.com/MariovdBerg/ProfielCheckPython/blob/main/CHANGELOG.md); not compatible with the C# library or 1.0.1.0) ## Overview @@ -17,28 +17,26 @@ profiles (`.prfl`): cross-sections of a dike with an optional foreland (voorland ## Installation -The module is not (yet) an installable package: there is no `pyproject.toml`, so `pip install` -does not work. The code lives in the folder `src` and is imported as `src`. +The package is called `prflcheck` (folder `src/prflcheck/`) and has no dependencies. +Install it from GitHub: -### From source +```bash +pip install git+https://github.com/MariovdBerg/ProfielCheckPython.git +``` + +Or from a local clone, in editable mode for development: ```bash git clone https://github.com/MariovdBerg/ProfielCheckPython.git cd ProfielCheckPython +pip install -e . python example_usage.py ``` -Scripts in the project folder can then use `from src import ...` directly. - -### Direct use from another project - -Add the project folder (the folder that *contains* `src`) to the Python path: +Then import it as usual: ```python -import sys -sys.path.append(r"C:\path\to\ProfielCheckPython") - -from src import Profiel, ProfielPunt, ProfielError +from prflcheck import Profiel, ProfielPunt, ProfielError ``` ## Quick Start @@ -46,7 +44,7 @@ from src import Profiel, ProfielPunt, ProfielError ### Creating a profile ```python -from src import Damwandmodule, DamType, Profiel, ProfielPunt, ProfielVersion +from prflcheck import Damwandmodule, DamType, Profiel, ProfielPunt, ProfielVersion # Profile points: x (m), z (m+NAP), roughness punten = [ @@ -85,7 +83,7 @@ are `NaN` (numbers) or `GEEN` (dam type and dam wall). ### Reading a profile ```python -from src import Profiel +from prflcheck import Profiel profiel = Profiel.from_file("profile_v4.prfl") # version 3 or 4, detected from VERSIE text = profiel.to_string(3) # the same profile in the version 3 format @@ -135,11 +133,13 @@ Dutch `description`: | 130 | Dam wall (crest height) above the end of the foreland | | 800, 801 | Invalid dam type or dam wall module | -The limits are constants in `src/checks.py`. A missing (`NaN`) crest height or roughness +The limits are constants in `src/prflcheck/checks.py`. A missing (`NaN`) crest height or roughness is reported as an error. ## Module Structure +The package `prflcheck` (folder `src/prflcheck/`) contains: + - **model.py**: `ProfielPunt`, `ProfielDeel` and `Profiel` (data only) - **reader.py**: `read_file()`, `read_string()` for version 3 and 4 - **writer.py**: `write_string()` for version 3 and 4 @@ -166,16 +166,32 @@ This demonstrates: ## Testing -The tests use pytest, pytest-cov and ruff (`requirements-dev.txt`). On Windows: +The tests use pytest, pytest-cov and ruff (the `dev` extra in `pyproject.toml`, which also +installs `build` and `twine`). The tests run against the installed package. On Windows: ```bash python -m venv .venv -.venv/Scripts/python -m pip install -r requirements-dev.txt -.venv/Scripts/python -m pytest --cov=src --cov-branch +.venv/Scripts/python -m pip install -e ".[dev]" +.venv/Scripts/python -m pytest --cov .venv/Scripts/python -m ruff check src test example_usage.py ``` -On Linux or macOS, use `.venv/bin/python` instead of `.venv/Scripts/python`. +On Linux or macOS, use `.venv/bin/python` instead of `.venv/Scripts/python`. GitHub Actions +runs the tests on Python 3.9 to 3.14 on Linux and Windows (`.github/workflows/ci.yml`). + +## Building and Publishing + +The version number is set in one place, `__version__` in `src/prflcheck/__init__.py`. +To make a release, update it, add a section to `CHANGELOG.md`, and build and check the +distributions: + +```bash +.venv/Scripts/python -m build +.venv/Scripts/python -m twine check dist/* +``` + +This creates a wheel and a source distribution in `dist/`. Upload them to PyPI with +`twine upload dist/*`. ## Requirements @@ -189,7 +205,7 @@ Copyright © 2025-2026 HKV lijn in water B.V. (Python code) Licensed under the EUPL -This work is licensed under the [European Union Public Licence v1.2](LICENSE) (EUPL-1.2), +This work is licensed under the [European Union Public Licence v1.2](https://github.com/MariovdBerg/ProfielCheckPython/blob/main/LICENSE) (EUPL-1.2), an open-source licence with copyleft: you may use, change and distribute the code, also commercially, provided that you keep the copyright notices, include the licence, mark your changes, and distribute changed versions under the EUPL (or a compatible licence listed in diff --git a/example_usage.py b/example_usage.py index 9f5963f..a4bb43e 100644 --- a/example_usage.py +++ b/example_usage.py @@ -1,14 +1,15 @@ """ Voorbeelden van het gebruik van de ProfielCheckPython-module. -Uitvoeren vanuit de hoofdmap van het project: +Uitvoeren vanuit de hoofdmap van het project, met prflcheck geïnstalleerd +(pip install -e .): python example_usage.py """ import tempfile from pathlib import Path -from src import DamType, Damwandmodule, Profiel, ProfielPunt, ProfielVersion +from prflcheck import DamType, Damwandmodule, Profiel, ProfielPunt, ProfielVersion PROFIEL_V3 = """VERSIE 3.0 DAM 0 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..46707d1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,81 @@ +[build-system] +requires = ["hatchling>=1.27"] +build-backend = "hatchling.build" + +[project] +name = "prflcheck" +dynamic = ["version"] +description = "Read, write and validate Hydra-NL/HydraRing profiles (.prfl)" +readme = "README.md" +requires-python = ">=3.9" +license = "EUPL-1.2" +license-files = ["LICENSE"] +authors = [ + { name = "Rolf Waterman" }, + { name = "Mario van den Berg", email = "M.vandenBerg@hkv.nl" }, +] +keywords = ["hydra-nl", "hydraring", "ringtoets", "profiel", "dijk", "prfl"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research", + "Natural Language :: Dutch", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", + "Topic :: Scientific/Engineering :: Hydrology", +] +dependencies = [] + +[project.optional-dependencies] +dev = ["pytest", "pytest-cov", "ruff", "build", "twine"] + +[project.urls] +Homepage = "https://github.com/MariovdBerg/ProfielCheckPython" +Source = "https://github.com/MariovdBerg/ProfielCheckPython" +Issues = "https://github.com/MariovdBerg/ProfielCheckPython/issues" +Changelog = "https://github.com/MariovdBerg/ProfielCheckPython/blob/main/CHANGELOG.md" + +# Eén bron voor het versienummer: __version__ in het package +[tool.hatch.version] +path = "src/prflcheck/__init__.py" + +[tool.hatch.build.targets.wheel] +packages = ["src/prflcheck"] + +[tool.hatch.build.targets.sdist] +include = [ + "src/prflcheck", + "test", + "example_usage.py", + "README.md", + "CHANGELOG.md", + "LICENSE", +] + +[tool.pytest.ini_options] +testpaths = ["test"] +# prflcheck wordt geïnstalleerd getest (pip install -e .), . is nodig voor example_usage.py +pythonpath = ["."] +addopts = "-ra" + +[tool.coverage.run] +source = ["prflcheck"] +branch = true + +[tool.ruff] +line-length = 120 +target-version = "py39" +# Mappen met eigen code, zodat imports van prflcheck als first-party worden gesorteerd +src = ["src", "."] + +[tool.ruff.lint] +select = ["E", "F", "W", "B", "I", "UP"] +# De foutmeldingen in ProfielError zijn bewust lange regels +per-file-ignores = { "src/prflcheck/profiel_enums.py" = ["E501"] } diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 330cc3c..0000000 --- a/pytest.ini +++ /dev/null @@ -1,4 +0,0 @@ -[pytest] -testpaths = test -pythonpath = . -addopts = -ra diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index f56102b..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,3 +0,0 @@ -pytest -pytest-cov -ruff diff --git a/ruff.toml b/ruff.toml deleted file mode 100644 index 9f3cff9..0000000 --- a/ruff.toml +++ /dev/null @@ -1,7 +0,0 @@ -line-length = 120 -target-version = "py39" - -[lint] -select = ["E", "F", "W", "B", "I", "UP"] -# De foutmeldingen in ProfielError zijn bewust lange regels -per-file-ignores = { "src/profiel_enums.py" = ["E501"] } diff --git a/src/__init__.py b/src/prflcheck/__init__.py similarity index 100% rename from src/__init__.py rename to src/prflcheck/__init__.py diff --git a/src/checks.py b/src/prflcheck/checks.py similarity index 100% rename from src/checks.py rename to src/prflcheck/checks.py diff --git a/src/convert_string.py b/src/prflcheck/convert_string.py similarity index 100% rename from src/convert_string.py rename to src/prflcheck/convert_string.py diff --git a/src/model.py b/src/prflcheck/model.py similarity index 100% rename from src/model.py rename to src/prflcheck/model.py diff --git a/src/profiel_enums.py b/src/prflcheck/profiel_enums.py similarity index 100% rename from src/profiel_enums.py rename to src/prflcheck/profiel_enums.py diff --git a/src/reader.py b/src/prflcheck/reader.py similarity index 100% rename from src/reader.py rename to src/prflcheck/reader.py diff --git a/src/writer.py b/src/prflcheck/writer.py similarity index 100% rename from src/writer.py rename to src/prflcheck/writer.py diff --git a/test/conftest.py b/test/conftest.py index 790287b..10e9d9a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -2,7 +2,7 @@ import pytest -from src import ProfielPunt +from prflcheck import ProfielPunt TESTPROFILES_DIR = Path(__file__).parent / "testprofiles" diff --git a/test/test_checks.py b/test/test_checks.py index c60f9fc..986ecea 100644 --- a/test/test_checks.py +++ b/test/test_checks.py @@ -2,7 +2,7 @@ import pytest -from src import Damwandmodule, Profiel, ProfielError, ProfielPunt, checks +from prflcheck import Damwandmodule, Profiel, ProfielError, ProfielPunt, checks from .conftest import punten diff --git a/test/test_convert_string.py b/test/test_convert_string.py index 70d8e4b..97649f1 100644 --- a/test/test_convert_string.py +++ b/test/test_convert_string.py @@ -3,7 +3,7 @@ import pytest -from src import format_float, parse_float, parse_int +from prflcheck import format_float, parse_float, parse_int @pytest.mark.parametrize("tekst, verwacht", [ diff --git a/test/test_encoding.py b/test/test_encoding.py index e47a461..52a4d30 100644 --- a/test/test_encoding.py +++ b/test/test_encoding.py @@ -2,8 +2,8 @@ import pytest -from src import Profiel, ProfielError, read_file -from src.reader import VERVANGTEKEN +from prflcheck import Profiel, ProfielError, read_file +from prflcheck.reader import VERVANGTEKEN TEKST = "VERSIE 4.0\nID X\nVOORLAND 0\nKRUINHOOGTE 8.0\nDIJK 2\n0 2 0.8\n8 3 0.8\nMEMO\nDijk bij Één, café\n" diff --git a/test/test_example_usage.py b/test/test_example_usage.py index 7285c1c..98b3c9b 100644 --- a/test/test_example_usage.py +++ b/test/test_example_usage.py @@ -1,7 +1,7 @@ """Houdt example_usage.py werkend: de voorbeelden moeten de verwachte uitkomst geven.""" import example_usage -from src import ProfielError +from prflcheck import ProfielError def test_voorbeelden_1_tot_4_zijn_geldig(capsys): diff --git a/test/test_model.py b/test/test_model.py index 169120b..0cbedcc 100644 --- a/test/test_model.py +++ b/test/test_model.py @@ -2,7 +2,7 @@ import pytest -from src import DamType, Damwandmodule, Profiel, ProfielDeel, ProfielDeelType, ProfielPunt +from prflcheck import DamType, Damwandmodule, Profiel, ProfielDeel, ProfielDeelType, ProfielPunt from .conftest import punten diff --git a/test/test_reader.py b/test/test_reader.py index 7521586..0220c29 100644 --- a/test/test_reader.py +++ b/test/test_reader.py @@ -3,7 +3,7 @@ import pytest -from src import DamType, Damwandmodule, Profiel, ProfielError, ProfielPunt, read_file, read_string +from prflcheck import DamType, Damwandmodule, Profiel, ProfielError, ProfielPunt, read_file, read_string from .conftest import fixture_path diff --git a/test/test_writer.py b/test/test_writer.py index f87fda9..d5c3cd3 100644 --- a/test/test_writer.py +++ b/test/test_writer.py @@ -2,7 +2,16 @@ import pytest -from src import DamType, Damwandmodule, Profiel, ProfielError, ProfielPunt, ProfielVersion, read_file, write_string +from prflcheck import ( + DamType, + Damwandmodule, + Profiel, + ProfielError, + ProfielPunt, + ProfielVersion, + read_file, + write_string, +) from .conftest import fixture_path, punten diff --git a/todo.txt b/todo.txt index 4ba7c3e..35e6048 100644 --- a/todo.txt +++ b/todo.txt @@ -2,4 +2,3 @@ Open - Ruwheid (ERROR121): de C#-code had geen ruwheidscontrole en geen foutcode 121 (de constanten RUWHEIDLAAG en RUWHEIDHOOG bestonden wel). Nog bevestigen met de Hydra-documentatie dat de controle zo klopt: alleen dijkdelen, grenzen 0.5 en 1.0 zelf toegestaan. -- Packaging: pyproject.toml, package-naam (nu 'src'), installatie-instructies in README.md kloppen nog niet.