diff --git a/cppython/project.py b/cppython/project.py index c9744b7..8045616 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from importlib import metadata +from pathlib import Path from typing import Any, Type, TypeVar from xmlrpc.client import Boolean @@ -98,7 +99,6 @@ def __init__( self, configuration: ProjectConfiguration, interface: Interface, pyproject_data: dict[str, Any] ) -> None: - self.enabled = False self.configuration = configuration if self.configuration.verbose: @@ -113,52 +113,51 @@ def __init__( return extended_pyproject_type = builder.generate_model(plugins) - pyproject = extended_pyproject_type(**pyproject_data) + self.pyproject = extended_pyproject_type(**pyproject_data) - if pyproject.tool is None: + if self.pyproject.tool is None: if self.configuration.verbose: interface.print("Table [tool] is not defined") return - if pyproject.tool.cppython is None: + if self.pyproject.tool.cppython is None: if self.configuration.verbose: interface.print("Table [tool.cppython] is not defined") return - self.enabled = True - self._interface = interface - self._generators = builder.create_generators(plugins, pyproject) + self._generators = builder.create_generators(plugins, self.pyproject) if self.configuration.verbose: interface.print("CPPython project initialized") - def download(self): + def download(self, path: Path): """ Download the generator tooling if required """ + for generator in self._generators: - if not generator.generator_downloaded(): + if not generator.generator_downloaded(path): self._interface.print(f"Downloading the {generator.name()} tool") # TODO: Make async with progress bar - generator.download_generator() + generator.download_generator(path) self._interface.print("Download complete") # API Contract def install(self) -> None: - if self.enabled: + if self.pyproject.tool and self.pyproject.tool.cppython: if self.configuration.verbose: self._interface.print("CPPython: Installing...") - self.download() + self.download(self.pyproject.tool.cppython.install_path) for generator in self._generators: generator.install() def update(self) -> None: - if self.enabled: + if self.pyproject.tool and self.pyproject.tool.cppython: if self.configuration.verbose: self._interface.print("CPPython: Updating...") @@ -166,7 +165,7 @@ def update(self) -> None: generator.update() def build(self) -> None: - if self.enabled: + if self.pyproject.tool and self.pyproject.tool.cppython: if self.configuration.verbose: self._interface.print("CPPython: Building...") diff --git a/pdm.lock b/pdm.lock index 4c48b29..ba8bfba 100644 --- a/pdm.lock +++ b/pdm.lock @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "cppython-core" -version = "0.1.4" +version = "0.2.1" requires_python = ">=3.10" summary = "Data definitions for CPPython" dependencies = [ @@ -199,11 +199,12 @@ dependencies = [ [[package]] name = "pytest-cppython" -version = "0.1.1" +version = "0.1.4" requires_python = ">=3.10" summary = "A pytest plugin that imports CPPython testing types" dependencies = [ - "cppython-core>=0.1.4", + "cppython-core>=0.2.1", + "pydantic>=1.9.0", ] [[package]] @@ -247,7 +248,7 @@ summary = "Module for decorators, wrappers and monkey patching." [metadata] lock_version = "3.1" -content_hash = "sha256:f53b6399862b1bc49a0ad0dc5017dfeb3c9348259b7b5fbabf9c7053678c9224" +content_hash = "sha256:df6c31dc4b507acddb260891407183bb5d4b0f4c62c8fbb39623d64f2a24ff2c" [metadata.files] "astroid 2.11.2" = [ @@ -338,9 +339,9 @@ content_hash = "sha256:f53b6399862b1bc49a0ad0dc5017dfeb3c9348259b7b5fbabf9c70536 {file = "coverage-6.3.2-pp36.pp37.pp38-none-any.whl", hash = "sha256:18d520c6860515a771708937d2f78f63cc47ab3b80cb78e86573b0a760161faf"}, {file = "coverage-6.3.2.tar.gz", hash = "sha256:03e2a7826086b91ef345ff18742ee9fc47a6839ccd517061ef8fa1976e652ce9"}, ] -"cppython-core 0.1.4" = [ - {file = "cppython_core-0.1.4-py3-none-any.whl", hash = "sha256:1856a7b9e58c3b95eb376fa01b04227c499726285868fce96152e52417d8178f"}, - {file = "cppython-core-0.1.4.tar.gz", hash = "sha256:cc787deda93fe3a3386d4c04e3dc209b9e7ff0d96fa3bab168047be11b911f9d"}, +"cppython-core 0.2.1" = [ + {file = "cppython_core-0.2.1-py3-none-any.whl", hash = "sha256:d5f7be4815b89c53bfd7bbc7653e1fc66e1cde022edebe78afc86f5b0d6a1de4"}, + {file = "cppython-core-0.2.1.tar.gz", hash = "sha256:001fb049a1d62c584eb1a2bcc8c4e4acad461ff583e875bb44ab5df9249b37b7"}, ] "dill 0.3.4" = [ {file = "dill-0.3.4-py2.py3-none-any.whl", hash = "sha256:7e40e4a70304fd9ceab3535d36e58791d9c4a776b38ec7f7ec9afc8d3dca4d4f"}, @@ -474,9 +475,9 @@ content_hash = "sha256:f53b6399862b1bc49a0ad0dc5017dfeb3c9348259b7b5fbabf9c70536 {file = "pytest_cov-3.0.0-py3-none-any.whl", hash = "sha256:578d5d15ac4a25e5f961c938b85a05b09fdaae9deef3bb6de9a6e766622ca7a6"}, {file = "pytest-cov-3.0.0.tar.gz", hash = "sha256:e7f0f5b1617d2210a2cabc266dfe2f4c75a8d32fb89eafb7ad9d06f6d076d470"}, ] -"pytest-cppython 0.1.1" = [ - {file = "pytest_cppython-0.1.1-py3-none-any.whl", hash = "sha256:712e3ae3bc8db1d6f60a44424860ea05a4df473dc6f710ba78afaaefa92fb70e"}, - {file = "pytest-cppython-0.1.1.tar.gz", hash = "sha256:47701ed86497548e77310ef4dc232fc2bcdbc029a279b545d07af380f2820ade"}, +"pytest-cppython 0.1.4" = [ + {file = "pytest_cppython-0.1.4-py3-none-any.whl", hash = "sha256:b0c04961114872fc1cb472b31d0028c958140682b4769a3da15b66c6299880ff"}, + {file = "pytest-cppython-0.1.4.tar.gz", hash = "sha256:4cfdf36f6c7f767a13f407ca48d65b3848d89b1f676e3fe74872bae3d3b05675"}, ] "pytest-mock 3.7.0" = [ {file = "pytest_mock-3.7.0-py3-none-any.whl", hash = "sha256:6cff27cec936bf81dc5ee87f07132b807bcda51106b5ec4b90a04331cba76231"}, diff --git a/pyproject.toml b/pyproject.toml index 320eeb4..744a2b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,9 +14,9 @@ dynamic = ["version"] requires-python = ">=3.10" dependencies = [ - "click>=8.0.3", - "tomlkit>=0.10.0", - "cppython-core>=0.1.4", + "click>=8.1.2", + "tomlkit>=0.10.1", + "cppython-core>=0.2.1", "pydantic>=1.9.0", ] @@ -40,7 +40,7 @@ test = [ "pytest>=7.1.1", "pytest-cov>=3.0.0", "pytest-mock>=3.7.0", - "pytest-cppython>=0.1.0", + "pytest-cppython>=0.1.4", ] [project.scripts] diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index 291971d..92a4768 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -29,7 +29,12 @@ def test_construction(self, mocker: MockerFixture): interface_mock = mocker.MagicMock() configuration = ProjectConfiguration() - Project(configuration, interface_mock, default_pyproject.dict()) + Project(configuration, interface_mock, default_pyproject.dict(by_alias=True)) + + def test_download(self): + """ + TODO + """ class TestBuilder: @@ -65,10 +70,10 @@ def test_generator_data_construction(self, mocker: MockerFixture): model_type = builder.generate_model([generator_type]) - project_data = default_pyproject.dict() + project_data = default_pyproject.dict(by_alias=True) mock_data = MockGeneratorData(check=True) - project_data["tool"]["cppython"]["mock"] = mock_data.dict() + project_data["tool"]["cppython"]["mock"] = mock_data.dict(by_alias=True) result = model_type(**project_data) assert result.tool is not None