From 9b83b8365b01e97e865f1552a11bb52e94e0ad5e Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Mon, 1 Dec 2025 12:06:05 +0100 Subject: [PATCH 1/5] add very simple tests for tool functions --- tests/tools_test.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/tools_test.py diff --git a/tests/tools_test.py b/tests/tools_test.py new file mode 100644 index 0000000..71c5267 --- /dev/null +++ b/tests/tools_test.py @@ -0,0 +1,25 @@ + + +from corrlib import tools as tl + + +def test_m2k(): + assert tl.m2k(0.1) == 1/(2*0.1+8) + assert tl.m2k(0.5) == 1/(2*0.5+8) + assert tl.m2k(1.0) == 1/(2*1.0+8) + + +def test_k2m(): + assert tl.k2m(0.1) == (1/(2*0.1))-4 + assert tl.k2m(0.5) == (1/(2*0.5))-4 + assert tl.k2m(1.0) == (1/(2*1.0))-4 + + +def test_str2list(): + assert tl.str2list("a,b,c") == ["a", "b", "c"] + assert tl.str2list("1,2,3") == ["1", "2", "3"] + + +def test_list2str(): + assert tl.list2str(["a", "b", "c"]) == "a,b,c" + assert tl.list2str(["1", "2", "3"]) == "1,2,3" From 5bd3d5313a73a82f1fb12d9ba4de456e256ebd9c Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Mon, 1 Dec 2025 12:07:29 +0100 Subject: [PATCH 2/5] add typehints --- corrlib/tools.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/corrlib/tools.py b/corrlib/tools.py index 14bfc05..f9c216d 100644 --- a/corrlib/tools.py +++ b/corrlib/tools.py @@ -2,24 +2,24 @@ import os import datalad.api as dl -def str2list(string): +def str2list(string: str): return string.split(",") def list2str(mylist): s = ",".join(mylist) return s -cached = True +cached: bool = True -def m2k(m): +def m2k(m: float) -> float: return 1/(2*m+8) -def k2m(k): +def k2m(k: float) -> float: return (1/(2*k))-4 -def get_file(path, file): +def get_file(path: str, file: str): if file == "backlogger.db": print("Downloading database...") else: From cbe67e6f27315e953f34868eb3182efb3d047ea2 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Mon, 1 Dec 2025 12:14:39 +0100 Subject: [PATCH 3/5] add dev deps --- pyproject.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ed2df7b..8f083bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,4 +3,10 @@ requires = ["setuptools >= 63.0.0", "wheel"] build-backend = "setuptools.build_meta" [tool.ruff.lint] -ignore = ["F403"] \ No newline at end of file +ignore = ["F403"] + +[dependency-groups] +dev = [ + "pytest>=9.0.1", + "pytest-pretty>=1.3.0", +] From b8375018811f0acc5d22e955bfc7df2df826503d Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Mon, 1 Dec 2025 12:25:06 +0100 Subject: [PATCH 4/5] correct test due to new requirement of function --- .github/workflows/pytest.yaml | 24 ++++++++++++++++++++++++ tests/import_project_test.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pytest.yaml diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml new file mode 100644 index 0000000..db9cfa1 --- /dev/null +++ b/.github/workflows/pytest.yaml @@ -0,0 +1,24 @@ +name: Pytest + +jobs: + test: + strategy: + matrix: + python-version: + - "3.10" + - "3.11" + - "3.12" + + runs-on: ubuntu-latest + steps: + - name: Check out the repository + uses: actions/checkout@v4 + with: + show-progress: true + - name: Install uv + uses: astral-sh/setup-uv@v7 + - name: Install corrlib + run: uv sync --locked --all-extras --dev + - name: Run tests + # For example, using `pytest` + run: uv run pytest tests diff --git a/tests/import_project_test.py b/tests/import_project_test.py index ec8272c..2dea06f 100644 --- a/tests/import_project_test.py +++ b/tests/import_project_test.py @@ -14,4 +14,4 @@ def test_toml_check_measurement_data(): "names": ['list', 'of', 'names'] } } - t.check_measurement_data(measurements) + t.check_measurement_data(measurements, "sfcf") From 66faf9cf33b0fdebe1f4c6a73c786432deed24d2 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Mon, 1 Dec 2025 12:43:00 +0100 Subject: [PATCH 5/5] change versioning to dynamic versions with setuptools-scm --- corrlib/__init__.py | 1 - corrlib/cli.py | 5 +++-- pyproject.toml | 25 ++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/corrlib/__init__.py b/corrlib/__init__.py index 91b07f4..ee2b66c 100644 --- a/corrlib/__init__.py +++ b/corrlib/__init__.py @@ -20,4 +20,3 @@ from .import input as input from .initialization import * from .meas_io import * from .find import * -from .version import __version__ diff --git a/corrlib/cli.py b/corrlib/cli.py index b808c13..56b0221 100644 --- a/corrlib/cli.py +++ b/corrlib/cli.py @@ -1,6 +1,6 @@ from typing import Optional import typer -from corrlib import __app_name__, __version__ +from corrlib import __app_name__ from .initialization import create from .toml import import_tomls, update_project, reimport_project from .find import find_record, list_projects @@ -8,6 +8,7 @@ from .tools import str2list from .main import update_aliases from .meas_io import drop_cache as mio_drop_cache import os +from importlib.metadata import version, PackageNotFoundError app = typer.Typer() @@ -15,7 +16,7 @@ app = typer.Typer() def _version_callback(value: bool) -> None: if value: - typer.echo(f"{__app_name__} v{__version__}") + print(__app_name__, version(__app_name__)) raise typer.Exit() diff --git a/pyproject.toml b/pyproject.toml index 8f083bc..4551237 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,30 @@ [build-system] -requires = ["setuptools >= 63.0.0", "wheel"] +requires = ["setuptools >= 63.0.0", "wheel", "setuptools-scm"] build-backend = "setuptools.build_meta" +[project] +name = "corrlib" +dynamic = ["version"] +dependencies = [ + "gitpython>=3.1.45", + 'pyerrors>=2.11.1', + 'datalad>=1.1.0', + 'typer>=0.12.5' +] +description = "Python correlation library" +authors = [ + { name = 'Justus Kuhlmann', email = 'j_kuhl19@uni-muenster.de'} +] + +[project.scripts] +pcl = "corrlib.cli:app" + +[tool.setuptools.packages.find] +include = ["corrlib", "corrlib.*"] + +[tool.setuptools.dynamic] +version = { file = "corrlib/version.py" } + [tool.ruff.lint] ignore = ["F403"]