diff --git a/cppython/project.py b/cppython/project.py index 8045616..1e7c66e 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -99,6 +99,7 @@ def __init__( self, configuration: ProjectConfiguration, interface: Interface, pyproject_data: dict[str, Any] ) -> None: + self._enabled = False self.configuration = configuration if self.configuration.verbose: @@ -125,39 +126,43 @@ def __init__( interface.print("Table [tool.cppython] is not defined") return + self._enabled = True + self._interface = interface self._generators = builder.create_generators(plugins, self.pyproject) if self.configuration.verbose: interface.print("CPPython project initialized") - def download(self, path: Path): + def download(self): """ Download the generator tooling if required """ + if self._enabled: + path = self.pyproject.tool.cppython.install_path - for generator in self._generators: + for generator in self._generators: - if not generator.generator_downloaded(path): - self._interface.print(f"Downloading the {generator.name()} tool") + if not generator.generator_downloaded(path): + self._interface.print(f"Downloading the {generator.name()} tool") - # TODO: Make async with progress bar - generator.download_generator(path) - self._interface.print("Download complete") + # TODO: Make async with progress bar + generator.download_generator(path) + self._interface.print("Download complete") # API Contract def install(self) -> None: - if self.pyproject.tool and self.pyproject.tool.cppython: + if self._enabled: if self.configuration.verbose: self._interface.print("CPPython: Installing...") - self.download(self.pyproject.tool.cppython.install_path) + self.download() for generator in self._generators: generator.install() def update(self) -> None: - if self.pyproject.tool and self.pyproject.tool.cppython: + if self._enabled: if self.configuration.verbose: self._interface.print("CPPython: Updating...") @@ -165,7 +170,7 @@ def update(self) -> None: generator.update() def build(self) -> None: - if self.pyproject.tool and self.pyproject.tool.cppython: + if self._enabled: if self.configuration.verbose: self._interface.print("CPPython: Building...") diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index 92a4768..9d3d85f 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -31,11 +31,30 @@ def test_construction(self, mocker: MockerFixture): configuration = ProjectConfiguration() Project(configuration, interface_mock, default_pyproject.dict(by_alias=True)) - def test_download(self): + def test_download(self, mocker: MockerFixture): """ TODO """ + interface_mock = mocker.MagicMock() + configuration = ProjectConfiguration() + + generator_type = mocker.Mock(spec=Generator) + generator_type.name.return_value = "mock" + generator_type.data_type.return_value = MockGeneratorData + + gather_override = mocker.patch.object(ProjectBuilder, "gather_plugins") + gather_override.return_value = [generator_type] + + project_data = default_pyproject.dict(by_alias=True) + mock_data = MockGeneratorData(check=True) + project_data["tool"]["cppython"]["mock"] = mock_data.dict(by_alias=True) + + project = Project(configuration, interface_mock, project_data) + + # TODO: This does not verify signature correctness + project.download() + class TestBuilder: """