From dd40440843bb1ddfbcfac7cbeb7e71cf1cf0e1bb Mon Sep 17 00:00:00 2001 From: foefl Date: Fri, 24 Oct 2025 13:03:27 +0200 Subject: [PATCH] add simple CLI directly to package, related to #8 --- pyproject.toml | 7 ++-- .../{_csharp_interface.py => _interface.py} | 2 ++ src/dopt_sensor_anomalies/cli.py | 33 +++++++++++++++++++ src/dopt_sensor_anomalies/types.py | 7 ++++ ..._csharp_interface.py => test_interface.py} | 10 +++--- 5 files changed, 51 insertions(+), 8 deletions(-) rename src/dopt_sensor_anomalies/{_csharp_interface.py => _interface.py} (87%) create mode 100644 src/dopt_sensor_anomalies/cli.py rename tests/{test_csharp_interface.py => test_interface.py} (87%) diff --git a/pyproject.toml b/pyproject.toml index bcab462..4886922 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dopt-sensor-anomalies" -version = "0.1.1" +version = "0.1.2" description = "anomaly detection for sensor images for quality assurance processes" authors = [ {name = "d-opt GmbH", email = "f.foerster@d-opt.com"}, @@ -10,6 +10,9 @@ requires-python = "<3.14,>=3.11" readme = "README.md" license = {text = "LicenseRef-Proprietary"} +[project.scripts] +EKF = "dopt_sensor_anomalies.cli:main" + [build-system] requires = ["pdm-backend", "Cython", "setuptools"] build-backend = "pdm.backend" @@ -76,7 +79,7 @@ directory = "reports/coverage" [tool.bumpversion] -current_version = "0.1.1" +current_version = "0.1.2" parse = """(?x) (?P0|[1-9]\\d*)\\. (?P0|[1-9]\\d*)\\. diff --git a/src/dopt_sensor_anomalies/_csharp_interface.py b/src/dopt_sensor_anomalies/_interface.py similarity index 87% rename from src/dopt_sensor_anomalies/_csharp_interface.py rename to src/dopt_sensor_anomalies/_interface.py index 3602143..590cf6d 100644 --- a/src/dopt_sensor_anomalies/_csharp_interface.py +++ b/src/dopt_sensor_anomalies/_interface.py @@ -1,3 +1,5 @@ +"""main pipeline interface for external calls""" + from dopt_sensor_anomalies import detection diff --git a/src/dopt_sensor_anomalies/cli.py b/src/dopt_sensor_anomalies/cli.py new file mode 100644 index 0000000..cf75eea --- /dev/null +++ b/src/dopt_sensor_anomalies/cli.py @@ -0,0 +1,33 @@ +import argparse +from typing import cast + +from dopt_sensor_anomalies import _interface +from dopt_sensor_anomalies.types import CliArgs + + +def main() -> None: + parser = argparse.ArgumentParser( + description=("simple CLI tool to analyse single sensor images for anomalies") + ) + parser.add_argument( + "img_path", + help="file path to the image which is to be analysed", + type=str, + ) + parser.add_argument( + "calib_value_x", + help="calibration value in pixels per mcm for x axis", + type=float, + ) + parser.add_argument( + "calib_value_y", + help="calibration value in pixels per mcm for y axis", + type=float, + ) + args = cast(CliArgs, parser.parse_args()) + + _interface.sensor_anomalies_detection( + args.img_path, + args.calib_value_x, + args.calib_value_y, + ) diff --git a/src/dopt_sensor_anomalies/types.py b/src/dopt_sensor_anomalies/types.py index c0cd9cc..2622127 100644 --- a/src/dopt_sensor_anomalies/types.py +++ b/src/dopt_sensor_anomalies/types.py @@ -25,3 +25,10 @@ class SensorImages(TypedDict): class DetectionModels(TypedDict): left: Path right: Path + + +@dc.dataclass() +class CliArgs: + img_path: str + calib_value_x: float + calib_value_y: float diff --git a/tests/test_csharp_interface.py b/tests/test_interface.py similarity index 87% rename from tests/test_csharp_interface.py rename to tests/test_interface.py index 7f16b7c..df8703c 100644 --- a/tests/test_csharp_interface.py +++ b/tests/test_interface.py @@ -3,7 +3,7 @@ from unittest.mock import patch import pytest -from dopt_sensor_anomalies import _csharp_interface, constants, errors +from dopt_sensor_anomalies import _interface, constants, errors @patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib") @@ -15,7 +15,7 @@ def test_sensor_anomalies_detection_FailImagePath(setup_temp_dir): MESSAGE = "The provided path seems not to exist" with pytest.raises(FileNotFoundError, match=MESSAGE): - _csharp_interface.sensor_anomalies_detection( + _interface.sensor_anomalies_detection( img_path, pixels_per_metric_X, pixels_per_metric_Y ) @@ -29,7 +29,7 @@ def test_sensor_anomalies_detection_FailElectrodeCount(path_img_with_failure_Ele MESSAGE = "Number of counted electrodes does not match the" with pytest.raises(errors.InvalidElectrodeCount, match=MESSAGE): - _csharp_interface.sensor_anomalies_detection( + _interface.sensor_anomalies_detection( img_path, pixels_per_metric_X, pixels_per_metric_Y ) @@ -52,9 +52,7 @@ def test_sensor_anomalies_detection_Success( pixels_per_metric_X: float = 0.251 pixels_per_metric_Y: float = 0.251 - _csharp_interface.sensor_anomalies_detection( - img_path, pixels_per_metric_X, pixels_per_metric_Y - ) + _interface.sensor_anomalies_detection(img_path, pixels_per_metric_X, pixels_per_metric_Y) assert csv_file.exists() assert heatmap_file.exists()