From ad434ea0083e0ad8b0e8666813515fbc94221a46 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Mar 2022 16:22:51 -0500 Subject: [PATCH 1/6] Conditional Running --- cppython/plugins/test/data.py | 4 ++-- cppython/project.py | 15 ++++++++++----- cppython/schema.py | 9 +++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cppython/plugins/test/data.py b/cppython/plugins/test/data.py index 76a30e7..df49c7b 100644 --- a/cppython/plugins/test/data.py +++ b/cppython/plugins/test/data.py @@ -10,6 +10,6 @@ # CMake is a default plugin # TODO: Provide dynamic default -default_cppython_data = CPPythonData(generator="cmake", target=TargetEnum.EXE, install_path=Path()) +default_cppython_data = CPPythonData(**{"generator": "cmake", "target": TargetEnum.EXE, "install-path": Path()}) -default_pyproject = PyProject(pep_621=default_pep621, cppython_data=default_cppython_data) +default_pyproject = PyProject(project=default_pep621, cppython=default_cppython_data) diff --git a/cppython/project.py b/cppython/project.py index 20d195e..5300fba 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -16,6 +16,8 @@ class Project(API): def __init__(self, interface: Interface, pyproject: PyProject) -> None: + self.enabled = pyproject.cppython != None + self._interface = interface PluginType = TypeVar("PluginType", bound=Type[Plugin]) @@ -35,10 +37,10 @@ def find_plugin_type(plugin_type: PluginType, condition: Callable[[str], bool]) return None - plugin_type = find_plugin_type(Generator, lambda name: name == pyproject.cppython_data.generator) + plugin_type = find_plugin_type(Generator, lambda name: name == pyproject.cppython.generator) if plugin_type is None: - raise ConfigError(f"No generator plugin with the name '{pyproject.cppython_data.generator}' was found.") + raise ConfigError(f"No generator plugin with the name '{pyproject.cppython.generator}' was found.") generator_data = interface.read_generator_data(plugin_type.data_type()) self._generator = plugin_type(pyproject, generator_data) @@ -47,10 +49,13 @@ def find_plugin_type(plugin_type: PluginType, condition: Callable[[str], bool]) # API Contract def install(self) -> None: - self._generator.install() + if self.enabled: + self._generator.install() def update(self) -> None: - self._generator.update() + if self.enabled: + self._generator.update() def build(self) -> None: - self._generator.build() + if self.enabled: + self._generator.build() diff --git a/cppython/schema.py b/cppython/schema.py index ba363af..aea2566 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -5,9 +5,10 @@ from abc import ABC, abstractmethod from enum import Enum from pathlib import Path -from typing import Type, TypeVar +from typing import Optional, Type, TypeVar from pydantic import BaseModel +from pydantic.fields import Field class TargetEnum(Enum): @@ -40,7 +41,7 @@ class CPPythonData(BaseModel): generator: str target: TargetEnum dependencies: dict[str, str] = {} - install_path: Path + install_path: Path = Field(alias="install-path") class PyProject(BaseModel): @@ -48,8 +49,8 @@ class PyProject(BaseModel): pyproject.toml schema """ - pep_621: PEP621 - cppython_data: CPPythonData + project: PEP621 + cppython: Optional[CPPythonData] class API(ABC): From a8765b4cb53fd2745dc0936a3e047a0dfd7ef2c4 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Mar 2022 16:25:22 -0500 Subject: [PATCH 2/6] Install Generator --- cppython/project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cppython/project.py b/cppython/project.py index 5300fba..f05418f 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -50,6 +50,7 @@ def find_plugin_type(plugin_type: PluginType, condition: Callable[[str], bool]) def install(self) -> None: if self.enabled: + self._generator.install_generator() self._generator.install() def update(self) -> None: From 426b6f735dbdd47c0a578a138242dac1eaf5943c Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Mar 2022 17:17:16 -0500 Subject: [PATCH 3/6] Download and Print --- cppython/plugins/generator/cmake.py | 6 ++++-- cppython/plugins/interface/console.py | 4 +++- cppython/project.py | 11 +++++++++-- cppython/schema.py | 19 ++++++++++++++++--- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index ff859ce..83e266a 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -34,12 +34,14 @@ def data_type() -> Type[GeneratorData]: """ return CMakeData - def install_generator(self) -> bool: + def downloaded(self) -> bool: + return True + + def download(self) -> None: """ Installs the external tooling required by the generator if necessary Returns whether anything was installed or not """ - return False def install(self) -> None: raise NotImplementedError() diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index a2e6219..3137a8d 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -109,4 +109,6 @@ def write_pyproject(self) -> None: """ Write output """ - pass + + def print(self, string: str) -> None: + click.echo(string) diff --git a/cppython/project.py b/cppython/project.py index f05418f..2f6e769 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -44,13 +44,20 @@ def find_plugin_type(plugin_type: PluginType, condition: Callable[[str], bool]) generator_data = interface.read_generator_data(plugin_type.data_type()) self._generator = plugin_type(pyproject, generator_data) - self._generator.install_generator() + + def download(self): + """ + Download the generator tooling if required + """ + if not self._generator.downloaded(): + + self._generator.download() # API Contract def install(self) -> None: if self.enabled: - self._generator.install_generator() + self.download() self._generator.install() def update(self) -> None: diff --git a/cppython/schema.py b/cppython/schema.py index aea2566..9b0c8eb 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -132,6 +132,13 @@ def write_pyproject(self) -> None: """ raise NotImplementedError() + @abstractmethod + def print(self, string: str) -> None: + """ + Prints the given string into the Interface IO + """ + raise NotImplementedError() + class Generator(Plugin, API): """ @@ -166,9 +173,15 @@ def data_type() -> Type[GeneratorData]: raise NotImplementedError() @abstractmethod - def install_generator(self) -> bool: + def downloaded(self) -> bool: + """ + Returns whether the generator needs to be downloaded + """ + raise NotImplementedError() + + @abstractmethod + def download(self) -> None: """ - Installs the external tooling required by the generator if necessary - Returns whether anything was installed or not + Installs the external tooling required by the generator """ raise NotImplementedError() From 49f99f562956602603755e72d5c083cdcc7eacc7 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Mar 2022 17:17:36 -0500 Subject: [PATCH 4/6] Update data.py --- cppython/plugins/test/data.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cppython/plugins/test/data.py b/cppython/plugins/test/data.py index df49c7b..abdee63 100644 --- a/cppython/plugins/test/data.py +++ b/cppython/plugins/test/data.py @@ -9,7 +9,6 @@ default_pep621 = PEP621(name="test_name", version="1.0") # CMake is a default plugin -# TODO: Provide dynamic default default_cppython_data = CPPythonData(**{"generator": "cmake", "target": TargetEnum.EXE, "install-path": Path()}) default_pyproject = PyProject(project=default_pep621, cppython=default_cppython_data) From d5786764fff45fbe57aac6449a716a21bee9194d Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Mar 2022 17:20:40 -0500 Subject: [PATCH 5/6] Add Download Print --- cppython/project.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cppython/project.py b/cppython/project.py index 2f6e769..92284b0 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -50,8 +50,11 @@ def download(self): Download the generator tooling if required """ if not self._generator.downloaded(): + self._interface.print(f"Downloading the {self._generator.name()} tool") + # TODO: Make async with progress bar self._generator.download() + self._interface.print("Download complete") # API Contract From 1001334a9ac00314315c7b6b1f5ac4005a3892a4 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Mar 2022 17:39:08 -0500 Subject: [PATCH 6/6] Early out construction --- cppython/project.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cppython/project.py b/cppython/project.py index 92284b0..6bd8d7d 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -16,7 +16,10 @@ class Project(API): def __init__(self, interface: Interface, pyproject: PyProject) -> None: - self.enabled = pyproject.cppython != None + self.enabled = pyproject.cppython is not None + + if not self.enabled: + return self._interface = interface