From ad434ea0083e0ad8b0e8666813515fbc94221a46 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Mar 2022 16:22:51 -0500 Subject: [PATCH 01/10] 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 02/10] 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 03/10] 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 04/10] 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 05/10] 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 06/10] 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 From 7fd7824a93d899cdb43ef798a757ceb725370385 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Mon, 7 Mar 2022 21:31:51 -0500 Subject: [PATCH 07/10] Remove Abstract Requirement From Generator --- .github/workflows/{release.yml => python-publish.yml} | 0 cppython/plugins/generator/cmake.py | 4 +++- cppython/schema.py | 4 ---- 3 files changed, 3 insertions(+), 5 deletions(-) rename .github/workflows/{release.yml => python-publish.yml} (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/python-publish.yml similarity index 100% rename from .github/workflows/release.yml rename to .github/workflows/python-publish.yml diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index 83e266a..b7300ce 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -18,7 +18,9 @@ class CMakeGenerator(Generator): """ def __init__(self, pyproject: PyProject, cmake_data: CMakeData) -> None: - super().__init__(pyproject, cmake_data) + """ + TODO + """ @staticmethod def name() -> str: diff --git a/cppython/schema.py b/cppython/schema.py index 9b0c8eb..388800a 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -145,10 +145,6 @@ class Generator(Plugin, API): Abstract type to be inherited by CPPython Generator plugins """ - @abstractmethod - def __init__(self, pyproject: PyProject, generator_data: GeneratorData) -> None: - super().__init__() - @staticmethod def plugin_group() -> str: """ From 6287c1cd902a8449af34cb3f768fc074fd0d3061 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 9 Mar 2022 06:31:40 -0500 Subject: [PATCH 08/10] Update Metadata --- pyproject.toml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index de30104..a8d599a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,17 +2,13 @@ description = " A Python package manager agnostic plugin integrating a transparent Conan and CMake workflow." name = "cppython" -license = "MIT" +license-expression = "MIT" authors = [ - "Synodic Software", + {name = "Synodic Software", email = "contact@synodic.software"}, ] - readme = "README.md" -homepage = "https://github.com/Synodic-Software/CPPython" -repository = "https://github.com/Synodic-Software/CPPython" - dynamic = ["version"] requires-python = ">=3.10" @@ -25,6 +21,13 @@ dependencies = [ "pytest>=7.0.0", # Required for testing injection ] +[project.license-files] +paths = ["LICENSE.md"] + +[project.urls] +homepage = "https://github.com/Synodic-Software/CPPython" +repository = "https://github.com/Synodic-Software/CPPython" + [tool.pdm] version = {use_scm = true} From 45deb1084756099eebf43a0536aab9a2d912330f Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 10 Mar 2022 05:51:28 -0500 Subject: [PATCH 09/10] Readd Abstract Init --- cppython/schema.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cppython/schema.py b/cppython/schema.py index 388800a..bf2c758 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -145,6 +145,12 @@ class Generator(Plugin, API): Abstract type to be inherited by CPPython Generator plugins """ + @abstractmethod + def __init__(self, pyproject: PyProject, generator_data: GeneratorData) -> None: + """ + TODO + """ + @staticmethod def plugin_group() -> str: """ From 6dd8e326ce9cf5eca675d188147e42729c45b35a Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 10 Mar 2022 06:35:41 -0500 Subject: [PATCH 10/10] Add Tooling Update Requirement --- cppython/plugins/generator/cmake.py | 16 ++++++++++------ cppython/schema.py | 13 ++++++++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index b7300ce..3f708c9 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -18,9 +18,7 @@ class CMakeGenerator(Generator): """ def __init__(self, pyproject: PyProject, cmake_data: CMakeData) -> None: - """ - TODO - """ + self.data = cmake_data @staticmethod def name() -> str: @@ -36,13 +34,19 @@ def data_type() -> Type[GeneratorData]: """ return CMakeData - def downloaded(self) -> bool: + def generator_downloaded(self) -> bool: + + # CMake tooling is a part of the python package tooling return True - def download(self) -> None: + def download_generator(self) -> None: """ Installs the external tooling required by the generator if necessary - Returns whether anything was installed or not + """ + + def update_generator(self) -> None: + """ + Update the tooling required by the generator """ def install(self) -> None: diff --git a/cppython/schema.py b/cppython/schema.py index bf2c758..6c777bc 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -148,7 +148,7 @@ class Generator(Plugin, API): @abstractmethod def __init__(self, pyproject: PyProject, generator_data: GeneratorData) -> None: """ - TODO + Allows CPPython to pass the relevant data to constructed Generator plugin """ @staticmethod @@ -175,15 +175,22 @@ def data_type() -> Type[GeneratorData]: raise NotImplementedError() @abstractmethod - def downloaded(self) -> bool: + def generator_downloaded(self) -> bool: """ Returns whether the generator needs to be downloaded """ raise NotImplementedError() @abstractmethod - def download(self) -> None: + def download_generator(self) -> None: """ Installs the external tooling required by the generator """ raise NotImplementedError() + + @abstractmethod + def update_generator(self) -> None: + """ + Update the tooling required by the generator + """ + raise NotImplementedError()