From 059b172adcc36af36fd659ded85dd809868f2e3c Mon Sep 17 00:00:00 2001 From: Jacob Faibussowitsch Date: Wed, 14 May 2025 08:59:47 -0400 Subject: [PATCH 1/2] Add default project variables file --- pyproject.toml | 2 +- src/aedifix/config.py | 17 +++++++++++------ src/aedifix/templates/variables.mk.in | 5 +++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 src/aedifix/templates/variables.mk.in diff --git a/pyproject.toml b/pyproject.toml index f9417bf..49a5ad8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta" [project] name = "aedifix" authors = [{name = "NVIDIA Corporation"}] -license = { text = "Apache-2.0" } +license = "Apache-2.0" description = "aedifix - Build system for Legate libraries" classifiers = [ "Intended Audience :: Developers", diff --git a/src/aedifix/config.py b/src/aedifix/config.py index 248c237..6346006 100644 --- a/src/aedifix/config.py +++ b/src/aedifix/config.py @@ -5,6 +5,7 @@ import re import sys +from pathlib import Path from typing import TYPE_CHECKING, Final from .base import Configurable @@ -12,8 +13,6 @@ from .util.utility import cmake_configure_file if TYPE_CHECKING: - from pathlib import Path - from .manager import ConfigurationManager @@ -26,14 +25,15 @@ class ConfigFile(Configurable): """ __slots__ = ( - "_cmake_configure_file", "_config_file_template", "_default_subst", "_project_variables_file", ) def __init__( - self, manager: ConfigurationManager, config_file_template: Path + self, + manager: ConfigurationManager, + config_file_template: Path | None = None, ) -> None: r"""Construct a Config. @@ -41,10 +41,15 @@ def __init__( ---------- manager : ConfigurationManager The configuration manager to manage this Config. - config_file_template : Path - The template file to read + config_file_template : Path, optional + The template file to read, or None to use the default template + file. """ super().__init__(manager=manager) + if config_file_template is None: + config_file_template = ( + Path(__file__).resolve() / "templates" / "variables.mk.in" + ) self._config_file_template = config_file_template.resolve() config_file = self.template_file diff --git a/src/aedifix/templates/variables.mk.in b/src/aedifix/templates/variables.mk.in new file mode 100644 index 0000000..7275eb2 --- /dev/null +++ b/src/aedifix/templates/variables.mk.in @@ -0,0 +1,5 @@ +# -*- mode: makefile-gmake -*- +export PYTHON ?= @AEDIFIX_PYTHON_EXECUTABLE@ +export CMAKE ?= @CMAKE_COMMAND@ +export CMAKE_BUILD_PARALLEL_LEVEL ?= @CMAKE_BUILD_PARALLEL_LEVEL@ +export CMAKE_GENERATOR ?= @CMAKE_GENERATOR@ From f6ea5ab327f27e6bb38078b0fa76430349a6a774 Mon Sep 17 00:00:00 2001 From: Jacob Faibussowitsch Date: Wed, 14 May 2025 09:20:11 -0400 Subject: [PATCH 2/2] fixup! Add default project variables file --- src/aedifix/config.py | 16 +++++----------- src/aedifix/package/main_package.py | 18 ++++++++++++------ tests/fixtures/dummy_main_module.py | 7 +------ tests/test_manager.py | 10 ++-------- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/aedifix/config.py b/src/aedifix/config.py index 6346006..afc508d 100644 --- a/src/aedifix/config.py +++ b/src/aedifix/config.py @@ -5,7 +5,6 @@ import re import sys -from pathlib import Path from typing import TYPE_CHECKING, Final from .base import Configurable @@ -13,6 +12,8 @@ from .util.utility import cmake_configure_file if TYPE_CHECKING: + from pathlib import Path + from .manager import ConfigurationManager @@ -31,9 +32,7 @@ class ConfigFile(Configurable): ) def __init__( - self, - manager: ConfigurationManager, - config_file_template: Path | None = None, + self, manager: ConfigurationManager, config_file_template: Path ) -> None: r"""Construct a Config. @@ -41,15 +40,10 @@ def __init__( ---------- manager : ConfigurationManager The configuration manager to manage this Config. - config_file_template : Path, optional - The template file to read, or None to use the default template - file. + config_file_template : Path + The template file to read. """ super().__init__(manager=manager) - if config_file_template is None: - config_file_template = ( - Path(__file__).resolve() / "templates" / "variables.mk.in" - ) self._config_file_template = config_file_template.resolve() config_file = self.template_file diff --git a/src/aedifix/package/main_package.py b/src/aedifix/package/main_package.py index 5be9522..e060e7d 100644 --- a/src/aedifix/package/main_package.py +++ b/src/aedifix/package/main_package.py @@ -372,7 +372,7 @@ def __init__( # noqa: PLR0913 arch_name: str, project_dir_name: str, project_dir_value: Path, - project_config_file_template: Path, + project_config_file_template: Path | None = None, project_src_dir: Path | None = None, default_arch_file_path: Path | None = None, ) -> None: @@ -390,9 +390,11 @@ def __init__( # noqa: PLR0913 The name of the project dir variable, e.g. 'LEGATE_DIR'. project_dir_value : Path The value of the project dir, e.g. /path/to/legate. - project_config_file_template: Path + project_config_file_template: Path, optional A path to a configure file template to fill out and place under - PROJECT_DIR/PROJECT_ARCH on successful configure. + PROJECT_DIR/PROJECT_ARCH on successful configure. If not given, + a default template file containing PYTHON, CMAKE, + CMAKE_BUILD_PARALLEL_LEVEL, and CMAKE_GENERATOR will be used. project_src_dir : Path, optional The path to the projects source directory for CMake. If not provided, ``project_dir_value`` is used instead. @@ -414,6 +416,11 @@ def __init__( # noqa: PLR0913 assert not arch_name.endswith("_") assert arch_name.isupper() assert arch_name.endswith("ARCH") + if project_config_file_template is None: + project_config_file_template = ( + Path(__file__).parents[1] / "templates" / "variables.mk.in" + ).resolve(strict=True) + if not project_config_file_template.exists(): msg = ( f"Project configure file: {project_config_file_template} does " @@ -426,6 +433,7 @@ def __init__( # noqa: PLR0913 "not a file" ) raise ValueError(msg) + self._arch_name = arch_name self._arch_value, self._arch_value_provenance = ( self.preparse_arch_value(argv) @@ -441,9 +449,7 @@ def __init__( # noqa: PLR0913 raise ValueError(msg) self._proj_dir_name = project_dir_name self._proj_dir_value = project_dir_value.resolve(strict=True) - self._proj_config_file_template = ( - project_config_file_template.resolve() - ) + self._proj_config_file_template = project_config_file_template if project_src_dir is None: project_src_dir = self._proj_dir_value self._proj_src_dir = project_src_dir.resolve(strict=True) diff --git a/tests/fixtures/dummy_main_module.py b/tests/fixtures/dummy_main_module.py index 186a742..c3c7f22 100644 --- a/tests/fixtures/dummy_main_module.py +++ b/tests/fixtures/dummy_main_module.py @@ -5,8 +5,7 @@ from os import environ from pathlib import Path -from tempfile import NamedTemporaryFile -from typing import TYPE_CHECKING, Final +from typing import TYPE_CHECKING from .dummy_main_package import DummyMainPackage @@ -15,9 +14,6 @@ from aedifix.manager import ConfigurationManager -_tmp_file: Final = NamedTemporaryFile() # noqa: SIM115 -_tmp_path: Final = Path(_tmp_file.name) - class DummyMainModule(DummyMainPackage): name = "DummyMainModule" @@ -31,7 +27,6 @@ def __init__( arch_name="AEDIFIX_PYTEST_ARCH", project_dir_name="AEDIFIX_PYTEST_DIR", project_dir_value=Path(environ["AEDIFIX_PYTEST_DIR"]), - project_config_file_template=_tmp_path, ) @classmethod diff --git a/tests/test_manager.py b/tests/test_manager.py index ba38762..216cffa 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -28,11 +28,6 @@ from pathlib import Path -@pytest.fixture -def manager() -> ConfigurationManager: - return ConfigurationManager((), DummyMainModule) - - class TestConfigurationManager: @pytest.mark.parametrize( "argv", ((), ("--foo",), ("-b", "1", "--bar=baz")) @@ -79,9 +74,8 @@ def test_create( assert (manager._aedifix_root_dir / "aedifix").exists() assert (manager._aedifix_root_dir / "aedifix").is_dir() - def test_setup( - self, manager: ConfigurationManager, AEDIFIX_PYTEST_ARCH: str - ) -> None: + def test_setup(self, AEDIFIX_PYTEST_ARCH: str) -> None: + manager = ConfigurationManager((), DummyMainModule) orig_argv = deepcopy(manager.argv) assert len(manager._modules) == 1 manager.setup()