diff --git a/cvs/cli_plugins/copy_config_plugin.py b/cvs/cli_plugins/copy_config_plugin.py index 3ff0abcb6..fcccabc19 100644 --- a/cvs/cli_plugins/copy_config_plugin.py +++ b/cvs/cli_plugins/copy_config_plugin.py @@ -1,5 +1,6 @@ from .base import SubcommandPlugin from cvs.extension import ExtensionConfig +from cvs.lib.utils_lib import cvs_package_root import os import shutil @@ -49,8 +50,7 @@ def _find_config_root(self): 1. Core cvs package (cvs/input/config_file, cvs/input/cluster_file, cvs/input/env_file) 2. Extension packages configured via extension.ini (e.g., cvs_extension/input) """ - plugin_dir = os.path.dirname(__file__) - cvs_dir = os.path.dirname(plugin_dir) # cvs/ + cvs_dir = cvs_package_root() config_root = os.path.join(cvs_dir, "input", "config_file") cluster_root = os.path.join(cvs_dir, "input", "cluster_file") env_root = os.path.join(cvs_dir, "input", "env_file") diff --git a/cvs/lib/run_config_paths.py b/cvs/lib/run_config_paths.py index 1987f0aac..eb44d3e21 100644 --- a/cvs/lib/run_config_paths.py +++ b/cvs/lib/run_config_paths.py @@ -31,10 +31,9 @@ def resolve_runner_results_base(run_config: dict) -> str: def _cvs_baseline_data_dir() -> str: - import cvs + from cvs.lib.utils_lib import cvs_package_root - root = os.path.dirname(os.path.abspath(cvs.__file__)) - return os.path.normpath(os.path.join(root, "baseline_data")) + return os.path.normpath(os.path.join(cvs_package_root(), "baseline_data")) def resolve_baseline_csv_folder(run_config: dict) -> Optional[str]: diff --git a/cvs/lib/unittests/test_utils_lib.py b/cvs/lib/unittests/test_utils_lib.py index 842982941..d4fddd93b 100644 --- a/cvs/lib/unittests/test_utils_lib.py +++ b/cvs/lib/unittests/test_utils_lib.py @@ -1,7 +1,9 @@ # cvs/lib/unittests/test_utils_lib.py +import os import unittest from unittest.mock import patch +import cvs import cvs.lib.utils_lib as utils_lib from cvs.parsers.schemas import AortaBenchmarkConfigFile @@ -19,6 +21,13 @@ def test_scan_test_results_no_failure(self, mock_fail_test): utils_lib.scan_test_results(out_dict) mock_fail_test.assert_not_called() + def test_cvs_package_root_matches_cvs_module_directory(self): + expected = os.path.dirname(os.path.abspath(cvs.__file__)) + self.assertEqual(utils_lib.cvs_package_root(), expected) + + def test_cvs_package_root_contains_input_dir(self): + self.assertTrue(os.path.isdir(os.path.join(utils_lib.cvs_package_root(), 'input'))) + class TestResolveTestConfigPlaceholdersAorta(unittest.TestCase): """Aorta benchmark YAML uses the same resolver as other CVS test suites (see tests/benchmark/test_aorta.py).""" diff --git a/cvs/lib/utils_lib.py b/cvs/lib/utils_lib.py index 8208a07f2..55e2c811d 100644 --- a/cvs/lib/utils_lib.py +++ b/cvs/lib/utils_lib.py @@ -16,6 +16,18 @@ log = globals.log +def cvs_package_root(): + """Absolute path to the installed/editable cvs package directory. + + This is the root cvs/input/, cvs/tests/, cvs/baseline_data/, etc. hang off + of -- not the repo root and not the process cwd -- so it resolves the same + way whether cvs was pip-installed or run from an editable checkout. + """ + import cvs + + return os.path.dirname(os.path.abspath(cvs.__file__)) + + def fail_test(msg): """ Record and report a test failure without immediately raising an exception.