Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/aedifix/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ConfigFile(Configurable):
"_cmake_configure_file",
"_config_file_template",
"_default_subst",
"_project_variables_file",
)

def __init__(
Expand All @@ -45,6 +46,13 @@ def __init__(
"""
super().__init__(manager=manager)
self._config_file_template = config_file_template.resolve()

config_file = self.template_file
if config_file.suffix == ".in":
# remove the trailing .in
config_file = config_file.with_suffix("")

self._project_variables_file = self.project_arch_dir / config_file.name
self._default_subst = {"PYTHON_EXECUTABLE": sys.executable}

@property
Expand Down Expand Up @@ -72,7 +80,7 @@ def project_variables_file(self) -> Path:
The file is not guaranteed to exist, or be up to date. Usually it is
created/refreshed during finalization of this object.
"""
return self.project_arch_dir / "gmakevariables"
return self._project_variables_file

def _read_entire_cmake_cache(self, cmake_cache: Path) -> dict[str, str]:
r"""Read a CMakeCache.txt and convert all of the cache values to
Expand Down Expand Up @@ -164,7 +172,7 @@ def finalize(self) -> None:
If the user config file contains an unknown AEDIFIX substitution.
"""
project_file = self.project_variables_file
template_file = self._config_file_template
template_file = self.template_file
self.log(f"Using project file: {project_file}")
self.log(f"Using template file: {template_file}")

Expand Down
22 changes: 21 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,29 @@ def test_create(self, manager: DummyManager, tmp_path: Path) -> None:
assert config.template_file.exists()
assert config.template_file.is_file()
assert config.template_file == template

assert (
config.project_variables_file.name == template.with_suffix("").name
)
assert config._default_subst == {"PYTHON_EXECUTABLE": sys.executable}

@pytest.mark.parametrize(
("base", "expected"),
(
("foo.bar.baz.in", "foo.bar.baz"),
("foo.bar", "foo.bar"),
("foo", "foo"),
),
)
def test_project_variables_file(
self, manager: DummyManager, tmp_path: Path, base: str, expected: str
) -> None:
template = tmp_path / base
template.touch()

config = ConfigFile(manager=manager, config_file_template=template)

assert config.project_variables_file.name == expected


if __name__ == "__main__":
sys.exit(pytest.main())