From dee1162d3a875b4759253c8462dfe8c0148df94c Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 7 Nov 2023 16:36:06 +0100 Subject: [PATCH 1/3] fix: replace relative paths for custom module with absolute ones in parse_yaml() --- junifer/api/parser.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/junifer/api/parser.py b/junifer/api/parser.py index 56bccf9a4..97ecf3fc2 100644 --- a/junifer/api/parser.py +++ b/junifer/api/parser.py @@ -50,6 +50,8 @@ def parse_yaml(filepath: Union[str, Path]) -> Dict: # Convert load modules to list if not isinstance(to_load, list): to_load = [to_load] + # Initialize list to have absolute paths for custom modules + final_to_load = [] for t_module in to_load: if t_module.endswith(".py"): logger.debug(f"Importing file: {t_module}") @@ -65,9 +67,18 @@ def parse_yaml(filepath: Union[str, Path]) -> Dict: module = importlib.util.module_from_spec(spec) # type: ignore sys.modules[t_module] = module spec.loader.exec_module(module) # type: ignore + # Add absolute path to final list + final_to_load.append(str(file_path.resolve())) else: logger.info(f"Importing module: {t_module}") importlib.import_module(t_module) + # Add module to final list + final_to_load.append(t_module) + + # Replace modules to be loaded so that custom modules will take the + # absolute path. This was not the case as found in #224. Similar thing + # is done with the storage URI below. + contents["with"] = final_to_load # Compute path for the URI parameter in storage files that are relative # This is a tricky thing that appeared in #127. The problem is that -- 2.52.0 From f4f45d981bb3b7741e5bc1616d887a87a3b6db1d Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 17 Nov 2023 10:55:47 +0100 Subject: [PATCH 2/3] chore: add changelog 224.bugfix --- docs/changes/newsfragments/224.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/newsfragments/224.bugfix diff --git a/docs/changes/newsfragments/224.bugfix b/docs/changes/newsfragments/224.bugfix new file mode 100644 index 000000000..ec0b01b64 --- /dev/null +++ b/docs/changes/newsfragments/224.bugfix @@ -0,0 +1 @@ +Make copying of assets in ``with`` block of YAML, relative to YAML and not to current working directory by `Fede Raimondo`_ and `Synchon Mandal`_ -- 2.52.0 From 62567ad665d0398b6cb06e5a70a59686c6494e13 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 17 Nov 2023 11:32:10 +0100 Subject: [PATCH 3/3] fix: update parse_yaml() test --- 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 bf5bcb58d..adad752c0 100644 --- a/junifer/api/tests/test_parser.py +++ b/junifer/api/tests/test_parser.py @@ -53,7 +53,7 @@ def test_parse_yaml_success_with_module_autoload(tmp_path: Path) -> None: assert "foo" in contents assert contents["foo"] == "bar" assert "with" in contents - assert contents["with"] == "numpy" + assert contents["with"] == ["numpy"] assert "numpy" in sys.modules assert "junifer.configs.wrong_config" not in sys.modules -- 2.52.0