From 59140f5e0c1d52107b0f4cf6cf0701222e777a16 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 30 Mar 2023 12:26:03 +0200 Subject: [PATCH 1/7] chore: add missing abstractmethod decorator for BaseMarker --- junifer/markers/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/junifer/markers/base.py b/junifer/markers/base.py index ba1c03da2..c78097c5d 100644 --- a/junifer/markers/base.py +++ b/junifer/markers/base.py @@ -45,6 +45,7 @@ class BaseMarker(ABC, PipelineStepMixin, UpdateMetaMixin): raise ValueError(f"{self.name} cannot be computed on {wrong_on}") self._on = on + @abstractmethod def get_valid_inputs(self) -> List[str]: """Get valid data types for input. -- 2.52.0 From 152a2218338da63a8dc35fcb0cdf633b70d34347 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 30 Mar 2023 12:26:37 +0200 Subject: [PATCH 2/7] chore: add missing abstractmethod decorator for BasePreprocessor --- junifer/preprocess/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/junifer/preprocess/base.py b/junifer/preprocess/base.py index c9f8b97e9..2423cc251 100644 --- a/junifer/preprocess/base.py +++ b/junifer/preprocess/base.py @@ -79,6 +79,7 @@ class BasePreprocessor(ABC, PipelineStepMixin, UpdateMetaMixin): klass=NotImplementedError, ) + @abstractmethod def get_valid_inputs(self) -> List[str]: """Get valid data types for input. -- 2.52.0 From 31d499c056eade8f6899a18afea34c5445a4a335 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 30 Mar 2023 13:30:58 +0200 Subject: [PATCH 3/7] chore: add changelog file 214.enh --- docs/changes/newsfragments/214.enh | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/newsfragments/214.enh diff --git a/docs/changes/newsfragments/214.enh b/docs/changes/newsfragments/214.enh new file mode 100644 index 000000000..8d22c9224 --- /dev/null +++ b/docs/changes/newsfragments/214.enh @@ -0,0 +1 @@ +Add missing ``abstractmethod`` decorators for ``get_valid_inputs`` methods of :class:`junifer.markers.BaseMarker` and :class:`junifer.preprocess.BasePreprocessor`. \ No newline at end of file -- 2.52.0 From dc509867595fc1b6b1660d03719a36224a388a2d Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 30 Mar 2023 14:06:08 +0200 Subject: [PATCH 4/7] chore: add author in changelog 214.enh --- docs/changes/newsfragments/214.enh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changes/newsfragments/214.enh b/docs/changes/newsfragments/214.enh index 8d22c9224..dcd629ae6 100644 --- a/docs/changes/newsfragments/214.enh +++ b/docs/changes/newsfragments/214.enh @@ -1 +1 @@ -Add missing ``abstractmethod`` decorators for ``get_valid_inputs`` methods of :class:`junifer.markers.BaseMarker` and :class:`junifer.preprocess.BasePreprocessor`. \ No newline at end of file +Add missing ``abstractmethod`` decorators for ``get_valid_inputs`` methods of :class:`junifer.markers.BaseMarker` and :class:`junifer.preprocess.BasePreprocessor` by `Synchon Mandal`_ \ No newline at end of file -- 2.52.0 From 2aa95d24184629d5081cd1198adccbb002dda8e7 Mon Sep 17 00:00:00 2001 From: Fede Raimondo Date: Thu, 30 Mar 2023 15:07:07 +0200 Subject: [PATCH 5/7] Fix for 191 --- docs/changes/newsfragments/191.bugfix | 1 + junifer/api/parser.py | 3 +-- junifer/api/tests/test_parser.py | 30 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 docs/changes/newsfragments/191.bugfix diff --git a/docs/changes/newsfragments/191.bugfix b/docs/changes/newsfragments/191.bugfix new file mode 100644 index 000000000..d2c3dede9 --- /dev/null +++ b/docs/changes/newsfragments/191.bugfix @@ -0,0 +1 @@ +Fix a bug in which relative paths in the YAML ``with`` directive would be computed relative to the current working directory of the process instead of the location of the YAML file by `Fede Raimondo`_. \ No newline at end of file diff --git a/junifer/api/parser.py b/junifer/api/parser.py index 18d37552c..985133f6b 100644 --- a/junifer/api/parser.py +++ b/junifer/api/parser.py @@ -6,7 +6,6 @@ import importlib import importlib.util -import os import sys from pathlib import Path from typing import Dict, Union @@ -56,7 +55,7 @@ def parse_yaml(filepath: Union[str, Path]) -> Dict: for t_module in to_load: if t_module.endswith(".py"): logger.debug(f"Importing file: {t_module}") - file_path = Path(os.getcwd()) / t_module + file_path = filepath.parent / t_module if not file_path.exists(): raise_error( f"File in 'with' section does not exist: {file_path}" diff --git a/junifer/api/tests/test_parser.py b/junifer/api/tests/test_parser.py index e61ff9fdb..af6103bae 100644 --- a/junifer/api/tests/test_parser.py +++ b/junifer/api/tests/test_parser.py @@ -75,3 +75,33 @@ def test_parse_yaml_failure_with_multi_module_autoload(tmp_path: Path) -> None: # Check test file with pytest.raises(ImportError, match="wrong_config"): parse_yaml(fname) + + +def test_parse_yaml_relative_path(tmp_path: Path) -> None: + """Test YAML parsing with relative paths in with. + + Parameters + ---------- + tmp_path : pathlib.Path + The path to the test directory. + + """ + t_tmp_path = tmp_path / "test_relative_with" + + # Write .py to include + py_path = t_tmp_path / "external" + py_path.mkdir(exist_ok=True, parents=True) + py_fname = py_path / "first.py" + py_fname.write_text("import numpy as np\n") + + # Write yaml that includes a relative path + yaml_path = t_tmp_path / "yamls" + yaml_path.mkdir(exist_ok=True, parents=True) + yaml_fname = yaml_path / "test_parse_yaml_relative_path.yaml" + + yaml_fname.write_text( + "foo: bar\nwith:\n - ../external/first.py\n - scipy\n" + ) + + # Check test file + parse_yaml(yaml_fname) -- 2.52.0 From 8bc14afa2f6a750118834335546eed860a5fb6e0 Mon Sep 17 00:00:00 2001 From: Fede Raimondo Date: Thu, 30 Mar 2023 15:15:05 +0200 Subject: [PATCH 6/7] Add test for absolute paths now --- junifer/api/parser.py | 1 + junifer/api/tests/test_parser.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/junifer/api/parser.py b/junifer/api/parser.py index 985133f6b..8111f39f6 100644 --- a/junifer/api/parser.py +++ b/junifer/api/parser.py @@ -55,6 +55,7 @@ def parse_yaml(filepath: Union[str, Path]) -> Dict: for t_module in to_load: if t_module.endswith(".py"): logger.debug(f"Importing file: {t_module}") + # This resolves both absolute and relative paths file_path = filepath.parent / t_module if not file_path.exists(): raise_error( diff --git a/junifer/api/tests/test_parser.py b/junifer/api/tests/test_parser.py index af6103bae..ecae55256 100644 --- a/junifer/api/tests/test_parser.py +++ b/junifer/api/tests/test_parser.py @@ -105,3 +105,33 @@ def test_parse_yaml_relative_path(tmp_path: Path) -> None: # Check test file parse_yaml(yaml_fname) + + +def test_parse_yaml_absolute_path(tmp_path: Path) -> None: + """Test YAML parsing with absolute paths in with. + + Parameters + ---------- + tmp_path : pathlib.Path + The path to the test directory. + + """ + t_tmp_path = tmp_path / "test_relative_with" + + # Write .py to include + py_path = t_tmp_path / "external" + py_path.mkdir(exist_ok=True, parents=True) + py_fname = py_path / "first.py" + py_fname.write_text("import numpy as np\n") + + # Write yaml that includes a relative path + yaml_path = t_tmp_path / "yamls" + yaml_path.mkdir(exist_ok=True, parents=True) + yaml_fname = yaml_path / "test_parse_yaml_relative_path.yaml" + + yaml_fname.write_text( + f"foo: bar\nwith:\n - {py_fname.absolute()}\n - scipy\n" + ) + + # Check test file + parse_yaml(yaml_fname) \ No newline at end of file -- 2.52.0 From d8e0be918e4acbfa800a93ae1a91c77cb4ffdb53 Mon Sep 17 00:00:00 2001 From: Fede Raimondo Date: Thu, 30 Mar 2023 15:15:13 +0200 Subject: [PATCH 7/7] lint --- junifer/api/tests/test_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junifer/api/tests/test_parser.py b/junifer/api/tests/test_parser.py index ecae55256..6585a1809 100644 --- a/junifer/api/tests/test_parser.py +++ b/junifer/api/tests/test_parser.py @@ -134,4 +134,4 @@ def test_parse_yaml_absolute_path(tmp_path: Path) -> None: ) # Check test file - parse_yaml(yaml_fname) \ No newline at end of file + parse_yaml(yaml_fname) -- 2.52.0