diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3a4ac69c..ed3d0100 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -25,3 +25,7 @@ jobs: - name: Test installation run: | kiss_icp_pipeline --version + - name: Run unittests + run: | + python -m pip install --verbose './python[test]' + pytest -rA --verbose ./python/ diff --git a/python/kiss_icp/config/parser.py b/python/kiss_icp/config/parser.py index e58c704d..fc004773 100644 --- a/python/kiss_icp/config/parser.py +++ b/python/kiss_icp/config/parser.py @@ -28,7 +28,8 @@ from pathlib import Path from typing import Any, Dict, Optional -from pydantic import BaseSettings, PrivateAttr +from pydantic import PrivateAttr +from pydantic_settings import BaseSettings from kiss_icp.config.config import AdaptiveThresholdConfig, DataConfig, MappingConfig @@ -38,32 +39,23 @@ class KISSConfig(BaseSettings): data: DataConfig = DataConfig() mapping: MappingConfig = MappingConfig() adaptive_threshold: AdaptiveThresholdConfig = AdaptiveThresholdConfig() - _config_file: Optional[Path] = PrivateAttr() - - def __init__(self, config_file: Optional[Path] = None, *args, **kwargs): - self._config_file = config_file - super().__init__(*args, **kwargs) - - def _yaml_source(self) -> Dict[str, Any]: - data = None - if self._config_file is not None: - try: - yaml = importlib.import_module("yaml") - except ModuleNotFoundError: - print( - "Custom configuration file specified but PyYAML is not installed on your system," - ' run `pip install "kiss-icp[all]"`. You can also modify the config.py if your ' - "system does not support PyYaml " - ) - sys.exit(1) - with open(self._config_file) as cfg_file: - data = yaml.safe_load(cfg_file) - return data or {} - - class Config: - @classmethod - def customise_sources(cls, init_settings, env_settings, file_secret_settings): - return init_settings, KISSConfig._yaml_source + + +def _yaml_source(config_file: Optional[Path]) -> Dict[str, Any]: + data = None + if config_file is not None: + try: + yaml = importlib.import_module("yaml") + except ModuleNotFoundError: + print( + "Custom configuration file specified but PyYAML is not installed on your system," + ' run `pip install "kiss-icp[all]"`. You can also modify the config.py if your ' + "system does not support PyYaml " + ) + sys.exit(1) + with open(config_file) as cfg_file: + data = yaml.safe_load(cfg_file) + return data or {} def load_config( @@ -72,7 +64,8 @@ def load_config( """Load configuration from an Optional yaml file. Additionally, deskew and max_range can be also specified from the CLI interface""" - config = KISSConfig(config_file=config_file) + config = KISSConfig(**_yaml_source(config_file)) + print(config.model_dump()) # Override defaults from command line if deskew is not None: diff --git a/python/pyproject.toml b/python/pyproject.toml index ac6576fa..a97062e4 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -38,7 +38,8 @@ dependencies = [ "natsort", "numpy", "plyfile", - "pydantic <2", + "pydantic>=2", + "pydantic-settings", "pyquaternion", "rich", "tqdm", @@ -53,6 +54,9 @@ all = [ "PyYAML", "trimesh", ] +test = [ + "pytest", +] visualizer = [ "open3d>=0.13", ] @@ -89,3 +93,6 @@ skip = ["*-musllinux*", "pp*", "cp36-*"] [tool.cibuildwheel.macos] environment = "MACOSX_DEPLOYMENT_TARGET=10.14" archs = ["auto64", "arm64"] + +[tool.pytest.ini_options] +testpaths = ['tests'] diff --git a/python/tests/test_kiss_icp.py b/python/tests/test_kiss_icp.py new file mode 100644 index 00000000..1d55f470 --- /dev/null +++ b/python/tests/test_kiss_icp.py @@ -0,0 +1,4 @@ +def test_import(): + from kiss_icp.kiss_icp import KissICP + + assert KissICP is not None