From 73534117a7947085da27adc98ef6c94036442ea8 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 19 Dec 2021 08:26:17 -0500 Subject: [PATCH 01/55] Comments and Style --- .vscode/settings.json | 14 +++++++-- cppython/exceptions.py | 10 +++++++ cppython/plugins/generator/cmake.py | 18 ++++------- cppython/plugins/interface/console.py | 23 +++++++------- cppython/plugins/test/pytest.py | 3 ++ cppython/project.py | 27 +++++++---------- cppython/schema.py | 43 ++++++++++++++++++++++----- pdm.lock | 12 ++++---- pyproject.toml | 11 ++++--- tests/conftest.py | 6 ++-- tests/integration/test_cli.py | 5 ++++ tests/integration/test_project.py | 5 ++++ tests/unit/test_generator.py | 2 +- tests/unit/test_interface.py | 4 +-- tests/unit/test_plugin.py | 1 - tests/unit/test_project.py | 3 ++ 16 files changed, 120 insertions(+), 67 deletions(-) delete mode 100644 tests/unit/test_plugin.py diff --git a/.vscode/settings.json b/.vscode/settings.json index eb0a85b..7e18c67 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,8 +5,18 @@ "python.testing.pytestArgs": [ "tests" ], + "python.formatting.provider": "black", + "python.formatting.blackPath": "${workspaceRoot}/__pypackages__/3.10/Scripts/black", "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, - "python.autoComplete.extraPaths": ["__pypackages__//lib"], - "python.analysis.extraPaths": ["__pypackages__//lib"] + "python.autoComplete.extraPaths": [ + "__pypackages__/3.10/lib" + ], + "python.analysis.extraPaths": [ + "__pypackages__/3.10/lib" + ], + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": true + } } \ No newline at end of file diff --git a/cppython/exceptions.py b/cppython/exceptions.py index 9d6f966..24b0f41 100644 --- a/cppython/exceptions.py +++ b/cppython/exceptions.py @@ -4,6 +4,10 @@ class ConfigError(Exception): + """ + Raised when there is a configuration error + """ + def __init__(self, error: Exception) -> None: self._error = error @@ -11,4 +15,10 @@ def __init__(self, error: Exception) -> None: @property def error(self) -> Exception: + """ + Accessor to the config error Exception base type + + Returns: + Exception -- The base error type + """ return self._error diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index 2fcb45b..e9fdaf5 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -1,4 +1,4 @@ -from cppython.schema import Generator, Metadata +from cppython.schema import PEP621, Generator, Metadata class CMakeGenerator(Generator): @@ -6,12 +6,10 @@ class CMakeGenerator(Generator): A CPPython generator implementing a CMake backend """ - def __init__(self) -> None: - pass + def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: dict) -> None: + super().__init__(pep_612, cppython_data, generator_data) - """ - Plugin Contract - """ + # Plugin Contract @staticmethod def name() -> str: @@ -20,9 +18,7 @@ def name() -> str: """ return "cmake" - """ - Generator Contract - """ + # Generator Contract def populate_metadata(self, data: dict): """ @@ -36,9 +32,7 @@ def populate_plugin(self, data: dict): """ pass - """ - API Contract - """ + # API Contract def install(self) -> None: raise NotImplementedError() diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index b724682..2a91a49 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -1,10 +1,15 @@ -from cppython.project import Project -from cppython.schema import Interface, PEP621 +""" +TODO: +""" + from pathlib import Path import click import tomlkit +from cppython.project import Project +from cppython.schema import PEP621, Interface + def _read_data(): path = Path.cwd() @@ -12,13 +17,13 @@ def _read_data(): while not path.glob("pyproject.toml"): if path.is_absolute(): assert ( - "This is not a valid project. No pyproject.toml found in the current directory or any of its parents." - ) + False + ), "This is not a valid project. No pyproject.toml found in the current directory or any of its parents." return tomlkit.loads(Path(path / "pyproject.toml").read_text(encoding="utf-8")) -class Config(object): +class Config: """ The data object that will be expanded alongside 'pass_obj' """ @@ -75,9 +80,7 @@ class ConsoleInterface(Interface): def __init__(self, data: dict) -> None: self._data = data - """ - Plugin Contract - """ + # Plugin Contract @staticmethod def name() -> str: @@ -86,9 +89,7 @@ def name() -> str: """ return "console" - """ - Interface Contract - """ + # Interface Contract @staticmethod def external_config() -> bool: diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index fb55b68..563a3f0 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -1,3 +1,6 @@ +""" +TODO: +""" import pytest diff --git a/cppython/project.py b/cppython/project.py index 8b339aa..cb29c7d 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -1,11 +1,10 @@ -from typing import Type, Callable - -from cppython.schema import API, Interface, Generator, Metadata, PEP621, Plugin -from cppython.exceptions import ConfigError - -import pkgutil import importlib import inspect +import pkgutil +from typing import Callable, Type + +from cppython.exceptions import ConfigError +from cppython.schema import API, PEP621, Generator, Interface, Metadata, Plugin class Project(API): @@ -21,20 +20,16 @@ def _parse_PEP621_data(self, data: dict, interface_type: Interface) -> PEP621: # Each plugin reads its own configuration file, interfaces without external data need a helping hand parsing it if not interface_type.external_config(): - """ - If the interface doesn't support an external configuration, search for a plugin that does - """ + # If the interface doesn't support an external configuration, search for a plugin that does temporary_interface_type = self._load_interface([*data["tool"]]) if temporary_interface_type is None: - """ - If there is no applicable plugin, we are interfaceing the toml project without a python buildsystem - """ + # If there is no applicable plugin, we are interfaceing the toml project without a python buildsystem + return self._interface.pep_621() - else: - return temporary_interface_type.parse_pep_621(data) + return temporary_interface_type.parse_pep_621(data) else: return self._interface.pep_621() @@ -104,9 +99,7 @@ def load(self): self.loaded = True - """ - API Contract - """ + # API Contract def install(self) -> None: self._generator.install() diff --git a/cppython/schema.py b/cppython/schema.py index 6e7a49b..9c37909 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -1,14 +1,22 @@ +""" +Data types for CPPython that encapsulate the requirements between the plugins and the core library +""" + from abc import ABC, abstractmethod -from pathlib import Path from enum import Enum +from pathlib import Path from pydantic import BaseModel, Field class TargetEnum(Enum): - exe = "executable" - static = "static" - shared = "shared" + """ + The C++ build target type + """ + + EXE = "executable" + STATIC = "static" + SHARED = "shared" class PEP621(BaseModel): @@ -42,14 +50,32 @@ class API(ABC): @abstractmethod def install(self) -> None: + """ + Called when dependencies need to be installed from a lock file. + + Raises: + NotImplementedError: [description] + """ raise NotImplementedError() @abstractmethod def update(self) -> None: + """ + Called when dependencies need to be updated and written to the lock file. + + Raises: + NotImplementedError: [description] + """ raise NotImplementedError() @abstractmethod def build(self) -> None: + """ + Called when the C++ target needs to be produced. + + Raises: + NotImplementedError: [description] + """ raise NotImplementedError() @@ -63,7 +89,7 @@ def __init__(self) -> None: @staticmethod @abstractmethod - def name(self) -> str: + def name() -> str: """ The name of the generator """ @@ -76,7 +102,7 @@ class Interface(Plugin): """ def __init__(self) -> None: - pass + super().__init__() @staticmethod def external_config() -> bool: @@ -91,7 +117,8 @@ def external_config() -> bool: @abstractmethod def parse_pep_621(data: dict) -> PEP621: """ - Requests the plugin to read the available PEP 621 information. Only requested if the plugin is not the entrypoint + Requests the plugin to read the available PEP 621 information. Only requested + if the plugin is not the entrypoint """ raise NotImplementedError() @@ -129,7 +156,7 @@ def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: dic @staticmethod @abstractmethod - def data_type(self): + def data_type(): """ Returns the pydantic type to cast the generator configuration data to """ diff --git a/pdm.lock b/pdm.lock index fa2ade7..f6a3ca8 100644 --- a/pdm.lock +++ b/pdm.lock @@ -225,8 +225,8 @@ dependencies = [ [[package]] name = "setuptools" -version = "59.6.0" -requires_python = ">=3.6" +version = "59.7.0" +requires_python = ">=3.7" summary = "Easily download, build, install, upgrade, and uninstall Python packages" [[package]] @@ -261,7 +261,7 @@ summary = "Module for decorators, wrappers and monkey patching." [metadata] lock_version = "3.1" -content_hash = "sha256:9c52d28eff0b966cb0ddf5369b3af743ec10571db88414c654993a1dba023c1e" +content_hash = "sha256:69f8ff5f1b08e27c2f183103206892654e1d6707780ed49f22572650e001b4f0" [metadata.files] "astroid 2.9.0" = [ @@ -486,9 +486,9 @@ content_hash = "sha256:9c52d28eff0b966cb0ddf5369b3af743ec10571db88414c654993a1db {file = "pytest_xdist-2.5.0-py3-none-any.whl", hash = "sha256:6fe5c74fec98906deb8f2d2b616b5c782022744978e7bd4695d39c8f42d0ce65"}, {file = "pytest-xdist-2.5.0.tar.gz", hash = "sha256:4580deca3ff04ddb2ac53eba39d76cb5dd5edeac050cb6fbc768b0dd712b4edf"}, ] -"setuptools 59.6.0" = [ - {file = "setuptools-59.6.0-py3-none-any.whl", hash = "sha256:4ce92f1e1f8f01233ee9952c04f6b81d1e02939d6e1b488428154974a4d0783e"}, - {file = "setuptools-59.6.0.tar.gz", hash = "sha256:22c7348c6d2976a52632c67f7ab0cdf40147db7789f9aed18734643fe9cf3373"}, +"setuptools 59.7.0" = [ + {file = "setuptools-59.7.0-py3-none-any.whl", hash = "sha256:0c8d5c36aea600828875ab751c03e2c52624edc8382a88a127e31bd8d860e34b"}, + {file = "setuptools-59.7.0.tar.gz", hash = "sha256:a426c5ce42242404fecb1cbce07af79c10b820ab2f684109e8129040413faaa1"}, ] "toml 0.10.2" = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, diff --git a/pyproject.toml b/pyproject.toml index 7b28885..06a18d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ dependencies = [ "cmake~=3.22", "pydantic~=1.8", "tomlkit~=0.7", + "pytest~=6.2", # Required for testing injection ] [tool.pdm] @@ -31,9 +32,9 @@ version = {use_scm = true} lint = [ "black<22,>=21.11b1", "pylint~=2.12", + "isort", ] test = [ - "pytest~=6.2", "pytest-cov~=3.0", "pytest-mock~=3.6", "pytest-xdist~=2.5", @@ -53,17 +54,19 @@ testpaths = [ ] [tool.black] +experimental-string-processing = true line-length = 120 +[tool.isort] +profile = "black" + [tool.pylint.messages_control] disable = "C0330, C0326" +extension-pkg-whitelist = "pydantic" [tool.pylint.format] max-line-length = "120" -[tool.pylint.'MESSAGES CONTROL'] -extension-pkg-whitelist = "pydantic" - [build-system] build-backend = "pdm.pep517.api" requires = ["pdm-pep517"] diff --git a/tests/conftest.py b/tests/conftest.py index ed5638c..fc325df 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,8 @@ -import pytest - -from pathlib import Path +from pathlib import Path from shutil import copytree +import pytest + @pytest.fixture def tmp_workspace(tmp_path): diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py index 34c7aa3..9ea95f0 100644 --- a/tests/integration/test_cli.py +++ b/tests/integration/test_cli.py @@ -1,3 +1,8 @@ +""" +TODO: +""" + + class TestCLI: def test_something(self): pass diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py index 3d3a61c..f7460fc 100644 --- a/tests/integration/test_project.py +++ b/tests/integration/test_project.py @@ -1,3 +1,8 @@ +""" +TODO: +""" + + class TestProjects: def test_correct_project(self, tmp_workspace): pass diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index 98e37d9..0c50654 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -1,7 +1,7 @@ import pytest -from cppython.plugins.test.pytest import BaseGenerator from cppython.plugins.generator.cmake import CMakeGenerator +from cppython.plugins.test.pytest import BaseGenerator @pytest.mark.parametrize("generator", [CMakeGenerator]) diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index f517cde..8d6be11 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -1,9 +1,9 @@ import pytest +from click.testing import CliRunner +from cppython.plugins.interface.console import Config, ConsoleInterface, cli from cppython.plugins.test.pytest import BaseInterface -from cppython.plugins.interface.console import ConsoleInterface, Config, cli from cppython.project import Project -from click.testing import CliRunner @pytest.mark.parametrize("interface", [ConsoleInterface]) diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py deleted file mode 100644 index 5f28270..0000000 --- a/tests/unit/test_plugin.py +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index 5f13681..0e20419 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -1,3 +1,6 @@ +""" +TODO: +""" from cppython.project import Project From c2c80a8ab58246a05b2822a4c10658046a9be3b7 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 19 Dec 2021 10:06:00 -0500 Subject: [PATCH 02/55] More Comments --- cppython/schema.py | 7 +++++++ tests/conftest.py | 6 +++++- tests/unit/test_generator.py | 4 ++++ tests/unit/test_interface.py | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cppython/schema.py b/cppython/schema.py index 9c37909..53e7ccf 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -154,6 +154,13 @@ class Generator(Plugin, API): def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: dict) -> None: pass + @abstractmethod + def install_generator(self): + """ + Installs the external tooling required by the generator if the generator is not a python library + """ + pass + @staticmethod @abstractmethod def data_type(): diff --git a/tests/conftest.py b/tests/conftest.py index fc325df..d24e181 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,8 @@ -from pathlib import Path +""" +TODO: +""" + +from pathlib import Path from shutil import copytree import pytest diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index 0c50654..ec6f293 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -1,3 +1,7 @@ +""" +TODO: +""" + import pytest from cppython.plugins.generator.cmake import CMakeGenerator diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 8d6be11..96b209e 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -1,3 +1,7 @@ +""" +TODO: +""" + import pytest from click.testing import CliRunner From b889379569e0567ecef54d0360bf22b6304d2f83 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 21 Dec 2021 23:27:50 -0500 Subject: [PATCH 03/55] Update Pytest Library Fixtures --- cppython/plugins/test/pytest.py | 22 +++++++++++++++------- cppython/schema.py | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index 563a3f0..623d257 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -1,6 +1,8 @@ """ TODO: """ +from abc import ABC + import pytest @@ -8,29 +10,35 @@ def generator(): """ A hook allowing implementations to override the fixture with a parameterization + @pytest.mark.parametrize("generator", [CustomGenerator]) """ raise NotImplementedError -class BaseGenerator: +class BaseGenerator(ABC): """ - Implementations of the Generator class should inherit from this class for its tests + Custom implementations of the Generator class should inherit from this class for its tests. + This class provides a generic test suite that all custom types must function with. """ - pass + def test_construction(self): + """ + Test the __init__ call of the generator object + """ + pass @pytest.fixture def interface(): """ A hook allowing implementations to override the fixture with a parameterization + @pytest.mark.parametrize("interface", [CustomInterface]) """ raise NotImplementedError -class BaseInterface: +class BaseInterface(ABC): """ - Implementations of the Interface class should inherit from this class for its tests + Custom implementations of the Interface class should inherit from this class for its tests. + This class provides a generic test suite that all custom types must function with. """ - - pass diff --git a/cppython/schema.py b/cppython/schema.py index 53e7ccf..8ee5717 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -157,7 +157,7 @@ def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: dic @abstractmethod def install_generator(self): """ - Installs the external tooling required by the generator if the generator is not a python library + Installs the external tooling required by the generator if necessary """ pass From a8be9bbf2517edac9541e9541033eaaeaf95cadd Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 11 Jan 2022 15:49:33 -0500 Subject: [PATCH 04/55] Update pdm.lock --- pdm.lock | 109 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 48 deletions(-) diff --git a/pdm.lock b/pdm.lock index f6a3ca8..276e38b 100644 --- a/pdm.lock +++ b/pdm.lock @@ -1,7 +1,7 @@ [[package]] name = "astroid" -version = "2.9.0" -requires_python = "~=3.6" +version = "2.9.3" +requires_python = ">=3.6.2" summary = "An abstract syntax tree for Python with inference support." dependencies = [ "lazy-object-proxy>=1.4.0", @@ -17,7 +17,7 @@ summary = "Atomic file writes." [[package]] name = "attrs" -version = "21.2.0" +version = "21.4.0" requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" summary = "Classes Without Boilerplate" @@ -122,8 +122,8 @@ summary = "Utility library for gitignore style pattern matching of file paths." [[package]] name = "platformdirs" -version = "2.4.0" -requires_python = ">=3.6" +version = "2.4.1" +requires_python = ">=3.7" summary = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." [[package]] @@ -140,7 +140,7 @@ summary = "library with cross-python path, ini-parsing, io, code, log facilities [[package]] name = "pydantic" -version = "1.8.2" +version = "1.9.0" requires_python = ">=3.6.1" summary = "Data validation and settings management using python 3.6 type hinting" dependencies = [ @@ -225,7 +225,7 @@ dependencies = [ [[package]] name = "setuptools" -version = "59.7.0" +version = "60.5.0" requires_python = ">=3.7" summary = "Easily download, build, install, upgrade, and uninstall Python packages" @@ -243,8 +243,8 @@ summary = "A lil' TOML parser" [[package]] name = "tomlkit" -version = "0.7.2" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "0.8.0" +requires_python = ">=3.6,<4.0" summary = "Style preserving TOML library" [[package]] @@ -261,20 +261,20 @@ summary = "Module for decorators, wrappers and monkey patching." [metadata] lock_version = "3.1" -content_hash = "sha256:69f8ff5f1b08e27c2f183103206892654e1d6707780ed49f22572650e001b4f0" +content_hash = "sha256:87bdb0e031e382b1ba32a8ef77760c6c7794c3cc6b1615759a2a46bd147f6ae3" [metadata.files] -"astroid 2.9.0" = [ - {file = "astroid-2.9.0-py3-none-any.whl", hash = "sha256:776ca0b748b4ad69c00bfe0fff38fa2d21c338e12c84aa9715ee0d473c422778"}, - {file = "astroid-2.9.0.tar.gz", hash = "sha256:5939cf55de24b92bda00345d4d0659d01b3c7dafb5055165c330bc7c568ba273"}, +"astroid 2.9.3" = [ + {file = "astroid-2.9.3-py3-none-any.whl", hash = "sha256:506daabe5edffb7e696ad82483ad0228245a9742ed7d2d8c9cdb31537decf9f6"}, + {file = "astroid-2.9.3.tar.gz", hash = "sha256:1efdf4e867d4d8ba4a9f6cf9ce07cd182c4c41de77f23814feb27ca93ca9d877"}, ] "atomicwrites 1.4.0" = [ {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, ] -"attrs 21.2.0" = [ - {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"}, - {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, +"attrs 21.4.0" = [ + {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, + {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, ] "black 21.12b0" = [ {file = "black-21.12b0-py3-none-any.whl", hash = "sha256:a615e69ae185e08fdd73e4715e260e2479c861b5740057fde6e8b4e3b7dd589f"}, @@ -422,9 +422,9 @@ content_hash = "sha256:69f8ff5f1b08e27c2f183103206892654e1d6707780ed49f22572650e {file = "pathspec-0.9.0-py2.py3-none-any.whl", hash = "sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a"}, {file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"}, ] -"platformdirs 2.4.0" = [ - {file = "platformdirs-2.4.0-py3-none-any.whl", hash = "sha256:8868bbe3c3c80d42f20156f22e7131d2fb321f5bc86a2a345375c6481a67021d"}, - {file = "platformdirs-2.4.0.tar.gz", hash = "sha256:367a5e80b3d04d2428ffa76d33f124cf11e8fff2acdaa9b43d545f5c7d661ef2"}, +"platformdirs 2.4.1" = [ + {file = "platformdirs-2.4.1-py3-none-any.whl", hash = "sha256:1d7385c7db91728b83efd0ca99a5afb296cab9d0ed8313a45ed8ba17967ecfca"}, + {file = "platformdirs-2.4.1.tar.gz", hash = "sha256:440633ddfebcc36264232365d7840a970e75e1018d15b4327d11f91909045fda"}, ] "pluggy 1.0.0" = [ {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, @@ -434,29 +434,42 @@ content_hash = "sha256:69f8ff5f1b08e27c2f183103206892654e1d6707780ed49f22572650e {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, ] -"pydantic 1.8.2" = [ - {file = "pydantic-1.8.2-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:05ddfd37c1720c392f4e0d43c484217b7521558302e7069ce8d318438d297739"}, - {file = "pydantic-1.8.2-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:a7c6002203fe2c5a1b5cbb141bb85060cbff88c2d78eccbc72d97eb7022c43e4"}, - {file = "pydantic-1.8.2-cp36-cp36m-manylinux2014_i686.whl", hash = "sha256:589eb6cd6361e8ac341db97602eb7f354551482368a37f4fd086c0733548308e"}, - {file = "pydantic-1.8.2-cp36-cp36m-manylinux2014_x86_64.whl", hash = "sha256:10e5622224245941efc193ad1d159887872776df7a8fd592ed746aa25d071840"}, - {file = "pydantic-1.8.2-cp36-cp36m-win_amd64.whl", hash = "sha256:99a9fc39470010c45c161a1dc584997f1feb13f689ecf645f59bb4ba623e586b"}, - {file = "pydantic-1.8.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:a83db7205f60c6a86f2c44a61791d993dff4b73135df1973ecd9eed5ea0bda20"}, - {file = "pydantic-1.8.2-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:41b542c0b3c42dc17da70554bc6f38cbc30d7066d2c2815a94499b5684582ecb"}, - {file = "pydantic-1.8.2-cp37-cp37m-manylinux2014_i686.whl", hash = "sha256:ea5cb40a3b23b3265f6325727ddfc45141b08ed665458be8c6285e7b85bd73a1"}, - {file = "pydantic-1.8.2-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:18b5ea242dd3e62dbf89b2b0ec9ba6c7b5abaf6af85b95a97b00279f65845a23"}, - {file = "pydantic-1.8.2-cp37-cp37m-win_amd64.whl", hash = "sha256:234a6c19f1c14e25e362cb05c68afb7f183eb931dd3cd4605eafff055ebbf287"}, - {file = "pydantic-1.8.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:021ea0e4133e8c824775a0cfe098677acf6fa5a3cbf9206a376eed3fc09302cd"}, - {file = "pydantic-1.8.2-cp38-cp38-manylinux1_i686.whl", hash = "sha256:e710876437bc07bd414ff453ac8ec63d219e7690128d925c6e82889d674bb505"}, - {file = "pydantic-1.8.2-cp38-cp38-manylinux2014_i686.whl", hash = "sha256:ac8eed4ca3bd3aadc58a13c2aa93cd8a884bcf21cb019f8cfecaae3b6ce3746e"}, - {file = "pydantic-1.8.2-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:4a03cbbe743e9c7247ceae6f0d8898f7a64bb65800a45cbdc52d65e370570820"}, - {file = "pydantic-1.8.2-cp38-cp38-win_amd64.whl", hash = "sha256:8621559dcf5afacf0069ed194278f35c255dc1a1385c28b32dd6c110fd6531b3"}, - {file = "pydantic-1.8.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:8b223557f9510cf0bfd8b01316bf6dd281cf41826607eada99662f5e4963f316"}, - {file = "pydantic-1.8.2-cp39-cp39-manylinux1_i686.whl", hash = "sha256:244ad78eeb388a43b0c927e74d3af78008e944074b7d0f4f696ddd5b2af43c62"}, - {file = "pydantic-1.8.2-cp39-cp39-manylinux2014_i686.whl", hash = "sha256:05ef5246a7ffd2ce12a619cbb29f3307b7c4509307b1b49f456657b43529dc6f"}, - {file = "pydantic-1.8.2-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:54cd5121383f4a461ff7644c7ca20c0419d58052db70d8791eacbbe31528916b"}, - {file = "pydantic-1.8.2-cp39-cp39-win_amd64.whl", hash = "sha256:4be75bebf676a5f0f87937c6ddb061fa39cbea067240d98e298508c1bda6f3f3"}, - {file = "pydantic-1.8.2-py3-none-any.whl", hash = "sha256:fec866a0b59f372b7e776f2d7308511784dace622e0992a0b59ea3ccee0ae833"}, - {file = "pydantic-1.8.2.tar.gz", hash = "sha256:26464e57ccaafe72b7ad156fdaa4e9b9ef051f69e175dbbb463283000c05ab7b"}, +"pydantic 1.9.0" = [ + {file = "pydantic-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:cb23bcc093697cdea2708baae4f9ba0e972960a835af22560f6ae4e7e47d33f5"}, + {file = "pydantic-1.9.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1d5278bd9f0eee04a44c712982343103bba63507480bfd2fc2790fa70cd64cf4"}, + {file = "pydantic-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ab624700dc145aa809e6f3ec93fb8e7d0f99d9023b713f6a953637429b437d37"}, + {file = "pydantic-1.9.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c8d7da6f1c1049eefb718d43d99ad73100c958a5367d30b9321b092771e96c25"}, + {file = "pydantic-1.9.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:3c3b035103bd4e2e4a28da9da7ef2fa47b00ee4a9cf4f1a735214c1bcd05e0f6"}, + {file = "pydantic-1.9.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:3011b975c973819883842c5ab925a4e4298dffccf7782c55ec3580ed17dc464c"}, + {file = "pydantic-1.9.0-cp310-cp310-win_amd64.whl", hash = "sha256:086254884d10d3ba16da0588604ffdc5aab3f7f09557b998373e885c690dd398"}, + {file = "pydantic-1.9.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:0fe476769acaa7fcddd17cadd172b156b53546ec3614a4d880e5d29ea5fbce65"}, + {file = "pydantic-1.9.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c8e9dcf1ac499679aceedac7e7ca6d8641f0193c591a2d090282aaf8e9445a46"}, + {file = "pydantic-1.9.0-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d1e4c28f30e767fd07f2ddc6f74f41f034d1dd6bc526cd59e63a82fe8bb9ef4c"}, + {file = "pydantic-1.9.0-cp36-cp36m-musllinux_1_1_i686.whl", hash = "sha256:c86229333cabaaa8c51cf971496f10318c4734cf7b641f08af0a6fbf17ca3054"}, + {file = "pydantic-1.9.0-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:c0727bda6e38144d464daec31dff936a82917f431d9c39c39c60a26567eae3ed"}, + {file = "pydantic-1.9.0-cp36-cp36m-win_amd64.whl", hash = "sha256:dee5ef83a76ac31ab0c78c10bd7d5437bfdb6358c95b91f1ba7ff7b76f9996a1"}, + {file = "pydantic-1.9.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:d9c9bdb3af48e242838f9f6e6127de9be7063aad17b32215ccc36a09c5cf1070"}, + {file = "pydantic-1.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2ee7e3209db1e468341ef41fe263eb655f67f5c5a76c924044314e139a1103a2"}, + {file = "pydantic-1.9.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0b6037175234850ffd094ca77bf60fb54b08b5b22bc85865331dd3bda7a02fa1"}, + {file = "pydantic-1.9.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:b2571db88c636d862b35090ccf92bf24004393f85c8870a37f42d9f23d13e032"}, + {file = "pydantic-1.9.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:8b5ac0f1c83d31b324e57a273da59197c83d1bb18171e512908fe5dc7278a1d6"}, + {file = "pydantic-1.9.0-cp37-cp37m-win_amd64.whl", hash = "sha256:bbbc94d0c94dd80b3340fc4f04fd4d701f4b038ebad72c39693c794fd3bc2d9d"}, + {file = "pydantic-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e0896200b6a40197405af18828da49f067c2fa1f821491bc8f5bde241ef3f7d7"}, + {file = "pydantic-1.9.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7bdfdadb5994b44bd5579cfa7c9b0e1b0e540c952d56f627eb227851cda9db77"}, + {file = "pydantic-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:574936363cd4b9eed8acdd6b80d0143162f2eb654d96cb3a8ee91d3e64bf4cf9"}, + {file = "pydantic-1.9.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c556695b699f648c58373b542534308922c46a1cda06ea47bc9ca45ef5b39ae6"}, + {file = "pydantic-1.9.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:f947352c3434e8b937e3aa8f96f47bdfe6d92779e44bb3f41e4c213ba6a32145"}, + {file = "pydantic-1.9.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:5e48ef4a8b8c066c4a31409d91d7ca372a774d0212da2787c0d32f8045b1e034"}, + {file = "pydantic-1.9.0-cp38-cp38-win_amd64.whl", hash = "sha256:96f240bce182ca7fe045c76bcebfa0b0534a1bf402ed05914a6f1dadff91877f"}, + {file = "pydantic-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:815ddebb2792efd4bba5488bc8fde09c29e8ca3227d27cf1c6990fc830fd292b"}, + {file = "pydantic-1.9.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:6c5b77947b9e85a54848343928b597b4f74fc364b70926b3c4441ff52620640c"}, + {file = "pydantic-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4c68c3bc88dbda2a6805e9a142ce84782d3930f8fdd9655430d8576315ad97ce"}, + {file = "pydantic-1.9.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5a79330f8571faf71bf93667d3ee054609816f10a259a109a0738dac983b23c3"}, + {file = "pydantic-1.9.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:f5a64b64ddf4c99fe201ac2724daada8595ada0d102ab96d019c1555c2d6441d"}, + {file = "pydantic-1.9.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a733965f1a2b4090a5238d40d983dcd78f3ecea221c7af1497b845a9709c1721"}, + {file = "pydantic-1.9.0-cp39-cp39-win_amd64.whl", hash = "sha256:2cc6a4cb8a118ffec2ca5fcb47afbacb4f16d0ab8b7350ddea5e8ef7bcc53a16"}, + {file = "pydantic-1.9.0-py3-none-any.whl", hash = "sha256:085ca1de245782e9b46cefcf99deecc67d418737a1fd3f6a4f511344b613a5b3"}, + {file = "pydantic-1.9.0.tar.gz", hash = "sha256:742645059757a56ecd886faf4ed2441b9c0cd406079c2b4bee51bcc3fbcd510a"}, ] "pylint 2.12.2" = [ {file = "pylint-2.12.2-py3-none-any.whl", hash = "sha256:daabda3f7ed9d1c60f52d563b1b854632fd90035bcf01443e234d3dc794e3b74"}, @@ -486,9 +499,9 @@ content_hash = "sha256:69f8ff5f1b08e27c2f183103206892654e1d6707780ed49f22572650e {file = "pytest_xdist-2.5.0-py3-none-any.whl", hash = "sha256:6fe5c74fec98906deb8f2d2b616b5c782022744978e7bd4695d39c8f42d0ce65"}, {file = "pytest-xdist-2.5.0.tar.gz", hash = "sha256:4580deca3ff04ddb2ac53eba39d76cb5dd5edeac050cb6fbc768b0dd712b4edf"}, ] -"setuptools 59.7.0" = [ - {file = "setuptools-59.7.0-py3-none-any.whl", hash = "sha256:0c8d5c36aea600828875ab751c03e2c52624edc8382a88a127e31bd8d860e34b"}, - {file = "setuptools-59.7.0.tar.gz", hash = "sha256:a426c5ce42242404fecb1cbce07af79c10b820ab2f684109e8129040413faaa1"}, +"setuptools 60.5.0" = [ + {file = "setuptools-60.5.0-py3-none-any.whl", hash = "sha256:68eb94073fc486091447fcb0501efd6560a0e5a1839ba249e5ff3c4c93f05f90"}, + {file = "setuptools-60.5.0.tar.gz", hash = "sha256:2404879cda71495fc4d5cbc445ed52fdaddf352b36e40be8dcc63147cb4edabe"}, ] "toml 0.10.2" = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, @@ -498,9 +511,9 @@ content_hash = "sha256:69f8ff5f1b08e27c2f183103206892654e1d6707780ed49f22572650e {file = "tomli-1.2.3-py3-none-any.whl", hash = "sha256:e3069e4be3ead9668e21cb9b074cd948f7b3113fd9c8bba083f48247aab8b11c"}, {file = "tomli-1.2.3.tar.gz", hash = "sha256:05b6166bff487dc068d322585c7ea4ef78deed501cc124060e0f238e89a9231f"}, ] -"tomlkit 0.7.2" = [ - {file = "tomlkit-0.7.2-py2.py3-none-any.whl", hash = "sha256:173ad840fa5d2aac140528ca1933c29791b79a374a0861a80347f42ec9328117"}, - {file = "tomlkit-0.7.2.tar.gz", hash = "sha256:d7a454f319a7e9bd2e249f239168729327e4dd2d27b17dc68be264ad1ce36754"}, +"tomlkit 0.8.0" = [ + {file = "tomlkit-0.8.0-py3-none-any.whl", hash = "sha256:b824e3466f1d475b2b5f1c392954c6cb7ea04d64354ff7300dc7c14257dc85db"}, + {file = "tomlkit-0.8.0.tar.gz", hash = "sha256:29e84a855712dfe0e88a48f6d05c21118dbafb283bb2eed614d46f80deb8e9a1"}, ] "typing-extensions 4.0.1" = [ {file = "typing_extensions-4.0.1-py3-none-any.whl", hash = "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"}, From 8ceffd1140affbfe2c98a87176cce3d765e9324b Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 11 Jan 2022 16:54:11 -0500 Subject: [PATCH 05/55] Fix Test Discovery --- cppython/plugins/test/pytest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index 623d257..69b6b20 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -21,7 +21,7 @@ class BaseGenerator(ABC): This class provides a generic test suite that all custom types must function with. """ - def test_construction(self): + def test_construction(self, generator): """ Test the __init__ call of the generator object """ From 6fade4eb613834a03e9b172d939d164332bee4c5 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 13 Jan 2022 18:55:51 -0500 Subject: [PATCH 06/55] Changes --- cppython/plugins/generator/cmake.py | 31 ++++++++++++++++++++++------- cppython/plugins/test/pytest.py | 29 +++++++++++++++++++++------ cppython/schema.py | 7 ++++--- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index e9fdaf5..1fe8721 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -1,12 +1,27 @@ +""" +TODO: +""" +from pathlib import Path + +from pydantic import BaseModel + from cppython.schema import PEP621, Generator, Metadata +class CMakeData(BaseModel): + """ + TODO: + """ + + installation_location: Path + + class CMakeGenerator(Generator): """ A CPPython generator implementing a CMake backend """ - def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: dict) -> None: + def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: CMakeData) -> None: super().__init__(pep_612, cppython_data, generator_data) # Plugin Contract @@ -20,17 +35,19 @@ def name() -> str: # Generator Contract - def populate_metadata(self, data: dict): + def install_generator(self) -> bool: """ - data - The CPPoetry data taken from pyproject.toml + Installs the external tooling required by the generator if necessary + Returns whether anything was installed or not """ - pass + return False - def populate_plugin(self, data: dict): + @staticmethod + def data_type() -> BaseModel: """ - data - The data taken from pyproject.toml that belongs to this generator + Returns the pydantic type to cast the generator configuration data to """ - pass + return CMakeData # API Contract diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index 69b6b20..007d122 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -7,36 +7,53 @@ @pytest.fixture -def generator(): +def generator_type(): """ A hook allowing implementations to override the fixture with a parameterization - @pytest.mark.parametrize("generator", [CustomGenerator]) + @pytest.mark.parametrize("generator_type", [CustomGenerator]) """ raise NotImplementedError +@pytest.fixture +def generator(generator_type): + """ + TODO: + """ + return generator_type() + + class BaseGenerator(ABC): """ Custom implementations of the Generator class should inherit from this class for its tests. This class provides a generic test suite that all custom types must function with. """ - def test_construction(self, generator): + def test_construction(self, generator_type): """ Test the __init__ call of the generator object """ - pass + generator_type() @pytest.fixture -def interface(): +def interface_type(): """ A hook allowing implementations to override the fixture with a parameterization - @pytest.mark.parametrize("interface", [CustomInterface]) + @pytest.mark.parametrize("interface_type", [CustomInterface]) """ raise NotImplementedError +@pytest.fixture +def interface(interface_type): + """ + A hook allowing implementations to override the fixture with a parameterization + @pytest.mark.parametrize("interface", [CustomInterface]) + """ + return interface_type() + + class BaseInterface(ABC): """ Custom implementations of the Interface class should inherit from this class for its tests. diff --git a/cppython/schema.py b/cppython/schema.py index 8ee5717..6053fe6 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -152,18 +152,19 @@ class Generator(Plugin, API): @abstractmethod def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: dict) -> None: - pass + super().__init__() @abstractmethod - def install_generator(self): + def install_generator(self) -> bool: """ Installs the external tooling required by the generator if necessary + Returns whether anything was installed or not """ pass @staticmethod @abstractmethod - def data_type(): + def data_type() -> BaseModel: """ Returns the pydantic type to cast the generator configuration data to """ From d0a48bef45b156919295d5836c1d004e19504516 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 13 Jan 2022 22:17:47 -0500 Subject: [PATCH 07/55] Broken Test --- cppython/plugins/test/pytest.py | 36 ++++++++++----------------------- tests/unit/test_generator.py | 4 ++-- tests/unit/test_interface.py | 5 ++--- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index 007d122..5b6c841 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -2,59 +2,45 @@ TODO: """ from abc import ABC +from typing import Type import pytest +from cppython.schema import Generator, Interface + @pytest.fixture -def generator_type(): +def generator() -> Type[Generator]: """ A hook allowing implementations to override the fixture with a parameterization - @pytest.mark.parametrize("generator_type", [CustomGenerator]) + @pytest.mark.parametrize("generator", [CustomGenerator]) """ raise NotImplementedError -@pytest.fixture -def generator(generator_type): - """ - TODO: - """ - return generator_type() - - -class BaseGenerator(ABC): +class BaseGeneratorSuite(ABC): """ Custom implementations of the Generator class should inherit from this class for its tests. This class provides a generic test suite that all custom types must function with. """ - def test_construction(self, generator_type): + def test_construction(self, generator): """ Test the __init__ call of the generator object """ - generator_type() - - -@pytest.fixture -def interface_type(): - """ - A hook allowing implementations to override the fixture with a parameterization - @pytest.mark.parametrize("interface_type", [CustomInterface]) - """ - raise NotImplementedError + generator() @pytest.fixture -def interface(interface_type): +def interface() -> Interface: """ A hook allowing implementations to override the fixture with a parameterization @pytest.mark.parametrize("interface", [CustomInterface]) """ - return interface_type() + raise NotImplementedError -class BaseInterface(ABC): +class BaseInterfaceSuite(ABC): """ Custom implementations of the Interface class should inherit from this class for its tests. This class provides a generic test suite that all custom types must function with. diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index ec6f293..45dd03a 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -5,11 +5,11 @@ import pytest from cppython.plugins.generator.cmake import CMakeGenerator -from cppython.plugins.test.pytest import BaseGenerator +from cppython.plugins.test.pytest import BaseGeneratorSuite @pytest.mark.parametrize("generator", [CMakeGenerator]) -class TestCMakeGenerator(BaseGenerator): +class TestCMakeGenerator(BaseGeneratorSuite): """ The tests for our CMake generator """ diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 96b209e..971495b 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -6,12 +6,11 @@ from click.testing import CliRunner from cppython.plugins.interface.console import Config, ConsoleInterface, cli -from cppython.plugins.test.pytest import BaseInterface -from cppython.project import Project +from cppython.plugins.test.pytest import BaseInterfaceSuite @pytest.mark.parametrize("interface", [ConsoleInterface]) -class TestCLIInterface(BaseInterface): +class TestCLIInterface(BaseInterfaceSuite): """ The tests for our CLI interface """ From 69c08503605ba6863e98d175974bf3e7d5064a8f Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Fri, 14 Jan 2022 14:23:28 -0500 Subject: [PATCH 08/55] Ya --- cppython/plugins/test/pytest.py | 33 +++++++++++++++++++++------------ tests/unit/test_generator.py | 4 +++- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index 5b6c841..bd1511e 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -1,7 +1,7 @@ """ TODO: """ -from abc import ABC +from abc import ABC, abstractmethod from typing import Type import pytest @@ -9,26 +9,29 @@ from cppython.schema import Generator, Interface -@pytest.fixture -def generator() -> Type[Generator]: - """ - A hook allowing implementations to override the fixture with a parameterization - @pytest.mark.parametrize("generator", [CustomGenerator]) - """ - raise NotImplementedError - - class BaseGeneratorSuite(ABC): """ Custom implementations of the Generator class should inherit from this class for its tests. This class provides a generic test suite that all custom types must function with. """ - def test_construction(self, generator): + @abstractmethod + def __init__(self, generator_type: Type[Generator]) -> None: + super().__init__() + + @pytest.fixture + def generator(self) -> Type[Generator]: + """ + A hook allowing implementations to override the fixture with a parameterization + @pytest.mark.parametrize("generator", [CustomGenerator]) + """ + raise NotImplementedError + + def test_construction(self): """ Test the __init__ call of the generator object """ - generator() + self.generator() @pytest.fixture @@ -45,3 +48,9 @@ class BaseInterfaceSuite(ABC): Custom implementations of the Interface class should inherit from this class for its tests. This class provides a generic test suite that all custom types must function with. """ + + def test_construction(self, interface): + """ + Test the __init__ call of the interface object + """ + interface() diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index 45dd03a..e35a973 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -8,12 +8,14 @@ from cppython.plugins.test.pytest import BaseGeneratorSuite -@pytest.mark.parametrize("generator", [CMakeGenerator]) class TestCMakeGenerator(BaseGeneratorSuite): """ The tests for our CMake generator """ + def __init__(self) -> None: + super().__init__(CMakeGenerator) + def test_name(self, generator): """ Tests that the generators name is expected From a3bdf79b70b11a1991da32f723416520fef8d9e9 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 19 Jan 2022 18:06:59 -0500 Subject: [PATCH 09/55] Update Versioning --- pdm.lock | 2 +- pyproject.toml | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pdm.lock b/pdm.lock index 276e38b..a1b4dd5 100644 --- a/pdm.lock +++ b/pdm.lock @@ -261,7 +261,7 @@ summary = "Module for decorators, wrappers and monkey patching." [metadata] lock_version = "3.1" -content_hash = "sha256:87bdb0e031e382b1ba32a8ef77760c6c7794c3cc6b1615759a2a46bd147f6ae3" +content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198dd30246c" [metadata.files] "astroid 2.9.3" = [ diff --git a/pyproject.toml b/pyproject.toml index 06a18d4..6fc5eec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,11 +18,11 @@ dynamic = ["version"] requires-python = ">=3.10" dependencies = [ - "click~=8.0", - "cmake~=3.22", - "pydantic~=1.8", - "tomlkit~=0.7", - "pytest~=6.2", # Required for testing injection + "click>=8.0", + "cmake>=3.22", + "pydantic>=1.8", + "tomlkit>=0.7", + "pytest>=6.2", # Required for testing injection ] [tool.pdm] @@ -31,13 +31,13 @@ version = {use_scm = true} [tool.pdm.dev-dependencies] lint = [ "black<22,>=21.11b1", - "pylint~=2.12", + "pylint>=2.12", "isort", ] test = [ - "pytest-cov~=3.0", - "pytest-mock~=3.6", - "pytest-xdist~=2.5", + "pytest-cov>=3.0", + "pytest-mock>=3.6", + "pytest-xdist>=2.5", ] [project.scripts] From 1685aa66a5403a23b4178c8ecb58ba3af7f3e213 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 27 Jan 2022 17:15:28 -0500 Subject: [PATCH 10/55] Update Versions --- cppython/schema.py | 4 ++ pdm.lock | 145 ++++++++++++++++++++++----------------------- 2 files changed, 75 insertions(+), 74 deletions(-) diff --git a/cppython/schema.py b/cppython/schema.py index 6053fe6..431e5bf 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -145,6 +145,10 @@ def write_pyproject(self) -> None: raise NotImplementedError() +class GeneratorData(BaseModel): + pass + + class Generator(Plugin, API): """ Abstract type to be inherited by CPPython Generator plugins diff --git a/pdm.lock b/pdm.lock index a1b4dd5..85d4f74 100644 --- a/pdm.lock +++ b/pdm.lock @@ -47,7 +47,7 @@ dependencies = [ [[package]] name = "cmake" -version = "3.22.1" +version = "3.22.2" summary = "CMake is an open-source, cross-platform family of tools designed to build, test and package software" [[package]] @@ -58,15 +58,15 @@ summary = "Cross-platform colored terminal text." [[package]] name = "coverage" -version = "6.2" -requires_python = ">=3.6" +version = "6.3" +requires_python = ">=3.7" summary = "Code coverage measurement for Python" [[package]] name = "coverage" -version = "6.2" +version = "6.3" extras = ["toml"] -requires_python = ">=3.6" +requires_python = ">=3.7" summary = "Code coverage measurement for Python" dependencies = [ "coverage>=5.2.1", @@ -163,7 +163,7 @@ dependencies = [ [[package]] name = "pyparsing" -version = "3.0.6" +version = "3.0.7" requires_python = ">=3.6" summary = "Python parsing module" @@ -284,76 +284,73 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "click-8.0.3-py3-none-any.whl", hash = "sha256:353f466495adaeb40b6b5f592f9f91cb22372351c84caeb068132442a4518ef3"}, {file = "click-8.0.3.tar.gz", hash = "sha256:410e932b050f5eed773c4cda94de75971c89cdb3155a72a0831139a79e5ecb5b"}, ] -"cmake 3.22.1" = [ - {file = "cmake-3.22.1-py2.py3-none-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl", hash = "sha256:153ab8c7d8bb6a0b6741a247ea89c3f269105e91b52cf44d7c51394193a3a94f"}, - {file = "cmake-3.22.1-py2.py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5135c2039fd5e147857ea3aceefea5de00cfdd9f911f94fc987f35cd5b0b71af"}, - {file = "cmake-3.22.1-py2.py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:609fe01e8b8241f4190f28d3e71f189c2272e7d7739568443b35fe1b0dea6494"}, - {file = "cmake-3.22.1-py2.py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:493e436ac33ddb39238999f5c04c5767a1eec9c15b2e1284222cff067d2a8901"}, - {file = "cmake-3.22.1-py2.py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:33d081e76237c38cf115f7eecdaa277d914e4a57afbeb93229de293fc1418cfd"}, - {file = "cmake-3.22.1-py2.py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:99cd7a3a33f6b78cb211334e120ed8d22f80c614d349e2b93fd958e0e9b89f7e"}, - {file = "cmake-3.22.1-py2.py3-none-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:360eb0ab90e5ba08ab651bf088e7bd56f2c41022e5cde5e9caef274f1466f133"}, - {file = "cmake-3.22.1-py2.py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:55e7d61e48492f9a7561b4849ef0287dd858c76dd70a22b47b5c71b8d8ebdd5c"}, - {file = "cmake-3.22.1-py2.py3-none-musllinux_1_1_aarch64.whl", hash = "sha256:dc9339db41ca0c208c082df3fb8ecb2ef62e38af5a9ccc0fe3ce2d91aa8eb2e8"}, - {file = "cmake-3.22.1-py2.py3-none-musllinux_1_1_i686.whl", hash = "sha256:aef8619108fe43abc92782faf63d26b63fc56a5ab956de9c8b5d72240c800512"}, - {file = "cmake-3.22.1-py2.py3-none-musllinux_1_1_ppc64le.whl", hash = "sha256:f4bd2d162d81419c8310062913b574836e5bb04edf639cc25b5a7d4020a3a572"}, - {file = "cmake-3.22.1-py2.py3-none-musllinux_1_1_s390x.whl", hash = "sha256:d6f78f6e6f728e08a9f330942d8175f8234051328f8e060e2e5155f12f6edf0a"}, - {file = "cmake-3.22.1-py2.py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:e33657f8c2e49e8dc4f1714a94c1fc6a74656001f1ee2187c4f7e9f1ed641860"}, - {file = "cmake-3.22.1-py2.py3-none-win32.whl", hash = "sha256:bf7718fe37c755a1430099149cd23099dc024868c42cab9db2b6c8fe8a11c881"}, - {file = "cmake-3.22.1-py2.py3-none-win_amd64.whl", hash = "sha256:1a8023e21b538520b75c0166236164ae9ae08ac0b3edcc2aeafd436030aaae0d"}, - {file = "cmake-3.22.1.tar.gz", hash = "sha256:75d1573037748d5be4c73a51ef1a338bf21757aaddef5b532abf33f4333cd3ae"}, +"cmake 3.22.2" = [ + {file = "cmake-3.22.2-py2.py3-none-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl", hash = "sha256:7bc1c50c9131105b4892528183475d3fc564f3d611f0fe2f1b1bd184f7de1fd4"}, + {file = "cmake-3.22.2-py2.py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ccb57bf773fdc0d3d299da387f7d46f38b452608fdc3100aa294dbb25d216515"}, + {file = "cmake-3.22.2-py2.py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0801156be44344de6b1427ee8e845850d113868001c4c5bd415caf8d44328b8f"}, + {file = "cmake-3.22.2-py2.py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:43b820c4b880e28c10ff78ea0189deed77d77ddc166bb3fd807fa848a2822a25"}, + {file = "cmake-3.22.2-py2.py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:026edb77648e9d84e2f446534a964513cf5ea82f226996bbe6dc480fb8048cf9"}, + {file = "cmake-3.22.2-py2.py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6aff4053fb344dc3d89a3ebd4ef66dd6ba0c8bf0130a2fd3fb8c65baf7316518"}, + {file = "cmake-3.22.2-py2.py3-none-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:9bc25b9c8be9507f4fc2004931f0d2f680eeae7c00f6d21aa168839a8aee7432"}, + {file = "cmake-3.22.2-py2.py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:e01697d8beefd3cb2224aa70139858b6f515fc74348447fe97ddef8b56bf1cb9"}, + {file = "cmake-3.22.2-py2.py3-none-musllinux_1_1_aarch64.whl", hash = "sha256:457e4990e8459cacbe37df6fb1aaf9648d6d08788d8b5f526c46a19d3cd7b700"}, + {file = "cmake-3.22.2-py2.py3-none-musllinux_1_1_i686.whl", hash = "sha256:29eecf8285be72db820a60fa4adfc7b1f4c2acc0f3181881d191587ac5272e8c"}, + {file = "cmake-3.22.2-py2.py3-none-musllinux_1_1_ppc64le.whl", hash = "sha256:87cce96f5bd40987741718462fa29138d17bb8dbd24cd2a3f0824d2210cac429"}, + {file = "cmake-3.22.2-py2.py3-none-musllinux_1_1_s390x.whl", hash = "sha256:a642208015f3ffbc95dce55c23058ee7c562d3dece0da398f8d3276f45f5ee34"}, + {file = "cmake-3.22.2-py2.py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:7f10f00b863f2c60b585ebb45ae048174d450982c2595f336fcbbd6695a50e19"}, + {file = "cmake-3.22.2-py2.py3-none-win32.whl", hash = "sha256:fd3168e2535ddd0bd9bfff0e4aeb921a61a8351c272654ba71b518da502b9ec2"}, + {file = "cmake-3.22.2-py2.py3-none-win_amd64.whl", hash = "sha256:9f5f563e89a3ee8873a4c48c69d8a32331749da3c3b657d0f0ac74b659e87954"}, + {file = "cmake-3.22.2.tar.gz", hash = "sha256:b5bd5eeb488b13cf64ec963800f3d979eaeb90b4382861b86909df503379e219"}, ] "colorama 0.4.4" = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] -"coverage 6.2" = [ - {file = "coverage-6.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6dbc1536e105adda7a6312c778f15aaabe583b0e9a0b0a324990334fd458c94b"}, - {file = "coverage-6.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:174cf9b4bef0db2e8244f82059a5a72bd47e1d40e71c68ab055425172b16b7d0"}, - {file = "coverage-6.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:92b8c845527eae547a2a6617d336adc56394050c3ed8a6918683646328fbb6da"}, - {file = "coverage-6.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:c7912d1526299cb04c88288e148c6c87c0df600eca76efd99d84396cfe00ef1d"}, - {file = "coverage-6.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d5d2033d5db1d58ae2d62f095e1aefb6988af65b4b12cb8987af409587cc0739"}, - {file = "coverage-6.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:3feac4084291642165c3a0d9eaebedf19ffa505016c4d3db15bfe235718d4971"}, - {file = "coverage-6.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:276651978c94a8c5672ea60a2656e95a3cce2a3f31e9fb2d5ebd4c215d095840"}, - {file = "coverage-6.2-cp310-cp310-win32.whl", hash = "sha256:f506af4f27def639ba45789fa6fde45f9a217da0be05f8910458e4557eed020c"}, - {file = "coverage-6.2-cp310-cp310-win_amd64.whl", hash = "sha256:3f7c17209eef285c86f819ff04a6d4cbee9b33ef05cbcaae4c0b4e8e06b3ec8f"}, - {file = "coverage-6.2-cp311-cp311-macosx_10_14_x86_64.whl", hash = "sha256:13362889b2d46e8d9f97c421539c97c963e34031ab0cb89e8ca83a10cc71ac76"}, - {file = "coverage-6.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:22e60a3ca5acba37d1d4a2ee66e051f5b0e1b9ac950b5b0cf4aa5366eda41d47"}, - {file = "coverage-6.2-cp311-cp311-win_amd64.whl", hash = "sha256:b637c57fdb8be84e91fac60d9325a66a5981f8086c954ea2772efe28425eaf64"}, - {file = "coverage-6.2-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f467bbb837691ab5a8ca359199d3429a11a01e6dfb3d9dcc676dc035ca93c0a9"}, - {file = "coverage-6.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2641f803ee9f95b1f387f3e8f3bf28d83d9b69a39e9911e5bfee832bea75240d"}, - {file = "coverage-6.2-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:1219d760ccfafc03c0822ae2e06e3b1248a8e6d1a70928966bafc6838d3c9e48"}, - {file = "coverage-6.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:9a2b5b52be0a8626fcbffd7e689781bf8c2ac01613e77feda93d96184949a98e"}, - {file = "coverage-6.2-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:8e2c35a4c1f269704e90888e56f794e2d9c0262fb0c1b1c8c4ee44d9b9e77b5d"}, - {file = "coverage-6.2-cp36-cp36m-musllinux_1_1_i686.whl", hash = "sha256:5d6b09c972ce9200264c35a1d53d43ca55ef61836d9ec60f0d44273a31aa9f17"}, - {file = "coverage-6.2-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:e3db840a4dee542e37e09f30859f1612da90e1c5239a6a2498c473183a50e781"}, - {file = "coverage-6.2-cp36-cp36m-win32.whl", hash = "sha256:4e547122ca2d244f7c090fe3f4b5a5861255ff66b7ab6d98f44a0222aaf8671a"}, - {file = "coverage-6.2-cp36-cp36m-win_amd64.whl", hash = "sha256:01774a2c2c729619760320270e42cd9e797427ecfddd32c2a7b639cdc481f3c0"}, - {file = "coverage-6.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:fb8b8ee99b3fffe4fd86f4c81b35a6bf7e4462cba019997af2fe679365db0c49"}, - {file = "coverage-6.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:619346d57c7126ae49ac95b11b0dc8e36c1dd49d148477461bb66c8cf13bb521"}, - {file = "coverage-6.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:0a7726f74ff63f41e95ed3a89fef002916c828bb5fcae83b505b49d81a066884"}, - {file = "coverage-6.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:cfd9386c1d6f13b37e05a91a8583e802f8059bebfccde61a418c5808dea6bbfa"}, - {file = "coverage-6.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:17e6c11038d4ed6e8af1407d9e89a2904d573be29d51515f14262d7f10ef0a64"}, - {file = "coverage-6.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:c254b03032d5a06de049ce8bca8338a5185f07fb76600afff3c161e053d88617"}, - {file = "coverage-6.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:dca38a21e4423f3edb821292e97cec7ad38086f84313462098568baedf4331f8"}, - {file = "coverage-6.2-cp37-cp37m-win32.whl", hash = "sha256:600617008aa82032ddeace2535626d1bc212dfff32b43989539deda63b3f36e4"}, - {file = "coverage-6.2-cp37-cp37m-win_amd64.whl", hash = "sha256:bf154ba7ee2fd613eb541c2bc03d3d9ac667080a737449d1a3fb342740eb1a74"}, - {file = "coverage-6.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:f9afb5b746781fc2abce26193d1c817b7eb0e11459510fba65d2bd77fe161d9e"}, - {file = "coverage-6.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:edcada2e24ed68f019175c2b2af2a8b481d3d084798b8c20d15d34f5c733fa58"}, - {file = "coverage-6.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:a9c8c4283e17690ff1a7427123ffb428ad6a52ed720d550e299e8291e33184dc"}, - {file = "coverage-6.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:f614fc9956d76d8a88a88bb41ddc12709caa755666f580af3a688899721efecd"}, - {file = "coverage-6.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:9365ed5cce5d0cf2c10afc6add145c5037d3148585b8ae0e77cc1efdd6aa2953"}, - {file = "coverage-6.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:8bdfe9ff3a4ea37d17f172ac0dff1e1c383aec17a636b9b35906babc9f0f5475"}, - {file = "coverage-6.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:63c424e6f5b4ab1cf1e23a43b12f542b0ec2e54f99ec9f11b75382152981df57"}, - {file = "coverage-6.2-cp38-cp38-win32.whl", hash = "sha256:49dbff64961bc9bdd2289a2bda6a3a5a331964ba5497f694e2cbd540d656dc1c"}, - {file = "coverage-6.2-cp38-cp38-win_amd64.whl", hash = "sha256:9a29311bd6429be317c1f3fe4bc06c4c5ee45e2fa61b2a19d4d1d6111cb94af2"}, - {file = "coverage-6.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:03b20e52b7d31be571c9c06b74746746d4eb82fc260e594dc662ed48145e9efd"}, - {file = "coverage-6.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:215f8afcc02a24c2d9a10d3790b21054b58d71f4b3c6f055d4bb1b15cecce685"}, - {file = "coverage-6.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:a4bdeb0a52d1d04123b41d90a4390b096f3ef38eee35e11f0b22c2d031222c6c"}, - {file = "coverage-6.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:c332d8f8d448ded473b97fefe4a0983265af21917d8b0cdcb8bb06b2afe632c3"}, - {file = "coverage-6.2-cp39-cp39-win32.whl", hash = "sha256:6e1394d24d5938e561fbeaa0cd3d356207579c28bd1792f25a068743f2d5b282"}, - {file = "coverage-6.2-cp39-cp39-win_amd64.whl", hash = "sha256:86f2e78b1eff847609b1ca8050c9e1fa3bd44ce755b2ec30e70f2d3ba3844644"}, - {file = "coverage-6.2-pp36.pp37.pp38-none-any.whl", hash = "sha256:5829192582c0ec8ca4a2532407bc14c2f338d9878a10442f5d03804a95fac9de"}, - {file = "coverage-6.2.tar.gz", hash = "sha256:e2cad8093172b7d1595b4ad66f24270808658e11acf43a8f95b41276162eb5b8"}, +"coverage 6.3" = [ + {file = "coverage-6.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e8071e7d9ba9f457fc674afc3de054450be2c9b195c470147fbbc082468d8ff7"}, + {file = "coverage-6.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:86c91c511853dfda81c2cf2360502cb72783f4b7cebabef27869f00cbe1db07d"}, + {file = "coverage-6.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3c4ce3b647bd1792d4394f5690d9df6dc035b00bcdbc5595099c01282a59ae01"}, + {file = "coverage-6.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2a491e159294d756e7fc8462f98175e2d2225e4dbe062cca7d3e0d5a75ba6260"}, + {file = "coverage-6.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5d008e0f67ac800b0ca04d7914b8501312c8c6c00ad8c7ba17754609fae1231a"}, + {file = "coverage-6.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:4578728c36de2801c1deb1c6b760d31883e62e33f33c7ba8f982e609dc95167d"}, + {file = "coverage-6.3-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:7ee317486593193e066fc5e98ac0ce712178c21529a85c07b7cb978171f25d53"}, + {file = "coverage-6.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2bc85664b06ba42d14bb74d6ddf19d8bfc520cb660561d2d9ce5786ae72f71b5"}, + {file = "coverage-6.3-cp310-cp310-win32.whl", hash = "sha256:27a94db5dc098c25048b0aca155f5fac674f2cf1b1736c5272ba28ead2fc267e"}, + {file = "coverage-6.3-cp310-cp310-win_amd64.whl", hash = "sha256:bde4aeabc0d1b2e52c4036c54440b1ad05beeca8113f47aceb4998bb7471e2c2"}, + {file = "coverage-6.3-cp311-cp311-macosx_10_14_x86_64.whl", hash = "sha256:509c68c3e2015022aeda03b003dd68fa19987cdcf64e9d4edc98db41cfc45d30"}, + {file = "coverage-6.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:e4ff163602c5c77e7bb4ea81ba5d3b793b4419f8acd296aae149370902cf4e92"}, + {file = "coverage-6.3-cp311-cp311-win_amd64.whl", hash = "sha256:d1675db48490e5fa0b300f6329ecb8a9a37c29b9ab64fa9c964d34111788ca2d"}, + {file = "coverage-6.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:7eed8459a2b81848cafb3280b39d7d49950d5f98e403677941c752e7e7ee47cb"}, + {file = "coverage-6.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1b4285fde5286b946835a1a53bba3ad41ef74285ba9e8013e14b5ea93deaeafc"}, + {file = "coverage-6.3-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a4748349734110fd32d46ff8897b561e6300d8989a494ad5a0a2e4f0ca974fc7"}, + {file = "coverage-6.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:823f9325283dc9565ba0aa2d240471a93ca8999861779b2b6c7aded45b58ee0f"}, + {file = "coverage-6.3-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:fff16a30fdf57b214778eff86391301c4509e327a65b877862f7c929f10a4253"}, + {file = "coverage-6.3-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:da1a428bdbe71f9a8c270c7baab29e9552ac9d0e0cba5e7e9a4c9ee6465d258d"}, + {file = "coverage-6.3-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:7d82c610a2e10372e128023c5baf9ce3d270f3029fe7274ff5bc2897c68f1318"}, + {file = "coverage-6.3-cp37-cp37m-win32.whl", hash = "sha256:11e61c5548ecf74ea1f8b059730b049871f0e32b74f88bd0d670c20c819ad749"}, + {file = "coverage-6.3-cp37-cp37m-win_amd64.whl", hash = "sha256:8e0c3525b1a182c8ffc9bca7e56b521e0c2b8b3e82f033c8e16d6d721f1b54d6"}, + {file = "coverage-6.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:a189036c50dcd56100746139a459f0d27540fef95b09aba03e786540b8feaa5f"}, + {file = "coverage-6.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:32168001f33025fd756884d56d01adebb34e6c8c0b3395ca8584cdcee9c7c9d2"}, + {file = "coverage-6.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a5d79c9af3f410a2b5acad91258b4ae179ee9c83897eb9de69151b179b0227f5"}, + {file = "coverage-6.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:85c5fc9029043cf8b07f73fbb0a7ab6d3b717510c3b5642b77058ea55d7cacde"}, + {file = "coverage-6.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a7596aa2f2b8fa5604129cfc9a27ad9beec0a96f18078cb424d029fdd707468d"}, + {file = "coverage-6.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:ce443a3e6df90d692c38762f108fc4c88314bf477689f04de76b3f252e7a351c"}, + {file = "coverage-6.3-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:012157499ec4f135fc36cd2177e3d1a1840af9b236cbe80e9a5ccfc83d912a69"}, + {file = "coverage-6.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:0a34d313105cdd0d3644c56df2d743fe467270d6ab93b5d4a347eb9fec8924d6"}, + {file = "coverage-6.3-cp38-cp38-win32.whl", hash = "sha256:6e78b1e25e5c5695dea012be473e442f7094d066925604be20b30713dbd47f89"}, + {file = "coverage-6.3-cp38-cp38-win_amd64.whl", hash = "sha256:433b99f7b0613bdcdc0b00cc3d39ed6d756797e3b078d2c43f8a38288520aec6"}, + {file = "coverage-6.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9ed3244b415725f08ca3bdf02ed681089fd95e9465099a21c8e2d9c5d6ca2606"}, + {file = "coverage-6.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ab4fc4b866b279740e0d917402f0e9a08683e002f43fa408e9655818ed392196"}, + {file = "coverage-6.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c8582e9280f8d0f38114fe95a92ae8d0790b56b099d728cc4f8a2e14b1c4a18c"}, + {file = "coverage-6.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c72bb4679283c6737f452eeb9b2a0e570acaef2197ad255fb20162adc80bea76"}, + {file = "coverage-6.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ca29c352389ea27a24c79acd117abdd8a865c6eb01576b6f0990cd9a4e9c9f48"}, + {file = "coverage-6.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:152cc2624381df4e4e604e21bd8e95eb8059535f7b768c1fb8b8ae0b26f47ab0"}, + {file = "coverage-6.3-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:51372e24b1f7143ee2df6b45cff6a721f3abe93b1e506196f3ffa4155c2497f7"}, + {file = "coverage-6.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:72d9d186508325a456475dd05b1756f9a204c7086b07fffb227ef8cee03b1dc2"}, + {file = "coverage-6.3-cp39-cp39-win32.whl", hash = "sha256:649df3641eb351cdfd0d5533c92fc9df507b6b2bf48a7ef8c71ab63cbc7b5c3c"}, + {file = "coverage-6.3-cp39-cp39-win_amd64.whl", hash = "sha256:e67ccd53da5958ea1ec833a160b96357f90859c220a00150de011b787c27b98d"}, + {file = "coverage-6.3-pp36.pp37.pp38-none-any.whl", hash = "sha256:27ac7cb84538e278e07569ceaaa6f807a029dc194b1c819a9820b9bb5dbf63ab"}, + {file = "coverage-6.3.tar.gz", hash = "sha256:987a84ff98a309994ca77ed3cc4b92424f824278e48e4bf7d1bb79a63cfe2099"}, ] "execnet 1.9.0" = [ {file = "execnet-1.9.0-py2.py3-none-any.whl", hash = "sha256:a295f7cc774947aac58dde7fdc85f4aa00c42adf5d8f5468fc630c1acf30a142"}, @@ -475,9 +472,9 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "pylint-2.12.2-py3-none-any.whl", hash = "sha256:daabda3f7ed9d1c60f52d563b1b854632fd90035bcf01443e234d3dc794e3b74"}, {file = "pylint-2.12.2.tar.gz", hash = "sha256:9d945a73640e1fec07ee34b42f5669b770c759acd536ec7b16d7e4b87a9c9ff9"}, ] -"pyparsing 3.0.6" = [ - {file = "pyparsing-3.0.6-py3-none-any.whl", hash = "sha256:04ff808a5b90911829c55c4e26f75fa5ca8a2f5f36aa3a51f68e27033341d3e4"}, - {file = "pyparsing-3.0.6.tar.gz", hash = "sha256:d9bdec0013ef1eb5a84ab39a3b3868911598afa494f5faa038647101504e2b81"}, +"pyparsing 3.0.7" = [ + {file = "pyparsing-3.0.7-py3-none-any.whl", hash = "sha256:a6c06a88f252e6c322f65faf8f418b16213b51bdfaece0524c1c1bc30c63c484"}, + {file = "pyparsing-3.0.7.tar.gz", hash = "sha256:18ee9022775d270c55187733956460083db60b37d0d0fb357445f3094eed3eea"}, ] "pytest 6.2.5" = [ {file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"}, From 24e3bacc1718ae3da59925232d4d2e33c0a50299 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 1 Feb 2022 08:04:59 -0500 Subject: [PATCH 11/55] Typing --- cppython/plugins/generator/cmake.py | 9 ++++----- cppython/plugins/test/pytest.py | 25 ++++++++++++------------- cppython/schema.py | 15 ++++++++++----- pdm.lock | 21 +++++++++------------ tests/unit/test_generator.py | 10 ++++------ 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index 1fe8721..4b7fffe 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -2,13 +2,12 @@ TODO: """ from pathlib import Path +from typing import Type -from pydantic import BaseModel +from cppython.schema import PEP621, Generator, GeneratorData, Metadata -from cppython.schema import PEP621, Generator, Metadata - -class CMakeData(BaseModel): +class CMakeData(GeneratorData): """ TODO: """ @@ -43,7 +42,7 @@ def install_generator(self) -> bool: return False @staticmethod - def data_type() -> BaseModel: + def data_type() -> Type[GeneratorData]: """ Returns the pydantic type to cast the generator configuration data to """ diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index bd1511e..ea4712d 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -6,7 +6,7 @@ import pytest -from cppython.schema import Generator, Interface +from cppython.schema import Generator, GeneratorData, Interface class BaseGeneratorSuite(ABC): @@ -16,7 +16,7 @@ class BaseGeneratorSuite(ABC): """ @abstractmethod - def __init__(self, generator_type: Type[Generator]) -> None: + def __init__(self, generator_type: Type[Generator], generator_data_type: Type[GeneratorData]) -> None: super().__init__() @pytest.fixture @@ -34,23 +34,22 @@ def test_construction(self): self.generator() -@pytest.fixture -def interface() -> Interface: - """ - A hook allowing implementations to override the fixture with a parameterization - @pytest.mark.parametrize("interface", [CustomInterface]) - """ - raise NotImplementedError - - class BaseInterfaceSuite(ABC): """ Custom implementations of the Interface class should inherit from this class for its tests. This class provides a generic test suite that all custom types must function with. """ - def test_construction(self, interface): + @pytest.fixture + def interface(self) -> Type[Interface]: + """ + A hook allowing implementations to override the fixture with a parameterization + @pytest.mark.parametrize("interface", [CustomInterface]) + """ + raise NotImplementedError + + def test_construction(self): """ Test the __init__ call of the interface object """ - interface() + self.interface() diff --git a/cppython/schema.py b/cppython/schema.py index 431e5bf..32d116f 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -5,6 +5,7 @@ from abc import ABC, abstractmethod from enum import Enum from pathlib import Path +from typing import Any, Type from pydantic import BaseModel, Field @@ -39,7 +40,7 @@ class Metadata(BaseModel): # TODO: Grab default from plugin without circular import generator: str = "CMake" target: TargetEnum - dependencies: dict[str, str] = [] + dependencies: dict[str, str] = {} install_path: Path = Field(alias="install-path") @@ -115,7 +116,7 @@ def external_config() -> bool: @staticmethod @abstractmethod - def parse_pep_621(data: dict) -> PEP621: + def parse_pep_621(data: dict[str, Any]) -> PEP621: """ Requests the plugin to read the available PEP 621 information. Only requested if the plugin is not the entrypoint @@ -131,7 +132,7 @@ def pep_621(self) -> PEP621: raise NotImplementedError() @abstractmethod - def read_pyproject(self) -> dict: + def read_pyproject(self) -> dict[str, Any]: """ Called when CPPoetry requires the content of pyproject.toml """ @@ -146,6 +147,10 @@ def write_pyproject(self) -> None: class GeneratorData(BaseModel): + """ + Base class for the configuration data that will be given to the generator constructor + """ + pass @@ -155,7 +160,7 @@ class Generator(Plugin, API): """ @abstractmethod - def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: dict) -> None: + def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: GeneratorData) -> None: super().__init__() @abstractmethod @@ -168,7 +173,7 @@ def install_generator(self) -> bool: @staticmethod @abstractmethod - def data_type() -> BaseModel: + def data_type() -> Type[GeneratorData]: """ Returns the pydantic type to cast the generator configuration data to """ diff --git a/pdm.lock b/pdm.lock index 85d4f74..50d6a34 100644 --- a/pdm.lock +++ b/pdm.lock @@ -205,8 +205,8 @@ dependencies = [ [[package]] name = "pytest-mock" -version = "3.6.1" -requires_python = ">=3.6" +version = "3.7.0" +requires_python = ">=3.7" summary = "Thin-wrapper around the mock package for easier use with pytest" dependencies = [ "pytest>=5.0", @@ -225,7 +225,7 @@ dependencies = [ [[package]] name = "setuptools" -version = "60.5.0" +version = "60.6.0" requires_python = ">=3.7" summary = "Easily download, build, install, upgrade, and uninstall Python packages" @@ -317,9 +317,6 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "coverage-6.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2bc85664b06ba42d14bb74d6ddf19d8bfc520cb660561d2d9ce5786ae72f71b5"}, {file = "coverage-6.3-cp310-cp310-win32.whl", hash = "sha256:27a94db5dc098c25048b0aca155f5fac674f2cf1b1736c5272ba28ead2fc267e"}, {file = "coverage-6.3-cp310-cp310-win_amd64.whl", hash = "sha256:bde4aeabc0d1b2e52c4036c54440b1ad05beeca8113f47aceb4998bb7471e2c2"}, - {file = "coverage-6.3-cp311-cp311-macosx_10_14_x86_64.whl", hash = "sha256:509c68c3e2015022aeda03b003dd68fa19987cdcf64e9d4edc98db41cfc45d30"}, - {file = "coverage-6.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:e4ff163602c5c77e7bb4ea81ba5d3b793b4419f8acd296aae149370902cf4e92"}, - {file = "coverage-6.3-cp311-cp311-win_amd64.whl", hash = "sha256:d1675db48490e5fa0b300f6329ecb8a9a37c29b9ab64fa9c964d34111788ca2d"}, {file = "coverage-6.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:7eed8459a2b81848cafb3280b39d7d49950d5f98e403677941c752e7e7ee47cb"}, {file = "coverage-6.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1b4285fde5286b946835a1a53bba3ad41ef74285ba9e8013e14b5ea93deaeafc"}, {file = "coverage-6.3-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a4748349734110fd32d46ff8897b561e6300d8989a494ad5a0a2e4f0ca974fc7"}, @@ -488,17 +485,17 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "pytest_forked-1.4.0-py3-none-any.whl", hash = "sha256:bbbb6717efc886b9d64537b41fb1497cfaf3c9601276be8da2cccfea5a3c8ad8"}, {file = "pytest-forked-1.4.0.tar.gz", hash = "sha256:8b67587c8f98cbbadfdd804539ed5455b6ed03802203485dd2f53c1422d7440e"}, ] -"pytest-mock 3.6.1" = [ - {file = "pytest_mock-3.6.1-py3-none-any.whl", hash = "sha256:30c2f2cc9759e76eee674b81ea28c9f0b94f8f0445a1b87762cadf774f0df7e3"}, - {file = "pytest-mock-3.6.1.tar.gz", hash = "sha256:40217a058c52a63f1042f0784f62009e976ba824c418cced42e88d5f40ab0e62"}, +"pytest-mock 3.7.0" = [ + {file = "pytest_mock-3.7.0-py3-none-any.whl", hash = "sha256:6cff27cec936bf81dc5ee87f07132b807bcda51106b5ec4b90a04331cba76231"}, + {file = "pytest-mock-3.7.0.tar.gz", hash = "sha256:5112bd92cc9f186ee96e1a92efc84969ea494939c3aead39c50f421c4cc69534"}, ] "pytest-xdist 2.5.0" = [ {file = "pytest_xdist-2.5.0-py3-none-any.whl", hash = "sha256:6fe5c74fec98906deb8f2d2b616b5c782022744978e7bd4695d39c8f42d0ce65"}, {file = "pytest-xdist-2.5.0.tar.gz", hash = "sha256:4580deca3ff04ddb2ac53eba39d76cb5dd5edeac050cb6fbc768b0dd712b4edf"}, ] -"setuptools 60.5.0" = [ - {file = "setuptools-60.5.0-py3-none-any.whl", hash = "sha256:68eb94073fc486091447fcb0501efd6560a0e5a1839ba249e5ff3c4c93f05f90"}, - {file = "setuptools-60.5.0.tar.gz", hash = "sha256:2404879cda71495fc4d5cbc445ed52fdaddf352b36e40be8dcc63147cb4edabe"}, +"setuptools 60.6.0" = [ + {file = "setuptools-60.6.0-py3-none-any.whl", hash = "sha256:c99207037c38984eae838c2fd986f39a9ddf4fabfe0fddd957e622d1d1dcdd05"}, + {file = "setuptools-60.6.0.tar.gz", hash = "sha256:eb83b1012ae6bf436901c2a2cee35d45b7260f31fd4b65fd1e50a9f99c11d7f8"}, ] "toml 0.10.2" = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index e35a973..a8b4322 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -2,9 +2,7 @@ TODO: """ -import pytest - -from cppython.plugins.generator.cmake import CMakeGenerator +from cppython.plugins.generator.cmake import CMakeData, CMakeGenerator from cppython.plugins.test.pytest import BaseGeneratorSuite @@ -14,10 +12,10 @@ class TestCMakeGenerator(BaseGeneratorSuite): """ def __init__(self) -> None: - super().__init__(CMakeGenerator) + super().__init__(CMakeGenerator, CMakeData) - def test_name(self, generator): + def test_type(self, generator: CMakeGenerator): """ Tests that the generators name is expected """ - assert generator.name() == "cmake" + assert generator.data_type == CMakeGenerator From ac665f4bf97b7ee9549adeb1da80db712ed5144c Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 2 Feb 2022 06:28:31 -0500 Subject: [PATCH 12/55] More Type Fixing --- .vscode/settings.json | 3 ++- cppython/exceptions.py | 12 +++--------- cppython/plugins/test/pytest.py | 8 ++------ cppython/project.py | 25 ++++++++++++++++--------- tests/unit/test_generator.py | 5 +---- tests/unit/test_interface.py | 13 ++++++++++--- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7e18c67..3023089 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,5 +18,6 @@ "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": true - } + }, + "python.analysis.typeCheckingMode": "basic" } \ No newline at end of file diff --git a/cppython/exceptions.py b/cppython/exceptions.py index 24b0f41..b705a6e 100644 --- a/cppython/exceptions.py +++ b/cppython/exceptions.py @@ -8,17 +8,11 @@ class ConfigError(Exception): Raised when there is a configuration error """ - def __init__(self, error: Exception) -> None: + def __init__(self, error: str) -> None: self._error = error - super().__init__(str(error)) + super().__init__(error) @property - def error(self) -> Exception: - """ - Accessor to the config error Exception base type - - Returns: - Exception -- The base error type - """ + def error(self) -> str: return self._error diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index ea4712d..eb6f657 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -1,12 +1,12 @@ """ TODO: """ -from abc import ABC, abstractmethod +from abc import ABC from typing import Type import pytest -from cppython.schema import Generator, GeneratorData, Interface +from cppython.schema import Generator, Interface class BaseGeneratorSuite(ABC): @@ -15,10 +15,6 @@ class BaseGeneratorSuite(ABC): This class provides a generic test suite that all custom types must function with. """ - @abstractmethod - def __init__(self, generator_type: Type[Generator], generator_data_type: Type[GeneratorData]) -> None: - super().__init__() - @pytest.fixture def generator(self) -> Type[Generator]: """ diff --git a/cppython/project.py b/cppython/project.py index cb29c7d..9db0765 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -1,13 +1,21 @@ import importlib import inspect import pkgutil -from typing import Callable, Type +from typing import Callable, Optional, Type, TypeVar +import cppython.plugins.generator +import cppython.plugins.interface from cppython.exceptions import ConfigError from cppython.schema import API, PEP621, Generator, Interface, Metadata, Plugin class Project(API): + """ + TODO + + + """ + def __init__(self, interface: Interface) -> None: self._interface = interface @@ -47,9 +55,11 @@ def _parse_generator_data(self, data: dict, generator_type): generator_config_type = generator_type.data_type() return generator_config_type(**data[generator_type.name()]) + _PluginType = TypeVar("_PluginType", bound=Type[Plugin]) + def _find_first_plugin( - self, namespace_package, plugin_type: Type[Plugin], condition: Callable[[str], bool] - ) -> Type[Plugin]: + self, namespace_package, plugin_type: _PluginType, condition: Callable[[str], bool] + ) -> Optional[_PluginType]: """ Finds the first plugin that satisfies the given condition """ @@ -61,23 +71,20 @@ def _find_first_plugin( if issubclass(value, plugin_type) & (value is not plugin_type): if condition(value.name()): return value + return None - def _load_interface(self, potential_keys: list) -> Type[Interface]: + def _load_interface(self, potential_keys: list) -> Optional[Type[Interface]]: """ TODO: """ - import cppython.plugins.interface - return self._find_first_plugin(cppython.plugins.interface, Interface, lambda name: name in potential_keys) - def _load_generator(self, generator: str) -> Type[Generator]: + def _load_generator(self, generator: str) -> Optional[Type[Generator]]: """ TODO: """ - import cppython.plugins.generator - return self._find_first_plugin(cppython.plugins.generator, Generator, lambda name: name == generator) def load(self): diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index a8b4322..ea0db3b 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -2,7 +2,7 @@ TODO: """ -from cppython.plugins.generator.cmake import CMakeData, CMakeGenerator +from cppython.plugins.generator.cmake import CMakeGenerator from cppython.plugins.test.pytest import BaseGeneratorSuite @@ -11,9 +11,6 @@ class TestCMakeGenerator(BaseGeneratorSuite): The tests for our CMake generator """ - def __init__(self) -> None: - super().__init__(CMakeGenerator, CMakeData) - def test_type(self, generator: CMakeGenerator): """ Tests that the generators name is expected diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 971495b..dd0bee2 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -4,20 +4,27 @@ import pytest from click.testing import CliRunner +from pytest_mock.plugin import MockerFixture from cppython.plugins.interface.console import Config, ConsoleInterface, cli from cppython.plugins.test.pytest import BaseInterfaceSuite -@pytest.mark.parametrize("interface", [ConsoleInterface]) class TestCLIInterface(BaseInterfaceSuite): """ The tests for our CLI interface """ @pytest.mark.parametrize("command", ["install", "update"]) - def test_command(self, interface, command, mocker): - + def test_command(self, interface: ConsoleInterface, command: str, mocker: MockerFixture): + """ + TODO + + Arguments: + interface {ConsoleInterface} -- [description] + command {str} -- [description] + mocker {[type]} -- [description] + """ # Patch the project mocker.patch("cppython.plugins.interface.console.Config.load") From c843f4933f5956191a6e71f1b1b5a6dc93802246 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 3 Feb 2022 15:53:39 -0500 Subject: [PATCH 13/55] Update Chore --- pdm.lock | 104 +++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/pdm.lock b/pdm.lock index 50d6a34..f034568 100644 --- a/pdm.lock +++ b/pdm.lock @@ -58,13 +58,13 @@ summary = "Cross-platform colored terminal text." [[package]] name = "coverage" -version = "6.3" +version = "6.3.1" requires_python = ">=3.7" summary = "Code coverage measurement for Python" [[package]] name = "coverage" -version = "6.3" +version = "6.3.1" extras = ["toml"] requires_python = ">=3.7" summary = "Code coverage measurement for Python" @@ -225,7 +225,7 @@ dependencies = [ [[package]] name = "setuptools" -version = "60.6.0" +version = "60.7.1" requires_python = ">=3.7" summary = "Easily download, build, install, upgrade, and uninstall Python packages" @@ -243,7 +243,7 @@ summary = "A lil' TOML parser" [[package]] name = "tomlkit" -version = "0.8.0" +version = "0.9.0" requires_python = ">=3.6,<4.0" summary = "Style preserving TOML library" @@ -306,48 +306,48 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] -"coverage 6.3" = [ - {file = "coverage-6.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e8071e7d9ba9f457fc674afc3de054450be2c9b195c470147fbbc082468d8ff7"}, - {file = "coverage-6.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:86c91c511853dfda81c2cf2360502cb72783f4b7cebabef27869f00cbe1db07d"}, - {file = "coverage-6.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3c4ce3b647bd1792d4394f5690d9df6dc035b00bcdbc5595099c01282a59ae01"}, - {file = "coverage-6.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2a491e159294d756e7fc8462f98175e2d2225e4dbe062cca7d3e0d5a75ba6260"}, - {file = "coverage-6.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5d008e0f67ac800b0ca04d7914b8501312c8c6c00ad8c7ba17754609fae1231a"}, - {file = "coverage-6.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:4578728c36de2801c1deb1c6b760d31883e62e33f33c7ba8f982e609dc95167d"}, - {file = "coverage-6.3-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:7ee317486593193e066fc5e98ac0ce712178c21529a85c07b7cb978171f25d53"}, - {file = "coverage-6.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2bc85664b06ba42d14bb74d6ddf19d8bfc520cb660561d2d9ce5786ae72f71b5"}, - {file = "coverage-6.3-cp310-cp310-win32.whl", hash = "sha256:27a94db5dc098c25048b0aca155f5fac674f2cf1b1736c5272ba28ead2fc267e"}, - {file = "coverage-6.3-cp310-cp310-win_amd64.whl", hash = "sha256:bde4aeabc0d1b2e52c4036c54440b1ad05beeca8113f47aceb4998bb7471e2c2"}, - {file = "coverage-6.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:7eed8459a2b81848cafb3280b39d7d49950d5f98e403677941c752e7e7ee47cb"}, - {file = "coverage-6.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1b4285fde5286b946835a1a53bba3ad41ef74285ba9e8013e14b5ea93deaeafc"}, - {file = "coverage-6.3-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a4748349734110fd32d46ff8897b561e6300d8989a494ad5a0a2e4f0ca974fc7"}, - {file = "coverage-6.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:823f9325283dc9565ba0aa2d240471a93ca8999861779b2b6c7aded45b58ee0f"}, - {file = "coverage-6.3-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:fff16a30fdf57b214778eff86391301c4509e327a65b877862f7c929f10a4253"}, - {file = "coverage-6.3-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:da1a428bdbe71f9a8c270c7baab29e9552ac9d0e0cba5e7e9a4c9ee6465d258d"}, - {file = "coverage-6.3-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:7d82c610a2e10372e128023c5baf9ce3d270f3029fe7274ff5bc2897c68f1318"}, - {file = "coverage-6.3-cp37-cp37m-win32.whl", hash = "sha256:11e61c5548ecf74ea1f8b059730b049871f0e32b74f88bd0d670c20c819ad749"}, - {file = "coverage-6.3-cp37-cp37m-win_amd64.whl", hash = "sha256:8e0c3525b1a182c8ffc9bca7e56b521e0c2b8b3e82f033c8e16d6d721f1b54d6"}, - {file = "coverage-6.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:a189036c50dcd56100746139a459f0d27540fef95b09aba03e786540b8feaa5f"}, - {file = "coverage-6.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:32168001f33025fd756884d56d01adebb34e6c8c0b3395ca8584cdcee9c7c9d2"}, - {file = "coverage-6.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a5d79c9af3f410a2b5acad91258b4ae179ee9c83897eb9de69151b179b0227f5"}, - {file = "coverage-6.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:85c5fc9029043cf8b07f73fbb0a7ab6d3b717510c3b5642b77058ea55d7cacde"}, - {file = "coverage-6.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a7596aa2f2b8fa5604129cfc9a27ad9beec0a96f18078cb424d029fdd707468d"}, - {file = "coverage-6.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:ce443a3e6df90d692c38762f108fc4c88314bf477689f04de76b3f252e7a351c"}, - {file = "coverage-6.3-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:012157499ec4f135fc36cd2177e3d1a1840af9b236cbe80e9a5ccfc83d912a69"}, - {file = "coverage-6.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:0a34d313105cdd0d3644c56df2d743fe467270d6ab93b5d4a347eb9fec8924d6"}, - {file = "coverage-6.3-cp38-cp38-win32.whl", hash = "sha256:6e78b1e25e5c5695dea012be473e442f7094d066925604be20b30713dbd47f89"}, - {file = "coverage-6.3-cp38-cp38-win_amd64.whl", hash = "sha256:433b99f7b0613bdcdc0b00cc3d39ed6d756797e3b078d2c43f8a38288520aec6"}, - {file = "coverage-6.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9ed3244b415725f08ca3bdf02ed681089fd95e9465099a21c8e2d9c5d6ca2606"}, - {file = "coverage-6.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ab4fc4b866b279740e0d917402f0e9a08683e002f43fa408e9655818ed392196"}, - {file = "coverage-6.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c8582e9280f8d0f38114fe95a92ae8d0790b56b099d728cc4f8a2e14b1c4a18c"}, - {file = "coverage-6.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c72bb4679283c6737f452eeb9b2a0e570acaef2197ad255fb20162adc80bea76"}, - {file = "coverage-6.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ca29c352389ea27a24c79acd117abdd8a865c6eb01576b6f0990cd9a4e9c9f48"}, - {file = "coverage-6.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:152cc2624381df4e4e604e21bd8e95eb8059535f7b768c1fb8b8ae0b26f47ab0"}, - {file = "coverage-6.3-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:51372e24b1f7143ee2df6b45cff6a721f3abe93b1e506196f3ffa4155c2497f7"}, - {file = "coverage-6.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:72d9d186508325a456475dd05b1756f9a204c7086b07fffb227ef8cee03b1dc2"}, - {file = "coverage-6.3-cp39-cp39-win32.whl", hash = "sha256:649df3641eb351cdfd0d5533c92fc9df507b6b2bf48a7ef8c71ab63cbc7b5c3c"}, - {file = "coverage-6.3-cp39-cp39-win_amd64.whl", hash = "sha256:e67ccd53da5958ea1ec833a160b96357f90859c220a00150de011b787c27b98d"}, - {file = "coverage-6.3-pp36.pp37.pp38-none-any.whl", hash = "sha256:27ac7cb84538e278e07569ceaaa6f807a029dc194b1c819a9820b9bb5dbf63ab"}, - {file = "coverage-6.3.tar.gz", hash = "sha256:987a84ff98a309994ca77ed3cc4b92424f824278e48e4bf7d1bb79a63cfe2099"}, +"coverage 6.3.1" = [ + {file = "coverage-6.3.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:eeffd96882d8c06d31b65dddcf51db7c612547babc1c4c5db6a011abe9798525"}, + {file = "coverage-6.3.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:621f6ea7260ea2ffdaec64fe5cb521669984f567b66f62f81445221d4754df4c"}, + {file = "coverage-6.3.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:84f2436d6742c01136dd940ee158bfc7cf5ced3da7e4c949662b8703b5cd8145"}, + {file = "coverage-6.3.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:de73fca6fb403dd72d4da517cfc49fcf791f74eee697d3219f6be29adf5af6ce"}, + {file = "coverage-6.3.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:78fbb2be068a13a5d99dce9e1e7d168db880870f7bc73f876152130575bd6167"}, + {file = "coverage-6.3.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:f5a4551dfd09c3bd12fca8144d47fe7745275adf3229b7223c2f9e29a975ebda"}, + {file = "coverage-6.3.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:7bff3a98f63b47464480de1b5bdd80c8fade0ba2832c9381253c9b74c4153c27"}, + {file = "coverage-6.3.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:a06c358f4aed05fa1099c39decc8022261bb07dfadc127c08cfbd1391b09689e"}, + {file = "coverage-6.3.1-cp310-cp310-win32.whl", hash = "sha256:9fff3ff052922cb99f9e52f63f985d4f7a54f6b94287463bc66b7cdf3eb41217"}, + {file = "coverage-6.3.1-cp310-cp310-win_amd64.whl", hash = "sha256:276b13cc085474e482566c477c25ed66a097b44c6e77132f3304ac0b039f83eb"}, + {file = "coverage-6.3.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:56c4a409381ddd7bbff134e9756077860d4e8a583d310a6f38a2315b9ce301d0"}, + {file = "coverage-6.3.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9eb494070aa060ceba6e4bbf44c1bc5fa97bfb883a0d9b0c9049415f9e944793"}, + {file = "coverage-6.3.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5e15d424b8153756b7c903bde6d4610be0c3daca3986173c18dd5c1a1625e4cd"}, + {file = "coverage-6.3.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61d47a897c1e91f33f177c21de897267b38fbb45f2cd8e22a710bcef1df09ac1"}, + {file = "coverage-6.3.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:25e73d4c81efa8ea3785274a2f7f3bfbbeccb6fcba2a0bdd3be9223371c37554"}, + {file = "coverage-6.3.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:fac0bcc5b7e8169bffa87f0dcc24435446d329cbc2b5486d155c2e0f3b493ae1"}, + {file = "coverage-6.3.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:72128176fea72012063200b7b395ed8a57849282b207321124d7ff14e26988e8"}, + {file = "coverage-6.3.1-cp37-cp37m-win32.whl", hash = "sha256:1bc6d709939ff262fd1432f03f080c5042dc6508b6e0d3d20e61dd045456a1a0"}, + {file = "coverage-6.3.1-cp37-cp37m-win_amd64.whl", hash = "sha256:618eeba986cea7f621d8607ee378ecc8c2504b98b3fdc4952b30fe3578304687"}, + {file = "coverage-6.3.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d5ed164af5c9078596cfc40b078c3b337911190d3faeac830c3f1274f26b8320"}, + {file = "coverage-6.3.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:352c68e233409c31048a3725c446a9e48bbff36e39db92774d4f2380d630d8f8"}, + {file = "coverage-6.3.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:448d7bde7ceb6c69e08474c2ddbc5b4cd13c9e4aa4a717467f716b5fc938a734"}, + {file = "coverage-6.3.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9fde6b90889522c220dd56a670102ceef24955d994ff7af2cb786b4ba8fe11e4"}, + {file = "coverage-6.3.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e647a0be741edbb529a72644e999acb09f2ad60465f80757da183528941ff975"}, + {file = "coverage-6.3.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:6a5cdc3adb4f8bb8d8f5e64c2e9e282bc12980ef055ec6da59db562ee9bdfefa"}, + {file = "coverage-6.3.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:2dd70a167843b4b4b2630c0c56f1b586fe965b4f8ac5da05b6690344fd065c6b"}, + {file = "coverage-6.3.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:9ad0a117b8dc2061ce9461ea4c1b4799e55edceb236522c5b8f958ce9ed8fa9a"}, + {file = "coverage-6.3.1-cp38-cp38-win32.whl", hash = "sha256:e92c7a5f7d62edff50f60a045dc9542bf939758c95b2fcd686175dd10ce0ed10"}, + {file = "coverage-6.3.1-cp38-cp38-win_amd64.whl", hash = "sha256:482fb42eea6164894ff82abbcf33d526362de5d1a7ed25af7ecbdddd28fc124f"}, + {file = "coverage-6.3.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c5b81fb37db76ebea79aa963b76d96ff854e7662921ce742293463635a87a78d"}, + {file = "coverage-6.3.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a4f923b9ab265136e57cc14794a15b9dcea07a9c578609cd5dbbfff28a0d15e6"}, + {file = "coverage-6.3.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:56d296cbc8254a7dffdd7bcc2eb70be5a233aae7c01856d2d936f5ac4e8ac1f1"}, + {file = "coverage-6.3.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1245ab82e8554fa88c4b2ab1e098ae051faac5af829efdcf2ce6b34dccd5567c"}, + {file = "coverage-6.3.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3f2b05757c92ad96b33dbf8e8ec8d4ccb9af6ae3c9e9bd141c7cc44d20c6bcba"}, + {file = "coverage-6.3.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:9e3dd806f34de38d4c01416344e98eab2437ac450b3ae39c62a0ede2f8b5e4ed"}, + {file = "coverage-6.3.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:d651fde74a4d3122e5562705824507e2f5b2d3d57557f1916c4b27635f8fbe3f"}, + {file = "coverage-6.3.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:704f89b87c4f4737da2860695a18c852b78ec7279b24eedacab10b29067d3a38"}, + {file = "coverage-6.3.1-cp39-cp39-win32.whl", hash = "sha256:2aed4761809640f02e44e16b8b32c1a5dee5e80ea30a0ff0912158bde9c501f2"}, + {file = "coverage-6.3.1-cp39-cp39-win_amd64.whl", hash = "sha256:9976fb0a5709988778ac9bc44f3d50fccd989987876dfd7716dee28beed0a9fa"}, + {file = "coverage-6.3.1-pp36.pp37.pp38-none-any.whl", hash = "sha256:463e52616ea687fd323888e86bf25e864a3cc6335a043fad6bbb037dbf49bbe2"}, + {file = "coverage-6.3.1.tar.gz", hash = "sha256:6c3f6158b02ac403868eea390930ae64e9a9a2a5bbfafefbb920d29258d9f2f8"}, ] "execnet 1.9.0" = [ {file = "execnet-1.9.0-py2.py3-none-any.whl", hash = "sha256:a295f7cc774947aac58dde7fdc85f4aa00c42adf5d8f5468fc630c1acf30a142"}, @@ -493,9 +493,9 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "pytest_xdist-2.5.0-py3-none-any.whl", hash = "sha256:6fe5c74fec98906deb8f2d2b616b5c782022744978e7bd4695d39c8f42d0ce65"}, {file = "pytest-xdist-2.5.0.tar.gz", hash = "sha256:4580deca3ff04ddb2ac53eba39d76cb5dd5edeac050cb6fbc768b0dd712b4edf"}, ] -"setuptools 60.6.0" = [ - {file = "setuptools-60.6.0-py3-none-any.whl", hash = "sha256:c99207037c38984eae838c2fd986f39a9ddf4fabfe0fddd957e622d1d1dcdd05"}, - {file = "setuptools-60.6.0.tar.gz", hash = "sha256:eb83b1012ae6bf436901c2a2cee35d45b7260f31fd4b65fd1e50a9f99c11d7f8"}, +"setuptools 60.7.1" = [ + {file = "setuptools-60.7.1-py3-none-any.whl", hash = "sha256:c9097cbcdefe88a64da966a764f2d95feb1cfaff77cc304528a23cefe3359d9a"}, + {file = "setuptools-60.7.1.tar.gz", hash = "sha256:a4dc3af29a67e7a45620aba43dde2c1af2dd6bc49726d78168f0cc6c4fb0c01b"}, ] "toml 0.10.2" = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, @@ -505,9 +505,9 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "tomli-1.2.3-py3-none-any.whl", hash = "sha256:e3069e4be3ead9668e21cb9b074cd948f7b3113fd9c8bba083f48247aab8b11c"}, {file = "tomli-1.2.3.tar.gz", hash = "sha256:05b6166bff487dc068d322585c7ea4ef78deed501cc124060e0f238e89a9231f"}, ] -"tomlkit 0.8.0" = [ - {file = "tomlkit-0.8.0-py3-none-any.whl", hash = "sha256:b824e3466f1d475b2b5f1c392954c6cb7ea04d64354ff7300dc7c14257dc85db"}, - {file = "tomlkit-0.8.0.tar.gz", hash = "sha256:29e84a855712dfe0e88a48f6d05c21118dbafb283bb2eed614d46f80deb8e9a1"}, +"tomlkit 0.9.0" = [ + {file = "tomlkit-0.9.0-py3-none-any.whl", hash = "sha256:c1b0fc73abd4f1e77c29ea4061ca0f2e11cbfb77342e17df3d3fdd496fc3f899"}, + {file = "tomlkit-0.9.0.tar.gz", hash = "sha256:5a83672c565f78f5fc8f1e44e5f2726446cc6b765113efd21d03e9331747d9ab"}, ] "typing-extensions 4.0.1" = [ {file = "typing_extensions-4.0.1-py3-none-any.whl", hash = "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"}, From 1ab173b49f0a4a12b48f4e4e5f5ede416ddc7f87 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 3 Feb 2022 17:02:11 -0500 Subject: [PATCH 14/55] Docstrings --- cppython/project.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cppython/project.py b/cppython/project.py index 9db0765..3a7c326 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -21,7 +21,7 @@ def __init__(self, interface: Interface) -> None: self._interface = interface self.loaded = False - def _parse_PEP621_data(self, data: dict, interface_type: Interface) -> PEP621: + def _parse_pep621_data(self, data: dict, interface_type: Interface) -> PEP621: """ Extracts the PEP621 metadata from the various possible project formats """ @@ -88,6 +88,10 @@ def _load_generator(self, generator: str) -> Optional[Type[Generator]]: return self._find_first_plugin(cppython.plugins.generator, Generator, lambda name: name == generator) def load(self): + """ + TODO + """ + # Read the raw configuration data pyproject_data = self._interface.read_pyproject() cppython_data = self._parse_cppython_data(pyproject_data) @@ -98,7 +102,7 @@ def load(self): if generator_type is None: raise ConfigError("") - pep_621 = self._parse_PEP621_data(pyproject_data, self._interface) + pep_621 = self._parse_pep621_data(pyproject_data, self._interface) generator_data = self._parse_generator_data(pyproject_data, generator_type) # Construct the generator From 987bdd123d2e4f094ffb4fb27cacbc2429d80665 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Fri, 4 Feb 2022 10:45:27 -0500 Subject: [PATCH 15/55] Update Chore --- pdm.lock | 59 +++++++++++++++++++++++++++++++++----------------- pyproject.toml | 24 ++++++++++---------- 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/pdm.lock b/pdm.lock index f034568..15488a4 100644 --- a/pdm.lock +++ b/pdm.lock @@ -23,17 +23,15 @@ summary = "Classes Without Boilerplate" [[package]] name = "black" -version = "21.12b0" +version = "22.1.0" requires_python = ">=3.6.2" summary = "The uncompromising code formatter." dependencies = [ - "click>=7.1.2", + "click>=8.0.0", "mypy-extensions>=0.4.3", - "pathspec<1,>=0.9.0", + "pathspec>=0.9.0", "platformdirs>=2", - "tomli<2.0.0,>=0.2.6", - "typing-extensions!=3.10.0.1; python_version >= \"3.10\"", - "typing-extensions>=3.10.0.0", + "tomli>=1.1.0", ] [[package]] @@ -169,7 +167,7 @@ summary = "Python parsing module" [[package]] name = "pytest" -version = "6.2.5" +version = "7.0.0" requires_python = ">=3.6" summary = "pytest: simple powerful testing with Python" dependencies = [ @@ -180,7 +178,7 @@ dependencies = [ "packaging", "pluggy<2.0,>=0.12", "py>=1.8.2", - "toml", + "tomli>=1.0.0", ] [[package]] @@ -237,8 +235,8 @@ summary = "Python Library for Tom's Obvious, Minimal Language" [[package]] name = "tomli" -version = "1.2.3" -requires_python = ">=3.6" +version = "2.0.0" +requires_python = ">=3.7" summary = "A lil' TOML parser" [[package]] @@ -261,7 +259,7 @@ summary = "Module for decorators, wrappers and monkey patching." [metadata] lock_version = "3.1" -content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198dd30246c" +content_hash = "sha256:899fefd00e486ed8301b187fd6050d9b60643b5c5f66fa19d57b2516c42d1216" [metadata.files] "astroid 2.9.3" = [ @@ -276,9 +274,30 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, ] -"black 21.12b0" = [ - {file = "black-21.12b0-py3-none-any.whl", hash = "sha256:a615e69ae185e08fdd73e4715e260e2479c861b5740057fde6e8b4e3b7dd589f"}, - {file = "black-21.12b0.tar.gz", hash = "sha256:77b80f693a569e2e527958459634f18df9b0ba2625ba4e0c2d5da5be42e6f2b3"}, +"black 22.1.0" = [ + {file = "black-22.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:1297c63b9e1b96a3d0da2d85d11cd9bf8664251fd69ddac068b98dc4f34f73b6"}, + {file = "black-22.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2ff96450d3ad9ea499fc4c60e425a1439c2120cbbc1ab959ff20f7c76ec7e866"}, + {file = "black-22.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0e21e1f1efa65a50e3960edd068b6ae6d64ad6235bd8bfea116a03b21836af71"}, + {file = "black-22.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e2f69158a7d120fd641d1fa9a921d898e20d52e44a74a6fbbcc570a62a6bc8ab"}, + {file = "black-22.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:228b5ae2c8e3d6227e4bde5920d2fc66cc3400fde7bcc74f480cb07ef0b570d5"}, + {file = "black-22.1.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b1a5ed73ab4c482208d20434f700d514f66ffe2840f63a6252ecc43a9bc77e8a"}, + {file = "black-22.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:35944b7100af4a985abfcaa860b06af15590deb1f392f06c8683b4381e8eeaf0"}, + {file = "black-22.1.0-cp36-cp36m-win_amd64.whl", hash = "sha256:7835fee5238fc0a0baf6c9268fb816b5f5cd9b8793423a75e8cd663c48d073ba"}, + {file = "black-22.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:dae63f2dbf82882fa3b2a3c49c32bffe144970a573cd68d247af6560fc493ae1"}, + {file = "black-22.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5fa1db02410b1924b6749c245ab38d30621564e658297484952f3d8a39fce7e8"}, + {file = "black-22.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:c8226f50b8c34a14608b848dc23a46e5d08397d009446353dad45e04af0c8e28"}, + {file = "black-22.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:2d6f331c02f0f40aa51a22e479c8209d37fcd520c77721c034517d44eecf5912"}, + {file = "black-22.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:742ce9af3086e5bd07e58c8feb09dbb2b047b7f566eb5f5bc63fd455814979f3"}, + {file = "black-22.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:fdb8754b453fb15fad3f72cd9cad3e16776f0964d67cf30ebcbf10327a3777a3"}, + {file = "black-22.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f5660feab44c2e3cb24b2419b998846cbb01c23c7fe645fee45087efa3da2d61"}, + {file = "black-22.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:6f2f01381f91c1efb1451998bd65a129b3ed6f64f79663a55fe0e9b74a5f81fd"}, + {file = "black-22.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:efbadd9b52c060a8fc3b9658744091cb33c31f830b3f074422ed27bad2b18e8f"}, + {file = "black-22.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:8871fcb4b447206904932b54b567923e5be802b9b19b744fdff092bd2f3118d0"}, + {file = "black-22.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ccad888050f5393f0d6029deea2a33e5ae371fd182a697313bdbd835d3edaf9c"}, + {file = "black-22.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:07e5c049442d7ca1a2fc273c79d1aecbbf1bc858f62e8184abe1ad175c4f7cc2"}, + {file = "black-22.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:373922fc66676133ddc3e754e4509196a8c392fec3f5ca4486673e685a421321"}, + {file = "black-22.1.0-py3-none-any.whl", hash = "sha256:3524739d76b6b3ed1132422bf9d82123cd1705086723bc3e235ca39fd21c667d"}, + {file = "black-22.1.0.tar.gz", hash = "sha256:a7c0192d35635f6fc1174be575cb7915e92e5dd629ee79fdaf0dcfa41a80afb5"}, ] "click 8.0.3" = [ {file = "click-8.0.3-py3-none-any.whl", hash = "sha256:353f466495adaeb40b6b5f592f9f91cb22372351c84caeb068132442a4518ef3"}, @@ -473,9 +492,9 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "pyparsing-3.0.7-py3-none-any.whl", hash = "sha256:a6c06a88f252e6c322f65faf8f418b16213b51bdfaece0524c1c1bc30c63c484"}, {file = "pyparsing-3.0.7.tar.gz", hash = "sha256:18ee9022775d270c55187733956460083db60b37d0d0fb357445f3094eed3eea"}, ] -"pytest 6.2.5" = [ - {file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"}, - {file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"}, +"pytest 7.0.0" = [ + {file = "pytest-7.0.0-py3-none-any.whl", hash = "sha256:42901e6bd4bd4a0e533358a86e848427a49005a3256f657c5c8f8dd35ef137a9"}, + {file = "pytest-7.0.0.tar.gz", hash = "sha256:dad48ffda394e5ad9aa3b7d7ddf339ed502e5e365b1350e0af65f4a602344b11"}, ] "pytest-cov 3.0.0" = [ {file = "pytest_cov-3.0.0-py3-none-any.whl", hash = "sha256:578d5d15ac4a25e5f961c938b85a05b09fdaae9deef3bb6de9a6e766622ca7a6"}, @@ -501,9 +520,9 @@ content_hash = "sha256:1bc5738eacbb0511baeca390a8df0c76982a4788b70dd091de4d8198d {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, ] -"tomli 1.2.3" = [ - {file = "tomli-1.2.3-py3-none-any.whl", hash = "sha256:e3069e4be3ead9668e21cb9b074cd948f7b3113fd9c8bba083f48247aab8b11c"}, - {file = "tomli-1.2.3.tar.gz", hash = "sha256:05b6166bff487dc068d322585c7ea4ef78deed501cc124060e0f238e89a9231f"}, +"tomli 2.0.0" = [ + {file = "tomli-2.0.0-py3-none-any.whl", hash = "sha256:b5bde28da1fed24b9bd1d4d2b8cba62300bfb4ec9a6187a957e8ddb9434c5224"}, + {file = "tomli-2.0.0.tar.gz", hash = "sha256:c292c34f58502a1eb2bbb9f5bbc9a5ebc37bee10ffb8c2d6bbdfa8eb13cc14e1"}, ] "tomlkit 0.9.0" = [ {file = "tomlkit-0.9.0-py3-none-any.whl", hash = "sha256:c1b0fc73abd4f1e77c29ea4061ca0f2e11cbfb77342e17df3d3fdd496fc3f899"}, diff --git a/pyproject.toml b/pyproject.toml index 6fc5eec..642b438 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,11 +18,11 @@ dynamic = ["version"] requires-python = ">=3.10" dependencies = [ - "click>=8.0", - "cmake>=3.22", - "pydantic>=1.8", - "tomlkit>=0.7", - "pytest>=6.2", # Required for testing injection + "click>=8.0.3", + "cmake>=3.22.2", + "pydantic>=1.9", + "tomlkit>=0.9", + "pytest>=7.0.0", # Required for testing injection ] [tool.pdm] @@ -30,14 +30,14 @@ version = {use_scm = true} [tool.pdm.dev-dependencies] lint = [ - "black<22,>=21.11b1", - "pylint>=2.12", - "isort", + "black>=22.1.0", + "pylint>=2.12.2", + "isort>=5.10.1", ] test = [ - "pytest-cov>=3.0", - "pytest-mock>=3.6", - "pytest-xdist>=2.5", + "pytest-cov>=3.0.0", + "pytest-mock>=3.7.0", + "pytest-xdist>=2.5.0", ] [project.scripts] @@ -54,8 +54,8 @@ testpaths = [ ] [tool.black] -experimental-string-processing = true line-length = 120 +preview = true [tool.isort] profile = "black" From 7419d2120809a4d591dd2fa1506b6f7917970991 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sat, 5 Feb 2022 18:40:54 -0500 Subject: [PATCH 16/55] Add Defaults --- cppython/plugins/generator/cmake.py | 2 +- cppython/plugins/interface/console.py | 38 ++++++++++++++++++++------- cppython/plugins/test/data.py | 13 +++++++++ cppython/plugins/test/pytest.py | 16 +++++------ cppython/schema.py | 18 +++++++++---- tests/unit/test_generator.py | 10 ++++++- tests/unit/test_interface.py | 5 ++++ 7 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 cppython/plugins/test/data.py diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index 4b7fffe..40c1378 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -12,7 +12,7 @@ class CMakeData(GeneratorData): TODO: """ - installation_location: Path + pass class CMakeGenerator(Generator): diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index 2a91a49..7e39ed2 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -2,16 +2,20 @@ TODO: """ +from mimetypes import init from pathlib import Path import click import tomlkit from cppython.project import Project -from cppython.schema import PEP621, Interface +from cppython.schema import PEP621, Interface, PyProject def _read_data(): + """ + TODO + """ path = Path.cwd() while not path.glob("pyproject.toml"): @@ -32,13 +36,18 @@ def __init__(self): data = _read_data() + pyproject = PyProject(data=data) + # Initialize the object hook into CPPython - interface = ConsoleInterface(data) + interface = ConsoleInterface(pyproject) # Initialize the CPPython context self.project = Project(interface) def load(self): + """ + TODO + """ self.project.load() @@ -48,6 +57,9 @@ def load(self): @click.group() @click.pass_context def cli(context): + """ + TODO + """ context.ensure_object(Config) # Initialize cppython @@ -57,19 +69,27 @@ def cli(context): @cli.command() @pass_config def install(config): + """ + TODO + """ config.project.install() @cli.command() @pass_config def update(config): + """ + TODO + """ config.project.update() @cli.result_callback() @pass_config def cleanup(config, result): - pass + """ + TODO + """ class ConsoleInterface(Interface): @@ -77,8 +97,8 @@ class ConsoleInterface(Interface): TODO: Description """ - def __init__(self, data: dict) -> None: - self._data = data + def __init__(self, pyproject: PyProject) -> None: + super().__init__(pyproject) # Plugin Contract @@ -101,7 +121,7 @@ def external_config() -> bool: return False @staticmethod - def parse_pep_621(data: dict) -> PEP621: + def parse_pep_621(data: PyProject) -> PEP621: """ Requests the plugin to read the available PEP 621 information. Only requested if the plugin is not the entrypoint """ @@ -111,10 +131,10 @@ def pep_621(self) -> PEP621: """ Requests PEP 621 information from the pyproject """ - return self.parse_pep_621(self._data) + return self.parse_pep_621(self._pyproject) def write_pyproject(self) -> None: raise NotImplementedError() - def read_pyproject(self) -> dict: - return self._data + def read_pyproject(self) -> PyProject: + return self._pyproject diff --git a/cppython/plugins/test/data.py b/cppython/plugins/test/data.py new file mode 100644 index 0000000..e5cb87f --- /dev/null +++ b/cppython/plugins/test/data.py @@ -0,0 +1,13 @@ +""" +TODO +""" + +from pathlib import Path + +from cppython.schema import PEP621, Metadata, PyProject, TargetEnum + +default_pyproject = PyProject(data={}) + +default_pep621 = PEP621(name="Ya", version="1.0") + +default_metadata = Metadata(target=TargetEnum.EXE, install_path=Path()) diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index eb6f657..76d31c8 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -2,7 +2,6 @@ TODO: """ from abc import ABC -from typing import Type import pytest @@ -15,19 +14,19 @@ class BaseGeneratorSuite(ABC): This class provides a generic test suite that all custom types must function with. """ - @pytest.fixture - def generator(self) -> Type[Generator]: + @pytest.fixture(name="generator") + def fixture_generator(self) -> Generator: """ A hook allowing implementations to override the fixture with a parameterization @pytest.mark.parametrize("generator", [CustomGenerator]) """ raise NotImplementedError - def test_construction(self): + def test_construction(self, generator: Generator): """ Test the __init__ call of the generator object """ - self.generator() + pass class BaseInterfaceSuite(ABC): @@ -36,16 +35,15 @@ class BaseInterfaceSuite(ABC): This class provides a generic test suite that all custom types must function with. """ - @pytest.fixture - def interface(self) -> Type[Interface]: + @pytest.fixture(name="interface") + def fixture_interface(self) -> Interface: """ A hook allowing implementations to override the fixture with a parameterization @pytest.mark.parametrize("interface", [CustomInterface]) """ raise NotImplementedError - def test_construction(self): + def test_construction(self, interface: Interface): """ Test the __init__ call of the interface object """ - self.interface() diff --git a/cppython/schema.py b/cppython/schema.py index 32d116f..5fe771e 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -20,6 +20,14 @@ class TargetEnum(Enum): SHARED = "shared" +class PyProject(BaseModel): + """ + TODO + """ + + data: dict[str, str] + + class PEP621(BaseModel): """ Subset of PEP 621 @@ -41,7 +49,7 @@ class Metadata(BaseModel): generator: str = "CMake" target: TargetEnum dependencies: dict[str, str] = {} - install_path: Path = Field(alias="install-path") + install_path: Path class API(ABC): @@ -85,6 +93,7 @@ class Plugin(ABC): Abstract plugin type """ + @abstractmethod def __init__(self) -> None: pass @@ -102,8 +111,10 @@ class Interface(Plugin): Abstract type to be inherited by CPPython Interface plugins """ - def __init__(self) -> None: + @abstractmethod + def __init__(self, pyproject: PyProject) -> None: super().__init__() + self._pyproject = pyproject @staticmethod def external_config() -> bool: @@ -151,8 +162,6 @@ class GeneratorData(BaseModel): Base class for the configuration data that will be given to the generator constructor """ - pass - class Generator(Plugin, API): """ @@ -169,7 +178,6 @@ def install_generator(self) -> bool: Installs the external tooling required by the generator if necessary Returns whether anything was installed or not """ - pass @staticmethod @abstractmethod diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index ea0db3b..d22fa0e 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -2,7 +2,10 @@ TODO: """ -from cppython.plugins.generator.cmake import CMakeGenerator +import pytest + +from cppython.plugins.generator.cmake import CMakeData, CMakeGenerator +from cppython.plugins.test.data import default_metadata, default_pep621 from cppython.plugins.test.pytest import BaseGeneratorSuite @@ -11,6 +14,11 @@ class TestCMakeGenerator(BaseGeneratorSuite): The tests for our CMake generator """ + @pytest.fixture(name="generator") + def fixture_generator(self): + cmake_data = CMakeData() + return CMakeGenerator(default_pep621, default_metadata, cmake_data) + def test_type(self, generator: CMakeGenerator): """ Tests that the generators name is expected diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index dd0bee2..354e647 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -7,6 +7,7 @@ from pytest_mock.plugin import MockerFixture from cppython.plugins.interface.console import Config, ConsoleInterface, cli +from cppython.plugins.test.data import default_pyproject from cppython.plugins.test.pytest import BaseInterfaceSuite @@ -15,6 +16,10 @@ class TestCLIInterface(BaseInterfaceSuite): The tests for our CLI interface """ + @pytest.fixture(name="interface") + def fixture_interface(self): + return ConsoleInterface(default_pyproject) + @pytest.mark.parametrize("command", ["install", "update"]) def test_command(self, interface: ConsoleInterface, command: str, mocker: MockerFixture): """ From 018e6a289d7d59fa15f19a23c3cfa7a438c198fd Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sat, 5 Feb 2022 19:04:38 -0500 Subject: [PATCH 17/55] Fix Tests --- tests/unit/test_generator.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index d22fa0e..3897bcf 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -18,9 +18,3 @@ class TestCMakeGenerator(BaseGeneratorSuite): def fixture_generator(self): cmake_data = CMakeData() return CMakeGenerator(default_pep621, default_metadata, cmake_data) - - def test_type(self, generator: CMakeGenerator): - """ - Tests that the generators name is expected - """ - assert generator.data_type == CMakeGenerator From 0c343bc8a8e5e9ba22aef895d5466873978bfdc8 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Feb 2022 09:33:07 -0500 Subject: [PATCH 18/55] Add Schema Test --- tests/unit/test_interface.py | 2 +- tests/unit/test_project.py | 10 ++++++++-- tests/unit/test_schema.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tests/unit/test_schema.py diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 354e647..babf413 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -21,7 +21,7 @@ def fixture_interface(self): return ConsoleInterface(default_pyproject) @pytest.mark.parametrize("command", ["install", "update"]) - def test_command(self, interface: ConsoleInterface, command: str, mocker: MockerFixture): + def test_command(self, command: str, mocker: MockerFixture): """ TODO diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index 0e20419..4158ef3 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -1,9 +1,15 @@ """ -TODO: +TODO """ from cppython.project import Project class TestProject: + """ + TODO + """ + def test_something(self): - pass + """ + TODO + """ diff --git a/tests/unit/test_schema.py b/tests/unit/test_schema.py new file mode 100644 index 0000000..288696a --- /dev/null +++ b/tests/unit/test_schema.py @@ -0,0 +1,34 @@ +""" +TODO: +""" +import pytest + +from cppython.plugins.test.data import ( + default_metadata, + default_pep621, + default_pyproject, +) + + +class TestSchema: + """ + TODO + """ + + @pytest.mark.parametrize("metadata", [default_metadata]) + def test_metadata(self, metadata): + """ + TODO + """ + + @pytest.mark.parametrize("pep621", [default_pep621]) + def test_pep621(self, pep621): + """ + TODO + """ + + @pytest.mark.parametrize("pyproject", [default_pyproject]) + def test_pyproject(self, pyproject): + """ + TODO + """ From 921cbeefcf418e368c886aae004af2cf2bf05f6c Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Feb 2022 13:47:40 -0500 Subject: [PATCH 19/55] us --- cppython/plugins/interface/console.py | 19 +++++++++++++++---- cppython/plugins/test/data.py | 2 +- cppython/schema.py | 5 +++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index 7e39ed2..0b687e4 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -4,15 +4,17 @@ from mimetypes import init from pathlib import Path +from typing import Tuple import click import tomlkit +from tomlkit.api import TOMLDocument from cppython.project import Project from cppython.schema import PEP621, Interface, PyProject -def _read_data(): +def _path_search() -> Path: """ TODO """ @@ -24,7 +26,15 @@ def _read_data(): False ), "This is not a valid project. No pyproject.toml found in the current directory or any of its parents." - return tomlkit.loads(Path(path / "pyproject.toml").read_text(encoding="utf-8")) + return Path(path / "pyproject.toml") + + +def _read_data(path: Path) -> TOMLDocument: + """ + TODO + """ + + return tomlkit.loads(path.read_text(encoding="utf-8")) class Config: @@ -34,9 +44,10 @@ class Config: def __init__(self): - data = _read_data() + path = _path_search() + data = _read_data(path) - pyproject = PyProject(data=data) + pyproject = PyProject(data=data, path=path) # Initialize the object hook into CPPython interface = ConsoleInterface(pyproject) diff --git a/cppython/plugins/test/data.py b/cppython/plugins/test/data.py index e5cb87f..a769fb5 100644 --- a/cppython/plugins/test/data.py +++ b/cppython/plugins/test/data.py @@ -6,7 +6,7 @@ from cppython.schema import PEP621, Metadata, PyProject, TargetEnum -default_pyproject = PyProject(data={}) +default_pyproject = PyProject(data={}, path=Path()) default_pep621 = PEP621(name="Ya", version="1.0") diff --git a/cppython/schema.py b/cppython/schema.py index 5fe771e..3e8e28a 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -7,7 +7,7 @@ from pathlib import Path from typing import Any, Type -from pydantic import BaseModel, Field +from pydantic import BaseModel class TargetEnum(Enum): @@ -22,10 +22,11 @@ class TargetEnum(Enum): class PyProject(BaseModel): """ - TODO + The data required from a PyProject.toml """ data: dict[str, str] + path: Path class PEP621(BaseModel): From 52c2e27e70f55e9b30c1909cd1b4a17a05741171 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Feb 2022 14:08:49 -0500 Subject: [PATCH 20/55] Remove Unused --- cppython/plugins/interface/console.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index 0b687e4..59aceb8 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -2,9 +2,7 @@ TODO: """ -from mimetypes import init from pathlib import Path -from typing import Tuple import click import tomlkit From bee82417834feece2133e06b659f72f73d351b29 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Feb 2022 14:34:51 -0500 Subject: [PATCH 21/55] Removed Unused Tests --- tests/integration/test_cli.py | 8 -------- tests/integration/test_project.py | 8 -------- tests/unit/test_project.py | 15 --------------- 3 files changed, 31 deletions(-) delete mode 100644 tests/integration/test_cli.py delete mode 100644 tests/integration/test_project.py delete mode 100644 tests/unit/test_project.py diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py deleted file mode 100644 index 9ea95f0..0000000 --- a/tests/integration/test_cli.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -TODO: -""" - - -class TestCLI: - def test_something(self): - pass diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py deleted file mode 100644 index f7460fc..0000000 --- a/tests/integration/test_project.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -TODO: -""" - - -class TestProjects: - def test_correct_project(self, tmp_workspace): - pass diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py deleted file mode 100644 index 4158ef3..0000000 --- a/tests/unit/test_project.py +++ /dev/null @@ -1,15 +0,0 @@ -""" -TODO -""" -from cppython.project import Project - - -class TestProject: - """ - TODO - """ - - def test_something(self): - """ - TODO - """ From 506548e7a753134f5be6f0d61e462072fdd6c5ce Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 6 Feb 2022 15:16:45 -0500 Subject: [PATCH 22/55] Removed duplicated schema tests --- tests/unit/test_schema.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 tests/unit/test_schema.py diff --git a/tests/unit/test_schema.py b/tests/unit/test_schema.py deleted file mode 100644 index 288696a..0000000 --- a/tests/unit/test_schema.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -TODO: -""" -import pytest - -from cppython.plugins.test.data import ( - default_metadata, - default_pep621, - default_pyproject, -) - - -class TestSchema: - """ - TODO - """ - - @pytest.mark.parametrize("metadata", [default_metadata]) - def test_metadata(self, metadata): - """ - TODO - """ - - @pytest.mark.parametrize("pep621", [default_pep621]) - def test_pep621(self, pep621): - """ - TODO - """ - - @pytest.mark.parametrize("pyproject", [default_pyproject]) - def test_pyproject(self, pyproject): - """ - TODO - """ From f1cb0cef252229fd84e3b79470c72ec23503d565 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Mon, 7 Feb 2022 05:51:50 -0500 Subject: [PATCH 23/55] Update Chore --- pdm.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pdm.lock b/pdm.lock index 15488a4..070dacc 100644 --- a/pdm.lock +++ b/pdm.lock @@ -223,7 +223,7 @@ dependencies = [ [[package]] name = "setuptools" -version = "60.7.1" +version = "60.8.1" requires_python = ">=3.7" summary = "Easily download, build, install, upgrade, and uninstall Python packages" @@ -241,7 +241,7 @@ summary = "A lil' TOML parser" [[package]] name = "tomlkit" -version = "0.9.0" +version = "0.9.1" requires_python = ">=3.6,<4.0" summary = "Style preserving TOML library" @@ -512,9 +512,9 @@ content_hash = "sha256:899fefd00e486ed8301b187fd6050d9b60643b5c5f66fa19d57b2516c {file = "pytest_xdist-2.5.0-py3-none-any.whl", hash = "sha256:6fe5c74fec98906deb8f2d2b616b5c782022744978e7bd4695d39c8f42d0ce65"}, {file = "pytest-xdist-2.5.0.tar.gz", hash = "sha256:4580deca3ff04ddb2ac53eba39d76cb5dd5edeac050cb6fbc768b0dd712b4edf"}, ] -"setuptools 60.7.1" = [ - {file = "setuptools-60.7.1-py3-none-any.whl", hash = "sha256:c9097cbcdefe88a64da966a764f2d95feb1cfaff77cc304528a23cefe3359d9a"}, - {file = "setuptools-60.7.1.tar.gz", hash = "sha256:a4dc3af29a67e7a45620aba43dde2c1af2dd6bc49726d78168f0cc6c4fb0c01b"}, +"setuptools 60.8.1" = [ + {file = "setuptools-60.8.1-py3-none-any.whl", hash = "sha256:07e97e2f1e5607d240454e98c75c7004560ac8417ca5ae1dbaa50811cb6cc95c"}, + {file = "setuptools-60.8.1.tar.gz", hash = "sha256:23aad87cc27f4ae704079618c1d117a71bd43d41e355f0698c35f6b1c796d26c"}, ] "toml 0.10.2" = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, @@ -524,9 +524,9 @@ content_hash = "sha256:899fefd00e486ed8301b187fd6050d9b60643b5c5f66fa19d57b2516c {file = "tomli-2.0.0-py3-none-any.whl", hash = "sha256:b5bde28da1fed24b9bd1d4d2b8cba62300bfb4ec9a6187a957e8ddb9434c5224"}, {file = "tomli-2.0.0.tar.gz", hash = "sha256:c292c34f58502a1eb2bbb9f5bbc9a5ebc37bee10ffb8c2d6bbdfa8eb13cc14e1"}, ] -"tomlkit 0.9.0" = [ - {file = "tomlkit-0.9.0-py3-none-any.whl", hash = "sha256:c1b0fc73abd4f1e77c29ea4061ca0f2e11cbfb77342e17df3d3fdd496fc3f899"}, - {file = "tomlkit-0.9.0.tar.gz", hash = "sha256:5a83672c565f78f5fc8f1e44e5f2726446cc6b765113efd21d03e9331747d9ab"}, +"tomlkit 0.9.1" = [ + {file = "tomlkit-0.9.1-py3-none-any.whl", hash = "sha256:01407892165b513969231085a33d4be2cb41f186d9fd072c975b6bd1435371b0"}, + {file = "tomlkit-0.9.1.tar.gz", hash = "sha256:3bdbfffc3ae6c8628b5fb6ed7b459edb8476472eae15033b705bc7d1380b3e3d"}, ] "typing-extensions 4.0.1" = [ {file = "typing_extensions-4.0.1-py3-none-any.whl", hash = "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"}, From 890aab164d03f77c278d707dd65cc866de96aed0 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Mon, 7 Feb 2022 08:09:27 -0500 Subject: [PATCH 24/55] Plugin Tests + Remove MP Tests --- cppython/plugins/generator/cmake.py | 3 --- pyproject.toml | 10 ++++++++-- tests/data/__init__.py | 1 + tests/integration/test_plugin.py | 27 +++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 tests/data/__init__.py create mode 100644 tests/integration/test_plugin.py diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index 40c1378..009a23d 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -1,7 +1,6 @@ """ TODO: """ -from pathlib import Path from typing import Type from cppython.schema import PEP621, Generator, GeneratorData, Metadata @@ -12,8 +11,6 @@ class CMakeData(GeneratorData): TODO: """ - pass - class CMakeGenerator(Generator): """ diff --git a/pyproject.toml b/pyproject.toml index 642b438..4eec2d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,12 +43,18 @@ test = [ [project.scripts] cppython = "cppython.plugins.interface.console:cli" -# Register the testing information with pytest +# CPPython plugins +[project.entry-points.cppython.generator] +cmake = "cppython.plugins.generator:CMakeGenerator" + +[project.entry-points.cppython.interface] +console = "cppython.plugins.interface:ConsoleInterface" + +# Pytest plugins [tool.entry-points.pytest11] pytest_cppython = "cppython.plugins.test.pytest" [tool.pytest.ini_options] -addopts = "-n auto" testpaths = [ "tests", ] diff --git a/tests/data/__init__.py b/tests/data/__init__.py new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/tests/data/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/integration/test_plugin.py b/tests/integration/test_plugin.py new file mode 100644 index 0000000..a4b8331 --- /dev/null +++ b/tests/integration/test_plugin.py @@ -0,0 +1,27 @@ +""" +TODO: +""" + +from importlib import metadata + + +class TestPlugin: + """ + TODO + """ + + def test_generator(self): + """ + TODO + """ + entries = metadata.entry_points() + plugin_entries = entries["cppython.generator"] + assert len(plugin_entries) > 1 + + def test_interface(self): + """ + TODO + """ + entries = metadata.entry_points() + plugin_entries = entries["cppython.interface"] + assert len(plugin_entries) > 1 From 9f1e7d1ad693a77904f23f0a2d6017bc88d1c2d3 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Mon, 7 Feb 2022 08:10:20 -0500 Subject: [PATCH 25/55] Remove x-dist --- pdm.lock | 41 +---------------------------------------- pyproject.toml | 1 - 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/pdm.lock b/pdm.lock index 070dacc..f4eecab 100644 --- a/pdm.lock +++ b/pdm.lock @@ -71,12 +71,6 @@ dependencies = [ "tomli", ] -[[package]] -name = "execnet" -version = "1.9.0" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" -summary = "execnet: rapid multi-Python deployment" - [[package]] name = "iniconfig" version = "1.1.1" @@ -191,16 +185,6 @@ dependencies = [ "pytest>=4.6", ] -[[package]] -name = "pytest-forked" -version = "1.4.0" -requires_python = ">=3.6" -summary = "run tests in isolated forked subprocesses" -dependencies = [ - "py", - "pytest>=3.10", -] - [[package]] name = "pytest-mock" version = "3.7.0" @@ -210,17 +194,6 @@ dependencies = [ "pytest>=5.0", ] -[[package]] -name = "pytest-xdist" -version = "2.5.0" -requires_python = ">=3.6" -summary = "pytest xdist plugin for distributed testing and loop-on-failing modes" -dependencies = [ - "execnet>=1.1", - "pytest-forked", - "pytest>=6.2.0", -] - [[package]] name = "setuptools" version = "60.8.1" @@ -259,7 +232,7 @@ summary = "Module for decorators, wrappers and monkey patching." [metadata] lock_version = "3.1" -content_hash = "sha256:899fefd00e486ed8301b187fd6050d9b60643b5c5f66fa19d57b2516c42d1216" +content_hash = "sha256:f18a6d6ee6b08697dc4b4ab33ecb41cf6cfe597cbf60877d816cb884f7544cfc" [metadata.files] "astroid 2.9.3" = [ @@ -368,10 +341,6 @@ content_hash = "sha256:899fefd00e486ed8301b187fd6050d9b60643b5c5f66fa19d57b2516c {file = "coverage-6.3.1-pp36.pp37.pp38-none-any.whl", hash = "sha256:463e52616ea687fd323888e86bf25e864a3cc6335a043fad6bbb037dbf49bbe2"}, {file = "coverage-6.3.1.tar.gz", hash = "sha256:6c3f6158b02ac403868eea390930ae64e9a9a2a5bbfafefbb920d29258d9f2f8"}, ] -"execnet 1.9.0" = [ - {file = "execnet-1.9.0-py2.py3-none-any.whl", hash = "sha256:a295f7cc774947aac58dde7fdc85f4aa00c42adf5d8f5468fc630c1acf30a142"}, - {file = "execnet-1.9.0.tar.gz", hash = "sha256:8f694f3ba9cc92cab508b152dcfe322153975c29bda272e2fd7f3f00f36e47c5"}, -] "iniconfig 1.1.1" = [ {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, @@ -500,18 +469,10 @@ content_hash = "sha256:899fefd00e486ed8301b187fd6050d9b60643b5c5f66fa19d57b2516c {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-forked 1.4.0" = [ - {file = "pytest_forked-1.4.0-py3-none-any.whl", hash = "sha256:bbbb6717efc886b9d64537b41fb1497cfaf3c9601276be8da2cccfea5a3c8ad8"}, - {file = "pytest-forked-1.4.0.tar.gz", hash = "sha256:8b67587c8f98cbbadfdd804539ed5455b6ed03802203485dd2f53c1422d7440e"}, -] "pytest-mock 3.7.0" = [ {file = "pytest_mock-3.7.0-py3-none-any.whl", hash = "sha256:6cff27cec936bf81dc5ee87f07132b807bcda51106b5ec4b90a04331cba76231"}, {file = "pytest-mock-3.7.0.tar.gz", hash = "sha256:5112bd92cc9f186ee96e1a92efc84969ea494939c3aead39c50f421c4cc69534"}, ] -"pytest-xdist 2.5.0" = [ - {file = "pytest_xdist-2.5.0-py3-none-any.whl", hash = "sha256:6fe5c74fec98906deb8f2d2b616b5c782022744978e7bd4695d39c8f42d0ce65"}, - {file = "pytest-xdist-2.5.0.tar.gz", hash = "sha256:4580deca3ff04ddb2ac53eba39d76cb5dd5edeac050cb6fbc768b0dd712b4edf"}, -] "setuptools 60.8.1" = [ {file = "setuptools-60.8.1-py3-none-any.whl", hash = "sha256:07e97e2f1e5607d240454e98c75c7004560ac8417ca5ae1dbaa50811cb6cc95c"}, {file = "setuptools-60.8.1.tar.gz", hash = "sha256:23aad87cc27f4ae704079618c1d117a71bd43d41e355f0698c35f6b1c796d26c"}, diff --git a/pyproject.toml b/pyproject.toml index 4eec2d4..5706420 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,6 @@ lint = [ test = [ "pytest-cov>=3.0.0", "pytest-mock>=3.7.0", - "pytest-xdist>=2.5.0", ] [project.scripts] From a7485b349c9dcfb08781bac0755710ec949828b3 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 8 Feb 2022 05:56:14 -0500 Subject: [PATCH 26/55] Proper Entry Points --- pyproject.toml | 8 ++++---- tests/integration/test_plugin.py | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5706420..6763d49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,11 +43,11 @@ test = [ cppython = "cppython.plugins.interface.console:cli" # CPPython plugins -[project.entry-points.cppython.generator] -cmake = "cppython.plugins.generator:CMakeGenerator" +[project.entry-points."cppython.generator_plugins"] +cmake = "cppython.plugins.generator.cmake:CMakeGenerator" -[project.entry-points.cppython.interface] -console = "cppython.plugins.interface:ConsoleInterface" +[project.entry-points."cppython.interface_plugins"] +console = "cppython.plugins.interface.console:ConsoleInterface" # Pytest plugins [tool.entry-points.pytest11] diff --git a/tests/integration/test_plugin.py b/tests/integration/test_plugin.py index a4b8331..627b939 100644 --- a/tests/integration/test_plugin.py +++ b/tests/integration/test_plugin.py @@ -2,7 +2,7 @@ TODO: """ -from importlib import metadata +from importlib.metadata import entry_points class TestPlugin: @@ -14,14 +14,12 @@ def test_generator(self): """ TODO """ - entries = metadata.entry_points() - plugin_entries = entries["cppython.generator"] - assert len(plugin_entries) > 1 + plugin_entries = entry_points(group="cppython.generator_plugins") + assert len(plugin_entries) > 0 def test_interface(self): """ TODO """ - entries = metadata.entry_points() - plugin_entries = entries["cppython.interface"] - assert len(plugin_entries) > 1 + plugin_entries = entry_points(group="cppython.interface_plugins") + assert len(plugin_entries) > 0 From 7699b2ef11490fd0c7d0313f7afe6807ea6c14f7 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 8 Feb 2022 17:57:20 -0500 Subject: [PATCH 27/55] Remove Interface Plugin + Update Chore --- cppython/project.py | 28 ++++++++++++---------------- cppython/schema.py | 23 +++++++++++++++++++---- pdm.lock | 16 ++++++++-------- tests/integration/test_plugin.py | 7 ------- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/cppython/project.py b/cppython/project.py index 3a7c326..4a4c172 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -1,6 +1,7 @@ import importlib import inspect import pkgutil +from importlib.metadata import entry_points from typing import Callable, Optional, Type, TypeVar import cppython.plugins.generator @@ -21,13 +22,13 @@ def __init__(self, interface: Interface) -> None: self._interface = interface self.loaded = False - def _parse_pep621_data(self, data: dict, interface_type: Interface) -> PEP621: + def _parse_pep621_data(self, data: dict, interface: Interface) -> PEP621: """ Extracts the PEP621 metadata from the various possible project formats """ # Each plugin reads its own configuration file, interfaces without external data need a helping hand parsing it - if not interface_type.external_config(): + if not interface.external_config(): # If the interface doesn't support an external configuration, search for a plugin that does temporary_interface_type = self._load_interface([*data["tool"]]) @@ -63,22 +64,17 @@ def _find_first_plugin( """ Finds the first plugin that satisfies the given condition """ - for _, name, is_package in pkgutil.iter_modules(namespace_package.__path__, namespace_package.__name__ + "."): - if not is_package: - module = importlib.import_module(name) - class_members = inspect.getmembers(module, inspect.isclass) - for (_, value) in class_members: - if issubclass(value, plugin_type) & (value is not plugin_type): - if condition(value.name()): - return value - return None - def _load_interface(self, potential_keys: list) -> Optional[Type[Interface]]: - """ - TODO: - """ + plugins = entry_points(group=f"cppython.{plugin_type.plugin_group()}") - return self._find_first_plugin(cppython.plugins.interface, Interface, lambda name: name in potential_keys) + plugins[""].load() + + for (_, value) in class_members: + if issubclass(value, plugin_type) & (value is not plugin_type): + if condition(value.name()): + return value + + return None def _load_generator(self, generator: str) -> Optional[Type[Generator]]: """ diff --git a/cppython/schema.py b/cppython/schema.py index 3e8e28a..d72abed 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -100,16 +100,16 @@ def __init__(self) -> None: @staticmethod @abstractmethod - def name() -> str: + def plugin_group() -> str: """ - The name of the generator + TODO """ raise NotImplementedError() -class Interface(Plugin): +class Interface: """ - Abstract type to be inherited by CPPython Interface plugins + Abstract type to be inherited by CPPython interfaces """ @abstractmethod @@ -173,6 +173,21 @@ class Generator(Plugin, API): def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: GeneratorData) -> None: super().__init__() + @staticmethod + def plugin_group() -> str: + """ + TODO + """ + return "generator_plugins" + + @staticmethod + @abstractmethod + def name() -> str: + """ + TODO + """ + raise NotImplementedError() + @abstractmethod def install_generator(self) -> bool: """ diff --git a/pdm.lock b/pdm.lock index f4eecab..4a80921 100644 --- a/pdm.lock +++ b/pdm.lock @@ -208,13 +208,13 @@ summary = "Python Library for Tom's Obvious, Minimal Language" [[package]] name = "tomli" -version = "2.0.0" +version = "2.0.1" requires_python = ">=3.7" summary = "A lil' TOML parser" [[package]] name = "tomlkit" -version = "0.9.1" +version = "0.9.2" requires_python = ">=3.6,<4.0" summary = "Style preserving TOML library" @@ -481,13 +481,13 @@ content_hash = "sha256:f18a6d6ee6b08697dc4b4ab33ecb41cf6cfe597cbf60877d816cb884f {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, ] -"tomli 2.0.0" = [ - {file = "tomli-2.0.0-py3-none-any.whl", hash = "sha256:b5bde28da1fed24b9bd1d4d2b8cba62300bfb4ec9a6187a957e8ddb9434c5224"}, - {file = "tomli-2.0.0.tar.gz", hash = "sha256:c292c34f58502a1eb2bbb9f5bbc9a5ebc37bee10ffb8c2d6bbdfa8eb13cc14e1"}, +"tomli 2.0.1" = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] -"tomlkit 0.9.1" = [ - {file = "tomlkit-0.9.1-py3-none-any.whl", hash = "sha256:01407892165b513969231085a33d4be2cb41f186d9fd072c975b6bd1435371b0"}, - {file = "tomlkit-0.9.1.tar.gz", hash = "sha256:3bdbfffc3ae6c8628b5fb6ed7b459edb8476472eae15033b705bc7d1380b3e3d"}, +"tomlkit 0.9.2" = [ + {file = "tomlkit-0.9.2-py3-none-any.whl", hash = "sha256:daf4f9c5f2fbf6b861d6adfc51940b98dee36c13e1d88749a6dc9fb280fff304"}, + {file = "tomlkit-0.9.2.tar.gz", hash = "sha256:ebd982d61446af95a1e082b103e250cb9e6d152eae2581d4a07d31a70b34ab0f"}, ] "typing-extensions 4.0.1" = [ {file = "typing_extensions-4.0.1-py3-none-any.whl", hash = "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"}, diff --git a/tests/integration/test_plugin.py b/tests/integration/test_plugin.py index 627b939..038a984 100644 --- a/tests/integration/test_plugin.py +++ b/tests/integration/test_plugin.py @@ -16,10 +16,3 @@ def test_generator(self): """ plugin_entries = entry_points(group="cppython.generator_plugins") assert len(plugin_entries) > 0 - - def test_interface(self): - """ - TODO - """ - plugin_entries = entry_points(group="cppython.interface_plugins") - assert len(plugin_entries) > 0 From 3d36713c65a3bfb1da183e4c9bda79c41082bba5 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 9 Feb 2022 10:10:02 -0500 Subject: [PATCH 28/55] Strip Project to Essentials --- cppython/project.py | 105 +++++++++----------------------------------- cppython/schema.py | 54 +++++++---------------- 2 files changed, 37 insertions(+), 122 deletions(-) diff --git a/cppython/project.py b/cppython/project.py index 4a4c172..8f5c2e5 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -1,13 +1,8 @@ -import importlib -import inspect -import pkgutil -from importlib.metadata import entry_points +from importlib import metadata from typing import Callable, Optional, Type, TypeVar -import cppython.plugins.generator -import cppython.plugins.interface from cppython.exceptions import ConfigError -from cppython.schema import API, PEP621, Generator, Interface, Metadata, Plugin +from cppython.schema import API, PEP621, CPPythonData, Generator, Interface, Plugin class Project(API): @@ -20,91 +15,33 @@ class Project(API): def __init__(self, interface: Interface) -> None: self._interface = interface - self.loaded = False + self._pep621 = interface.pep_621() + self._cppython_data = interface.cppython_data() - def _parse_pep621_data(self, data: dict, interface: Interface) -> PEP621: - """ - Extracts the PEP621 metadata from the various possible project formats - """ + _PluginType = TypeVar("_PluginType", bound=Type[Plugin]) - # Each plugin reads its own configuration file, interfaces without external data need a helping hand parsing it - if not interface.external_config(): - # If the interface doesn't support an external configuration, search for a plugin that does + def find_plugin_type(plugin_type: _PluginType, condition: Callable[[str], bool]) -> Optional[_PluginType]: + """ + Finds the first plugin that satisfies the given condition + """ - temporary_interface_type = self._load_interface([*data["tool"]]) + entry_points = metadata.entry_points(group=f"cppython.{plugin_type.plugin_group()}") - if temporary_interface_type is None: - # If there is no applicable plugin, we are interfaceing the toml project without a python buildsystem + for entry_point in entry_points: + loaded_plugin_type = entry_point.load() + if issubclass(loaded_plugin_type, plugin_type) & (loaded_plugin_type is not plugin_type): + if condition(loaded_plugin_type.name()): + return loaded_plugin_type - return self._interface.pep_621() + return None - return temporary_interface_type.parse_pep_621(data) + plugin_type = find_plugin_type(Generator, lambda name: name == self._cppython_data.generator) - else: - return self._interface.pep_621() + if plugin_type is None: + raise Exception(f"No generator plugin with the name '{self._cppython_data.generator}' was found.") - def _parse_cppython_data(self, data: dict) -> Metadata: - """ - TODO: - """ - return Metadata(**data["tool"]["cppython"]) - - def _parse_generator_data(self, data: dict, generator_type): - """ - TODO: - """ - generator_config_type = generator_type.data_type() - return generator_config_type(**data[generator_type.name()]) - - _PluginType = TypeVar("_PluginType", bound=Type[Plugin]) - - def _find_first_plugin( - self, namespace_package, plugin_type: _PluginType, condition: Callable[[str], bool] - ) -> Optional[_PluginType]: - """ - Finds the first plugin that satisfies the given condition - """ - - plugins = entry_points(group=f"cppython.{plugin_type.plugin_group()}") - - plugins[""].load() - - for (_, value) in class_members: - if issubclass(value, plugin_type) & (value is not plugin_type): - if condition(value.name()): - return value - - return None - - def _load_generator(self, generator: str) -> Optional[Type[Generator]]: - """ - TODO: - """ - - return self._find_first_plugin(cppython.plugins.generator, Generator, lambda name: name == generator) - - def load(self): - """ - TODO - """ - - # Read the raw configuration data - pyproject_data = self._interface.read_pyproject() - cppython_data = self._parse_cppython_data(pyproject_data) - - # Load the generator type - generator_type = self._load_generator(cppython_data.generator) - - if generator_type is None: - raise ConfigError("") - - pep_621 = self._parse_pep621_data(pyproject_data, self._interface) - generator_data = self._parse_generator_data(pyproject_data, generator_type) - - # Construct the generator - self._generator = generator_type(pep_621, cppython_data, generator_data) - - self.loaded = True + self._generator_data = interface.generator_data(plugin_type) + self._generator = plugin_type(self._pep621, self._cppython_data, self._generator_data) # API Contract diff --git a/cppython/schema.py b/cppython/schema.py index d72abed..b9de743 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -20,15 +20,6 @@ class TargetEnum(Enum): SHARED = "shared" -class PyProject(BaseModel): - """ - The data required from a PyProject.toml - """ - - data: dict[str, str] - path: Path - - class PEP621(BaseModel): """ Subset of PEP 621 @@ -41,13 +32,12 @@ class PEP621(BaseModel): description: str = "" -class Metadata(BaseModel): +class CPPythonData(BaseModel): """ Data required by the tool """ - # TODO: Grab default from plugin without circular import - generator: str = "CMake" + generator: str target: TargetEnum dependencies: dict[str, str] = {} install_path: Path @@ -107,6 +97,12 @@ def plugin_group() -> str: raise NotImplementedError() +class GeneratorData(BaseModel): + """ + Base class for the configuration data that will be given to the generator constructor + """ + + class Interface: """ Abstract type to be inherited by CPPython interfaces @@ -117,60 +113,42 @@ def __init__(self, pyproject: PyProject) -> None: super().__init__() self._pyproject = pyproject - @staticmethod - def external_config() -> bool: - """ - True if the plugin can read its own configuration. - False otherwise - """ - - return True - - @staticmethod @abstractmethod - def parse_pep_621(data: dict[str, Any]) -> PEP621: + def pep_621(self) -> PEP621: """ - Requests the plugin to read the available PEP 621 information. Only requested - if the plugin is not the entrypoint + Requests PEP 621 information """ raise NotImplementedError() @abstractmethod - def pep_621(self) -> PEP621: + def cppython_data(self) -> CPPythonData: """ - Requests PEP 621 information from the pyproject - Probably uses 'parse_pep_621' internally + Requests CPPython information """ raise NotImplementedError() @abstractmethod - def read_pyproject(self) -> dict[str, Any]: + def generator_data(self, generator_data: Type[GeneratorData]) -> GeneratorData: """ - Called when CPPoetry requires the content of pyproject.toml + Requests generator information """ raise NotImplementedError() @abstractmethod def write_pyproject(self) -> None: """ - Called when CPPoetry requires the plugin to write out pyproject.toml changes + Called when CPPython requires the plugin to write out pyproject.toml changes """ raise NotImplementedError() -class GeneratorData(BaseModel): - """ - Base class for the configuration data that will be given to the generator constructor - """ - - class Generator(Plugin, API): """ Abstract type to be inherited by CPPython Generator plugins """ @abstractmethod - def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: GeneratorData) -> None: + def __init__(self, pep_612: PEP621, cppython_data: CPPythonData, generator_data: GeneratorData) -> None: super().__init__() @staticmethod From 891d5df0641600550404a07ed0e4f756230290ba Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 9 Feb 2022 12:56:52 -0500 Subject: [PATCH 29/55] Type Cleanup --- cppython/plugins/interface/console.py | 23 ++++++----------------- cppython/plugins/test/data.py | 6 ++---- cppython/schema.py | 3 +-- tests/unit/test_generator.py | 4 ++-- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index 59aceb8..f7739e7 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -9,7 +9,7 @@ from tomlkit.api import TOMLDocument from cppython.project import Project -from cppython.schema import PEP621, Interface, PyProject +from cppython.schema import PEP621, Interface def _path_search() -> Path: @@ -45,20 +45,12 @@ def __init__(self): path = _path_search() data = _read_data(path) - pyproject = PyProject(data=data, path=path) - # Initialize the object hook into CPPython - interface = ConsoleInterface(pyproject) + interface = ConsoleInterface() # Initialize the CPPython context self.project = Project(interface) - def load(self): - """ - TODO - """ - self.project.load() - pass_config = click.make_pass_decorator(Config) @@ -106,8 +98,8 @@ class ConsoleInterface(Interface): TODO: Description """ - def __init__(self, pyproject: PyProject) -> None: - super().__init__(pyproject) + def __init__(self) -> None: + super().__init__() # Plugin Contract @@ -130,7 +122,7 @@ def external_config() -> bool: return False @staticmethod - def parse_pep_621(data: PyProject) -> PEP621: + def parse_pep_621() -> PEP621: """ Requests the plugin to read the available PEP 621 information. Only requested if the plugin is not the entrypoint """ @@ -140,10 +132,7 @@ def pep_621(self) -> PEP621: """ Requests PEP 621 information from the pyproject """ - return self.parse_pep_621(self._pyproject) + return self.parse_pep_621() def write_pyproject(self) -> None: raise NotImplementedError() - - def read_pyproject(self) -> PyProject: - return self._pyproject diff --git a/cppython/plugins/test/data.py b/cppython/plugins/test/data.py index a769fb5..075927c 100644 --- a/cppython/plugins/test/data.py +++ b/cppython/plugins/test/data.py @@ -4,10 +4,8 @@ from pathlib import Path -from cppython.schema import PEP621, Metadata, PyProject, TargetEnum - -default_pyproject = PyProject(data={}, path=Path()) +from cppython.schema import PEP621, CPPythonData, TargetEnum default_pep621 = PEP621(name="Ya", version="1.0") -default_metadata = Metadata(target=TargetEnum.EXE, install_path=Path()) +default_cppython_data = CPPythonData(generator="cmake", target=TargetEnum.EXE, install_path=Path()) diff --git a/cppython/schema.py b/cppython/schema.py index b9de743..f158c7b 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -109,9 +109,8 @@ class Interface: """ @abstractmethod - def __init__(self, pyproject: PyProject) -> None: + def __init__(self) -> None: super().__init__() - self._pyproject = pyproject @abstractmethod def pep_621(self) -> PEP621: diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index 3897bcf..307157e 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -5,7 +5,7 @@ import pytest from cppython.plugins.generator.cmake import CMakeData, CMakeGenerator -from cppython.plugins.test.data import default_metadata, default_pep621 +from cppython.plugins.test.data import default_cppython_data, default_pep621 from cppython.plugins.test.pytest import BaseGeneratorSuite @@ -17,4 +17,4 @@ class TestCMakeGenerator(BaseGeneratorSuite): @pytest.fixture(name="generator") def fixture_generator(self): cmake_data = CMakeData() - return CMakeGenerator(default_pep621, default_metadata, cmake_data) + return CMakeGenerator(default_pep621, default_cppython_data, cmake_data) From 2f4b1093d4f0dbad1366cf5d40841ada8db0ec89 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 9 Feb 2022 16:18:28 -0500 Subject: [PATCH 30/55] Data --- cppython/plugins/generator/cmake.py | 4 ++-- tests/unit/test_interface.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index 009a23d..d470182 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -3,7 +3,7 @@ """ from typing import Type -from cppython.schema import PEP621, Generator, GeneratorData, Metadata +from cppython.schema import PEP621, CPPythonData, Generator, GeneratorData class CMakeData(GeneratorData): @@ -17,7 +17,7 @@ class CMakeGenerator(Generator): A CPPython generator implementing a CMake backend """ - def __init__(self, pep_612: PEP621, cppython_data: Metadata, generator_data: CMakeData) -> None: + def __init__(self, pep_612: PEP621, cppython_data: CPPythonData, generator_data: CMakeData) -> None: super().__init__(pep_612, cppython_data, generator_data) # Plugin Contract diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index babf413..1ed533c 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -7,7 +7,6 @@ from pytest_mock.plugin import MockerFixture from cppython.plugins.interface.console import Config, ConsoleInterface, cli -from cppython.plugins.test.data import default_pyproject from cppython.plugins.test.pytest import BaseInterfaceSuite @@ -18,7 +17,7 @@ class TestCLIInterface(BaseInterfaceSuite): @pytest.fixture(name="interface") def fixture_interface(self): - return ConsoleInterface(default_pyproject) + return ConsoleInterface() @pytest.mark.parametrize("command", ["install", "update"]) def test_command(self, command: str, mocker: MockerFixture): From 3ec54983d34ba856b5daf6ae63af1b007f4c0a3e Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 9 Feb 2022 18:07:07 -0500 Subject: [PATCH 31/55] Update Plugin Test --- cppython/plugins/test/pytest.py | 13 +++++-------- cppython/project.py | 6 +++--- tests/integration/__init__.py | 1 - tests/integration/test_plugin.py | 18 ------------------ 4 files changed, 8 insertions(+), 30 deletions(-) delete mode 100644 tests/integration/__init__.py delete mode 100644 tests/integration/test_plugin.py diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index 76d31c8..3917834 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -2,6 +2,7 @@ TODO: """ from abc import ABC +from importlib.metadata import entry_points import pytest @@ -22,11 +23,12 @@ def fixture_generator(self) -> Generator: """ raise NotImplementedError - def test_construction(self, generator: Generator): + def test_plugin_registration(self, generator: Generator): """ - Test the __init__ call of the generator object + TODO """ - pass + plugin_entries = entry_points(group=f"cppython.{generator.plugin_group()}") + assert len(plugin_entries) > 0 class BaseInterfaceSuite(ABC): @@ -42,8 +44,3 @@ def fixture_interface(self) -> Interface: @pytest.mark.parametrize("interface", [CustomInterface]) """ raise NotImplementedError - - def test_construction(self, interface: Interface): - """ - Test the __init__ call of the interface object - """ diff --git a/cppython/project.py b/cppython/project.py index 8f5c2e5..1b57bbc 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -2,7 +2,7 @@ from typing import Callable, Optional, Type, TypeVar from cppython.exceptions import ConfigError -from cppython.schema import API, PEP621, CPPythonData, Generator, Interface, Plugin +from cppython.schema import API, Generator, Interface, Plugin class Project(API): @@ -38,9 +38,9 @@ def find_plugin_type(plugin_type: _PluginType, condition: Callable[[str], bool]) plugin_type = find_plugin_type(Generator, lambda name: name == self._cppython_data.generator) if plugin_type is None: - raise Exception(f"No generator plugin with the name '{self._cppython_data.generator}' was found.") + raise ConfigError(f"No generator plugin with the name '{self._cppython_data.generator}' was found.") - self._generator_data = interface.generator_data(plugin_type) + self._generator_data = interface.generator_data(plugin_type.data_type()) self._generator = plugin_type(self._pep621, self._cppython_data, self._generator_data) # API Contract diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py deleted file mode 100644 index 5f28270..0000000 --- a/tests/integration/__init__.py +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/integration/test_plugin.py b/tests/integration/test_plugin.py deleted file mode 100644 index 038a984..0000000 --- a/tests/integration/test_plugin.py +++ /dev/null @@ -1,18 +0,0 @@ -""" -TODO: -""" - -from importlib.metadata import entry_points - - -class TestPlugin: - """ - TODO - """ - - def test_generator(self): - """ - TODO - """ - plugin_entries = entry_points(group="cppython.generator_plugins") - assert len(plugin_entries) > 0 From 19ceac5a34a06f4feecf6eb91d6aa5c57e7caedf Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 9 Feb 2022 18:27:45 -0500 Subject: [PATCH 32/55] Tests --- cppython/plugins/interface/console.py | 3 --- tests/unit/test_interface.py | 7 ++----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index f7739e7..744cd56 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -63,9 +63,6 @@ def cli(context): """ context.ensure_object(Config) - # Initialize cppython - context.obj.load() - @cli.command() @pass_config diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 1ed533c..cf71926 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -29,11 +29,8 @@ def test_command(self, command: str, mocker: MockerFixture): command {str} -- [description] mocker {[type]} -- [description] """ - # Patch the project - mocker.patch("cppython.plugins.interface.console.Config.load") - - # Patch the file IO - mocker.patch("cppython.plugins.interface.console._read_data") + # Patch the project initialization + mocker.patch("cppython.project.Project.__init__", return_value=None) config = Config() From 1491bd2e37dbc7d459b1e1f9cbfdd709ec81106d Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 10 Feb 2022 05:59:29 -0500 Subject: [PATCH 33/55] Integration Tests --- cppython/plugins/test/pytest.py | 43 +++++++++++++++++++++++++---- tests/integration/__init__.py | 1 + tests/integration/test_generator.py | 20 ++++++++++++++ tests/integration/test_interface.py | 18 ++++++++++++ tests/unit/test_generator.py | 4 +-- tests/unit/test_interface.py | 4 +-- 6 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 tests/integration/__init__.py create mode 100644 tests/integration/test_generator.py create mode 100644 tests/integration/test_interface.py diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index 3917834..c06653f 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -6,13 +6,13 @@ import pytest +from cppython.project import Project from cppython.schema import Generator, Interface -class BaseGeneratorSuite(ABC): +class GeneratorTests(ABC): """ - Custom implementations of the Generator class should inherit from this class for its tests. - This class provides a generic test suite that all custom types must function with. + TODO """ @pytest.fixture(name="generator") @@ -23,6 +23,19 @@ def fixture_generator(self) -> Generator: """ raise NotImplementedError + +class GeneratorIntegrationTests(GeneratorTests): + """ + TODO + """ + + +class GeneratorUnitTests(GeneratorTests): + """ + Custom implementations of the Generator class should inherit from this class for its tests. + This class provides a generic test suite that all custom types must function with. + """ + def test_plugin_registration(self, generator: Generator): """ TODO @@ -31,10 +44,9 @@ def test_plugin_registration(self, generator: Generator): assert len(plugin_entries) > 0 -class BaseInterfaceSuite(ABC): +class InterfaceTests(ABC): """ - Custom implementations of the Interface class should inherit from this class for its tests. - This class provides a generic test suite that all custom types must function with. + TODO """ @pytest.fixture(name="interface") @@ -44,3 +56,22 @@ def fixture_interface(self) -> Interface: @pytest.mark.parametrize("interface", [CustomInterface]) """ raise NotImplementedError + + +class InterfaceIntegrationTests(InterfaceTests): + """ + TODO + """ + + def test_project(self, interface: Interface): + """ + TODO + """ + Project(interface) + + +class InterfaceUnitTests(InterfaceTests): + """ + Custom implementations of the Interface class should inherit from this class for its tests. + This class provides a generic test suite that all custom types must function with. + """ diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/tests/integration/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/integration/test_generator.py b/tests/integration/test_generator.py new file mode 100644 index 0000000..2160612 --- /dev/null +++ b/tests/integration/test_generator.py @@ -0,0 +1,20 @@ +""" +TODO: +""" + +import pytest + +from cppython.plugins.generator.cmake import CMakeData, CMakeGenerator +from cppython.plugins.test.data import default_cppython_data, default_pep621 +from cppython.plugins.test.pytest import GeneratorIntegrationTests + + +class TestCMakeGenerator(GeneratorIntegrationTests): + """ + The tests for our CMake generator + """ + + @pytest.fixture(name="generator") + def fixture_generator(self): + cmake_data = CMakeData() + return CMakeGenerator(default_pep621, default_cppython_data, cmake_data) diff --git a/tests/integration/test_interface.py b/tests/integration/test_interface.py new file mode 100644 index 0000000..a735846 --- /dev/null +++ b/tests/integration/test_interface.py @@ -0,0 +1,18 @@ +""" +TODO: +""" + +import pytest + +from cppython.plugins.interface.console import ConsoleInterface +from cppython.plugins.test.pytest import InterfaceIntegrationTests + + +class TestCLIInterface(InterfaceIntegrationTests): + """ + The tests for our CLI interface + """ + + @pytest.fixture(name="interface") + def fixture_interface(self): + return ConsoleInterface() diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index 307157e..c67e556 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -6,10 +6,10 @@ from cppython.plugins.generator.cmake import CMakeData, CMakeGenerator from cppython.plugins.test.data import default_cppython_data, default_pep621 -from cppython.plugins.test.pytest import BaseGeneratorSuite +from cppython.plugins.test.pytest import GeneratorUnitTests -class TestCMakeGenerator(BaseGeneratorSuite): +class TestCMakeGenerator(GeneratorUnitTests): """ The tests for our CMake generator """ diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index cf71926..ef685a3 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -7,10 +7,10 @@ from pytest_mock.plugin import MockerFixture from cppython.plugins.interface.console import Config, ConsoleInterface, cli -from cppython.plugins.test.pytest import BaseInterfaceSuite +from cppython.plugins.test.pytest import InterfaceUnitTests -class TestCLIInterface(BaseInterfaceSuite): +class TestCLIInterface(InterfaceUnitTests): """ The tests for our CLI interface """ From ef0790290becacf7c70cd4d1287fb4719f62f081 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 10 Feb 2022 07:59:30 -0500 Subject: [PATCH 34/55] Pydantic Types --- cppython/plugins/interface/console.py | 36 ++++++++------------ cppython/plugins/test/data.py | 6 ++-- cppython/plugins/test/pytest.py | 36 ++++++++++++++++++-- cppython/schema.py | 48 ++++++++++++++------------- tests/integration/test_interface.py | 3 +- 5 files changed, 78 insertions(+), 51 deletions(-) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index 744cd56..1a02258 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -3,13 +3,14 @@ """ from pathlib import Path +from typing import Any, Type import click import tomlkit from tomlkit.api import TOMLDocument from cppython.project import Project -from cppython.schema import PEP621, Interface +from cppython.schema import PEP621, CPPythonData, GeneratorData, Interface def _path_search() -> Path: @@ -95,41 +96,32 @@ class ConsoleInterface(Interface): TODO: Description """ - def __init__(self) -> None: + def __init__(self, data: dict) -> None: super().__init__() - # Plugin Contract - - @staticmethod - def name() -> str: - """ - The name of the generator - """ - return "console" + self.data = data # Interface Contract - @staticmethod - def external_config() -> bool: + @property + def pep_621(self) -> PEP621: """ - True if the plugin can read its own configuration. - False otherwise + Requests PEP 621 information from the pyproject """ + return PEP621(**self.data["project"]) - return False - - @staticmethod - def parse_pep_621() -> PEP621: + @property + def cppython_data(self) -> CPPythonData: """ - Requests the plugin to read the available PEP 621 information. Only requested if the plugin is not the entrypoint + Requests CPPython information """ raise NotImplementedError() - def pep_621(self) -> PEP621: + def generator_data(self, generator_data: Type[GeneratorData]) -> GeneratorData: """ - Requests PEP 621 information from the pyproject + Requests generator information """ - return self.parse_pep_621() + raise NotImplementedError() def write_pyproject(self) -> None: raise NotImplementedError() diff --git a/cppython/plugins/test/data.py b/cppython/plugins/test/data.py index 075927c..a1129e1 100644 --- a/cppython/plugins/test/data.py +++ b/cppython/plugins/test/data.py @@ -4,8 +4,10 @@ from pathlib import Path -from cppython.schema import PEP621, CPPythonData, TargetEnum +from cppython.schema import PEP621, CPPythonData, PyProject, TargetEnum -default_pep621 = PEP621(name="Ya", version="1.0") +default_pep621 = PEP621(name="test_name", version="1.0") default_cppython_data = CPPythonData(generator="cmake", target=TargetEnum.EXE, install_path=Path()) + +default_pyproject = PyProject() diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index c06653f..f08680b 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -29,6 +29,13 @@ class GeneratorIntegrationTests(GeneratorTests): TODO """ + def test_plugin_registration(self, generator: Generator): + """ + TODO + """ + plugin_entries = entry_points(group=f"cppython.{generator.plugin_group()}") + assert len(plugin_entries) > 0 + class GeneratorUnitTests(GeneratorTests): """ @@ -36,12 +43,21 @@ class GeneratorUnitTests(GeneratorTests): This class provides a generic test suite that all custom types must function with. """ - def test_plugin_registration(self, generator: Generator): + def test_name(self, generator: Generator): """ TODO """ - plugin_entries = entry_points(group=f"cppython.{generator.plugin_group()}") - assert len(plugin_entries) > 0 + name = generator.name() + + assert name != "" + + def test_data_type(self, generator: Generator): + """ + TODO + """ + data_type = generator.data_type() + + assert data_type != "" class InterfaceTests(ABC): @@ -75,3 +91,17 @@ class InterfaceUnitTests(InterfaceTests): Custom implementations of the Interface class should inherit from this class for its tests. This class provides a generic test suite that all custom types must function with. """ + + def test_pep612(self, interface: Interface): + """ + TODO + """ + + pep_621 = interface.pep_621 + + def test_cppython_data(self, interface: Interface): + """ + TODO + """ + + cppython_data = interface.cppython_data diff --git a/cppython/schema.py b/cppython/schema.py index f158c7b..9fa0244 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -43,6 +43,12 @@ class CPPythonData(BaseModel): install_path: Path +class PyProject(BaseModel): + """ + TODO + """ + + class API(ABC): """ API @@ -109,34 +115,30 @@ class Interface: """ @abstractmethod - def __init__(self) -> None: + def __init__(self, pyproject: PyProject) -> None: super().__init__() - @abstractmethod - def pep_621(self) -> PEP621: - """ - Requests PEP 621 information - """ - raise NotImplementedError() + self.pyproject = pyproject - @abstractmethod - def cppython_data(self) -> CPPythonData: + @property + def pyproject(self) -> PyProject: """ - Requests CPPython information + TODO """ - raise NotImplementedError() + return self._pyproject - @abstractmethod - def generator_data(self, generator_data: Type[GeneratorData]) -> GeneratorData: + @pyproject.setter + def pyproject(self, value: PyProject): """ - Requests generator information + TODO """ - raise NotImplementedError() + + self._pyproject = value @abstractmethod def write_pyproject(self) -> None: """ - Called when CPPython requires the plugin to write out pyproject.toml changes + Called when CPPython requires the interface to write out pyproject.toml changes """ raise NotImplementedError() @@ -165,13 +167,6 @@ def name() -> str: """ raise NotImplementedError() - @abstractmethod - def install_generator(self) -> bool: - """ - Installs the external tooling required by the generator if necessary - Returns whether anything was installed or not - """ - @staticmethod @abstractmethod def data_type() -> Type[GeneratorData]: @@ -179,3 +174,10 @@ def data_type() -> Type[GeneratorData]: Returns the pydantic type to cast the generator configuration data to """ raise NotImplementedError() + + @abstractmethod + def install_generator(self) -> bool: + """ + Installs the external tooling required by the generator if necessary + Returns whether anything was installed or not + """ diff --git a/tests/integration/test_interface.py b/tests/integration/test_interface.py index a735846..128c203 100644 --- a/tests/integration/test_interface.py +++ b/tests/integration/test_interface.py @@ -15,4 +15,5 @@ class TestCLIInterface(InterfaceIntegrationTests): @pytest.fixture(name="interface") def fixture_interface(self): - return ConsoleInterface() + + return ConsoleInterface(default_pyproject) From 5104c1d53c47b1f6ae4b84dd490b0da8a724e479 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Thu, 10 Feb 2022 19:12:25 -0500 Subject: [PATCH 35/55] Chores --- cppython/plugins/interface/console.py | 21 +-------------------- cppython/schema.py | 5 ----- pdm.lock | 16 ++++++++-------- tests/integration/test_interface.py | 1 + 4 files changed, 10 insertions(+), 33 deletions(-) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index 1a02258..6e6187c 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -10,7 +10,7 @@ from tomlkit.api import TOMLDocument from cppython.project import Project -from cppython.schema import PEP621, CPPythonData, GeneratorData, Interface +from cppython.schema import PEP621, CPPythonData, GeneratorData, Interface, PyProject def _path_search() -> Path: @@ -96,27 +96,8 @@ class ConsoleInterface(Interface): TODO: Description """ - def __init__(self, data: dict) -> None: - super().__init__() - - self.data = data - # Interface Contract - @property - def pep_621(self) -> PEP621: - """ - Requests PEP 621 information from the pyproject - """ - return PEP621(**self.data["project"]) - - @property - def cppython_data(self) -> CPPythonData: - """ - Requests CPPython information - """ - raise NotImplementedError() - def generator_data(self, generator_data: Type[GeneratorData]) -> GeneratorData: """ Requests generator information diff --git a/cppython/schema.py b/cppython/schema.py index 9fa0244..2838850 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -114,7 +114,6 @@ class Interface: Abstract type to be inherited by CPPython interfaces """ - @abstractmethod def __init__(self, pyproject: PyProject) -> None: super().__init__() @@ -148,10 +147,6 @@ class Generator(Plugin, API): Abstract type to be inherited by CPPython Generator plugins """ - @abstractmethod - def __init__(self, pep_612: PEP621, cppython_data: CPPythonData, generator_data: GeneratorData) -> None: - super().__init__() - @staticmethod def plugin_group() -> str: """ diff --git a/pdm.lock b/pdm.lock index 4a80921..11ffa14 100644 --- a/pdm.lock +++ b/pdm.lock @@ -114,7 +114,7 @@ summary = "Utility library for gitignore style pattern matching of file paths." [[package]] name = "platformdirs" -version = "2.4.1" +version = "2.5.0" requires_python = ">=3.7" summary = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." @@ -196,7 +196,7 @@ dependencies = [ [[package]] name = "setuptools" -version = "60.8.1" +version = "60.8.2" requires_python = ">=3.7" summary = "Easily download, build, install, upgrade, and uninstall Python packages" @@ -404,9 +404,9 @@ content_hash = "sha256:f18a6d6ee6b08697dc4b4ab33ecb41cf6cfe597cbf60877d816cb884f {file = "pathspec-0.9.0-py2.py3-none-any.whl", hash = "sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a"}, {file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"}, ] -"platformdirs 2.4.1" = [ - {file = "platformdirs-2.4.1-py3-none-any.whl", hash = "sha256:1d7385c7db91728b83efd0ca99a5afb296cab9d0ed8313a45ed8ba17967ecfca"}, - {file = "platformdirs-2.4.1.tar.gz", hash = "sha256:440633ddfebcc36264232365d7840a970e75e1018d15b4327d11f91909045fda"}, +"platformdirs 2.5.0" = [ + {file = "platformdirs-2.5.0-py3-none-any.whl", hash = "sha256:30671902352e97b1eafd74ade8e4a694782bd3471685e78c32d0fdfd3aa7e7bb"}, + {file = "platformdirs-2.5.0.tar.gz", hash = "sha256:8ec11dfba28ecc0715eb5fb0147a87b1bf325f349f3da9aab2cd6b50b96b692b"}, ] "pluggy 1.0.0" = [ {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, @@ -473,9 +473,9 @@ content_hash = "sha256:f18a6d6ee6b08697dc4b4ab33ecb41cf6cfe597cbf60877d816cb884f {file = "pytest_mock-3.7.0-py3-none-any.whl", hash = "sha256:6cff27cec936bf81dc5ee87f07132b807bcda51106b5ec4b90a04331cba76231"}, {file = "pytest-mock-3.7.0.tar.gz", hash = "sha256:5112bd92cc9f186ee96e1a92efc84969ea494939c3aead39c50f421c4cc69534"}, ] -"setuptools 60.8.1" = [ - {file = "setuptools-60.8.1-py3-none-any.whl", hash = "sha256:07e97e2f1e5607d240454e98c75c7004560ac8417ca5ae1dbaa50811cb6cc95c"}, - {file = "setuptools-60.8.1.tar.gz", hash = "sha256:23aad87cc27f4ae704079618c1d117a71bd43d41e355f0698c35f6b1c796d26c"}, +"setuptools 60.8.2" = [ + {file = "setuptools-60.8.2-py3-none-any.whl", hash = "sha256:43a5575eea6d3459789316e1596a3d2a0d215260cacf4189508112f35c9a145b"}, + {file = "setuptools-60.8.2.tar.gz", hash = "sha256:66b8598da112b8dc8cd941d54cf63ef91d3b50657b374457eda5851f3ff6a899"}, ] "toml 0.10.2" = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, diff --git a/tests/integration/test_interface.py b/tests/integration/test_interface.py index 128c203..abd89e9 100644 --- a/tests/integration/test_interface.py +++ b/tests/integration/test_interface.py @@ -5,6 +5,7 @@ import pytest from cppython.plugins.interface.console import ConsoleInterface +from cppython.plugins.test.data import default_pyproject from cppython.plugins.test.pytest import InterfaceIntegrationTests From b5733ac48e93711a8bba736246e5fc71e3636d89 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Fri, 11 Feb 2022 07:02:37 -0500 Subject: [PATCH 36/55] Type Cleanup --- cppython/plugins/generator/cmake.py | 24 +++++++++--------------- cppython/plugins/interface/console.py | 8 ++++---- cppython/project.py | 11 +++++------ cppython/schema.py | 9 ++++++++- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index d470182..9cd2871 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -3,7 +3,7 @@ """ from typing import Type -from cppython.schema import PEP621, CPPythonData, Generator, GeneratorData +from cppython.schema import Generator, GeneratorData, PyProject class CMakeData(GeneratorData): @@ -17,10 +17,8 @@ class CMakeGenerator(Generator): A CPPython generator implementing a CMake backend """ - def __init__(self, pep_612: PEP621, cppython_data: CPPythonData, generator_data: CMakeData) -> None: - super().__init__(pep_612, cppython_data, generator_data) - - # Plugin Contract + def __init__(self, pyproject: PyProject) -> None: + super().__init__(pyproject) @staticmethod def name() -> str: @@ -29,15 +27,6 @@ def name() -> str: """ return "cmake" - # Generator Contract - - def install_generator(self) -> bool: - """ - Installs the external tooling required by the generator if necessary - Returns whether anything was installed or not - """ - return False - @staticmethod def data_type() -> Type[GeneratorData]: """ @@ -45,7 +34,12 @@ def data_type() -> Type[GeneratorData]: """ return CMakeData - # API Contract + def install_generator(self) -> bool: + """ + 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 6e6187c..bdc14c2 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -10,7 +10,7 @@ from tomlkit.api import TOMLDocument from cppython.project import Project -from cppython.schema import PEP621, CPPythonData, GeneratorData, Interface, PyProject +from cppython.schema import GeneratorData, Interface, PyProject def _path_search() -> Path: @@ -46,8 +46,10 @@ def __init__(self): path = _path_search() data = _read_data(path) + pyproject = PyProject(**data) + # Initialize the object hook into CPPython - interface = ConsoleInterface() + interface = ConsoleInterface(pyproject) # Initialize the CPPython context self.project = Project(interface) @@ -96,8 +98,6 @@ class ConsoleInterface(Interface): TODO: Description """ - # Interface Contract - def generator_data(self, generator_data: Type[GeneratorData]) -> GeneratorData: """ Requests generator information diff --git a/cppython/project.py b/cppython/project.py index 1b57bbc..3e61a69 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -15,8 +15,6 @@ class Project(API): def __init__(self, interface: Interface) -> None: self._interface = interface - self._pep621 = interface.pep_621() - self._cppython_data = interface.cppython_data() _PluginType = TypeVar("_PluginType", bound=Type[Plugin]) @@ -35,13 +33,14 @@ def find_plugin_type(plugin_type: _PluginType, condition: Callable[[str], bool]) return None - plugin_type = find_plugin_type(Generator, lambda name: name == self._cppython_data.generator) + plugin_type = find_plugin_type(Generator, lambda name: name == interface.pyproject.cppython_data.generator) if plugin_type is None: - raise ConfigError(f"No generator plugin with the name '{self._cppython_data.generator}' was found.") + raise ConfigError( + f"No generator plugin with the name '{interface.pyproject.cppython_data.generator}' was found." + ) - self._generator_data = interface.generator_data(plugin_type.data_type()) - self._generator = plugin_type(self._pep621, self._cppython_data, self._generator_data) + self._generator = plugin_type(interface.pyproject) # API Contract diff --git a/cppython/schema.py b/cppython/schema.py index 2838850..3e02390 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod from enum import Enum from pathlib import Path -from typing import Any, Type +from typing import Type from pydantic import BaseModel @@ -48,6 +48,9 @@ class PyProject(BaseModel): TODO """ + pep_621: PEP621 + cppython_data: CPPythonData + class API(ABC): """ @@ -147,6 +150,10 @@ class Generator(Plugin, API): Abstract type to be inherited by CPPython Generator plugins """ + @abstractmethod + def __init__(self, pyproject: PyProject) -> None: + super().__init__() + @staticmethod def plugin_group() -> str: """ From a1dc39460c88e874d0406f812ab9ecb278bf9234 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Fri, 11 Feb 2022 07:20:19 -0500 Subject: [PATCH 37/55] Type Fixes --- cppython/plugins/test/data.py | 2 +- tests/integration/test_generator.py | 4 ++-- tests/unit/test_generator.py | 4 ++-- tests/unit/test_interface.py | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cppython/plugins/test/data.py b/cppython/plugins/test/data.py index a1129e1..9df1e88 100644 --- a/cppython/plugins/test/data.py +++ b/cppython/plugins/test/data.py @@ -10,4 +10,4 @@ default_cppython_data = CPPythonData(generator="cmake", target=TargetEnum.EXE, install_path=Path()) -default_pyproject = PyProject() +default_pyproject = PyProject(pep_621=default_pep621, cppython_data=default_cppython_data) diff --git a/tests/integration/test_generator.py b/tests/integration/test_generator.py index 2160612..d599bd2 100644 --- a/tests/integration/test_generator.py +++ b/tests/integration/test_generator.py @@ -5,7 +5,7 @@ import pytest from cppython.plugins.generator.cmake import CMakeData, CMakeGenerator -from cppython.plugins.test.data import default_cppython_data, default_pep621 +from cppython.plugins.test.data import default_pyproject from cppython.plugins.test.pytest import GeneratorIntegrationTests @@ -17,4 +17,4 @@ class TestCMakeGenerator(GeneratorIntegrationTests): @pytest.fixture(name="generator") def fixture_generator(self): cmake_data = CMakeData() - return CMakeGenerator(default_pep621, default_cppython_data, cmake_data) + return CMakeGenerator(default_pyproject) diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index c67e556..642ef6d 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -5,7 +5,7 @@ import pytest from cppython.plugins.generator.cmake import CMakeData, CMakeGenerator -from cppython.plugins.test.data import default_cppython_data, default_pep621 +from cppython.plugins.test.data import default_pyproject from cppython.plugins.test.pytest import GeneratorUnitTests @@ -17,4 +17,4 @@ class TestCMakeGenerator(GeneratorUnitTests): @pytest.fixture(name="generator") def fixture_generator(self): cmake_data = CMakeData() - return CMakeGenerator(default_pep621, default_cppython_data, cmake_data) + return CMakeGenerator(default_pyproject) diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index ef685a3..993571e 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -7,6 +7,7 @@ from pytest_mock.plugin import MockerFixture from cppython.plugins.interface.console import Config, ConsoleInterface, cli +from cppython.plugins.test.data import default_pyproject from cppython.plugins.test.pytest import InterfaceUnitTests @@ -17,7 +18,7 @@ class TestCLIInterface(InterfaceUnitTests): @pytest.fixture(name="interface") def fixture_interface(self): - return ConsoleInterface() + return ConsoleInterface(default_pyproject) @pytest.mark.parametrize("command", ["install", "update"]) def test_command(self, command: str, mocker: MockerFixture): From c6ee3af9ec6d2a878a0a6926b8c33b2278aa8c01 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Fri, 11 Feb 2022 07:20:58 -0500 Subject: [PATCH 38/55] Remove Outdated Tests --- cppython/plugins/test/pytest.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index f08680b..5c1622b 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -91,17 +91,3 @@ class InterfaceUnitTests(InterfaceTests): Custom implementations of the Interface class should inherit from this class for its tests. This class provides a generic test suite that all custom types must function with. """ - - def test_pep612(self, interface: Interface): - """ - TODO - """ - - pep_621 = interface.pep_621 - - def test_cppython_data(self, interface: Interface): - """ - TODO - """ - - cppython_data = interface.cppython_data From 048a36958c533d3d55eea98d3f5b378b506f0cd9 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Fri, 11 Feb 2022 08:04:28 -0500 Subject: [PATCH 39/55] Readd Generator Read --- cppython/schema.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cppython/schema.py b/cppython/schema.py index 3e02390..04403b6 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod from enum import Enum from pathlib import Path -from typing import Type +from typing import Type, TypeVar from pydantic import BaseModel @@ -112,6 +112,9 @@ class GeneratorData(BaseModel): """ +GeneratorDataType = TypeVar("GeneratorDataType", bound=GeneratorData) + + class Interface: """ Abstract type to be inherited by CPPython interfaces @@ -137,6 +140,12 @@ def pyproject(self, value: PyProject): self._pyproject = value + @abstractmethod + def read_generator_data(self, generator_data_type: Type[GeneratorDataType]) -> GeneratorDataType: + """ + TODO + """ + @abstractmethod def write_pyproject(self) -> None: """ From 21cdcf264a7f283fbcb221730c0fcdf17ce8d09a Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sat, 12 Feb 2022 07:09:09 -0500 Subject: [PATCH 40/55] Update Chore --- pdm.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pdm.lock b/pdm.lock index 11ffa14..ea5403e 100644 --- a/pdm.lock +++ b/pdm.lock @@ -161,7 +161,7 @@ summary = "Python parsing module" [[package]] name = "pytest" -version = "7.0.0" +version = "7.0.1" requires_python = ">=3.6" summary = "pytest: simple powerful testing with Python" dependencies = [ @@ -461,9 +461,9 @@ content_hash = "sha256:f18a6d6ee6b08697dc4b4ab33ecb41cf6cfe597cbf60877d816cb884f {file = "pyparsing-3.0.7-py3-none-any.whl", hash = "sha256:a6c06a88f252e6c322f65faf8f418b16213b51bdfaece0524c1c1bc30c63c484"}, {file = "pyparsing-3.0.7.tar.gz", hash = "sha256:18ee9022775d270c55187733956460083db60b37d0d0fb357445f3094eed3eea"}, ] -"pytest 7.0.0" = [ - {file = "pytest-7.0.0-py3-none-any.whl", hash = "sha256:42901e6bd4bd4a0e533358a86e848427a49005a3256f657c5c8f8dd35ef137a9"}, - {file = "pytest-7.0.0.tar.gz", hash = "sha256:dad48ffda394e5ad9aa3b7d7ddf339ed502e5e365b1350e0af65f4a602344b11"}, +"pytest 7.0.1" = [ + {file = "pytest-7.0.1-py3-none-any.whl", hash = "sha256:9ce3ff477af913ecf6321fe337b93a2c0dcf2a0a1439c43f5452112c1e4280db"}, + {file = "pytest-7.0.1.tar.gz", hash = "sha256:e30905a0c131d3d94b89624a1cc5afec3e0ba2fbdb151867d8e0ebd49850f171"}, ] "pytest-cov 3.0.0" = [ {file = "pytest_cov-3.0.0-py3-none-any.whl", hash = "sha256:578d5d15ac4a25e5f961c938b85a05b09fdaae9deef3bb6de9a6e766622ca7a6"}, From e30769a3bb7209a6d4468c547e50a54ac8ec260d Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sat, 12 Feb 2022 08:36:58 -0500 Subject: [PATCH 41/55] Fix Tests --- cppython/plugins/interface/console.py | 24 +++++++++++++++++++----- tests/unit/test_interface.py | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index bdc14c2..ed9c654 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -36,17 +36,31 @@ def _read_data(path: Path) -> TOMLDocument: return tomlkit.loads(path.read_text(encoding="utf-8")) +def _create_pyproject(): + + # Search for a path upward + path = Path.cwd() + + while not path.glob("pyproject.toml"): + if path.is_absolute(): + assert ( + False + ), "This is not a valid project. No pyproject.toml found in the current directory or any of its parents." + + path = Path(path / "pyproject.toml") + + data = tomlkit.loads(path.read_text(encoding="utf-8")) + + return PyProject(**data) + + class Config: """ The data object that will be expanded alongside 'pass_obj' """ def __init__(self): - - path = _path_search() - data = _read_data(path) - - pyproject = PyProject(**data) + pyproject = _create_pyproject() # Initialize the object hook into CPPython interface = ConsoleInterface(pyproject) diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 993571e..ed0aef8 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -33,6 +33,9 @@ def test_command(self, command: str, mocker: MockerFixture): # Patch the project initialization mocker.patch("cppython.project.Project.__init__", return_value=None) + # Patch the reading of data + mocker.patch("cppython.plugins.interface.console._create_pyproject", return_value=default_pyproject) + config = Config() # Patch out the non-plugin implementation From 90b5d602a4cc3bbdd91d7f215e7597436cb8edeb Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sat, 12 Feb 2022 10:11:46 -0500 Subject: [PATCH 42/55] Comments --- cppython/plugins/interface/console.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index ed9c654..a23f29e 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -49,8 +49,10 @@ def _create_pyproject(): path = Path(path / "pyproject.toml") + # Load file data = tomlkit.loads(path.read_text(encoding="utf-8")) + # Interpret and validate data return PyProject(**data) From bd657459751204cb07efc5ea21f7b011b450f3ce Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sat, 12 Feb 2022 12:25:00 -0500 Subject: [PATCH 43/55] Pass through Data --- cppython/plugins/generator/cmake.py | 4 ++-- cppython/project.py | 7 ++++--- cppython/schema.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index 9cd2871..65bdcc9 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -17,8 +17,8 @@ class CMakeGenerator(Generator): A CPPython generator implementing a CMake backend """ - def __init__(self, pyproject: PyProject) -> None: - super().__init__(pyproject) + def __init__(self, pyproject: PyProject, cmake_data: CMakeData) -> None: + super().__init__(pyproject, cmake_data) @staticmethod def name() -> str: diff --git a/cppython/project.py b/cppython/project.py index 3e61a69..adbf2e3 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -16,9 +16,9 @@ def __init__(self, interface: Interface) -> None: self._interface = interface - _PluginType = TypeVar("_PluginType", bound=Type[Plugin]) + PluginType = TypeVar("PluginType", bound=Type[Plugin]) - def find_plugin_type(plugin_type: _PluginType, condition: Callable[[str], bool]) -> Optional[_PluginType]: + def find_plugin_type(plugin_type: PluginType, condition: Callable[[str], bool]) -> Optional[PluginType]: """ Finds the first plugin that satisfies the given condition """ @@ -40,7 +40,8 @@ def find_plugin_type(plugin_type: _PluginType, condition: Callable[[str], bool]) f"No generator plugin with the name '{interface.pyproject.cppython_data.generator}' was found." ) - self._generator = plugin_type(interface.pyproject) + generator_data = interface.read_generator_data(plugin_type.data_type()) + self._generator = plugin_type(interface.pyproject, generator_data) # API Contract diff --git a/cppython/schema.py b/cppython/schema.py index 04403b6..ae4b731 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -160,7 +160,7 @@ class Generator(Plugin, API): """ @abstractmethod - def __init__(self, pyproject: PyProject) -> None: + def __init__(self, pyproject: PyProject, generator_data: GeneratorData) -> None: super().__init__() @staticmethod From 50cd1e066378a1a1a912d54937719ce3c39f2b5e Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sat, 12 Feb 2022 14:30:57 -0500 Subject: [PATCH 44/55] Fix CMake Tests --- tests/integration/test_generator.py | 2 +- tests/unit/test_generator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_generator.py b/tests/integration/test_generator.py index d599bd2..f00fd18 100644 --- a/tests/integration/test_generator.py +++ b/tests/integration/test_generator.py @@ -17,4 +17,4 @@ class TestCMakeGenerator(GeneratorIntegrationTests): @pytest.fixture(name="generator") def fixture_generator(self): cmake_data = CMakeData() - return CMakeGenerator(default_pyproject) + return CMakeGenerator(default_pyproject, cmake_data) diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index 642ef6d..93417c2 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -17,4 +17,4 @@ class TestCMakeGenerator(GeneratorUnitTests): @pytest.fixture(name="generator") def fixture_generator(self): cmake_data = CMakeData() - return CMakeGenerator(default_pyproject) + return CMakeGenerator(default_pyproject, cmake_data) From 0e2bd77788310fb24caed3099d75ff1d4d83308e Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 13 Feb 2022 09:22:42 -0500 Subject: [PATCH 45/55] Chore --- pdm.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pdm.lock b/pdm.lock index ea5403e..681ab32 100644 --- a/pdm.lock +++ b/pdm.lock @@ -220,7 +220,7 @@ summary = "Style preserving TOML library" [[package]] name = "typing-extensions" -version = "4.0.1" +version = "4.1.0" requires_python = ">=3.6" summary = "Backported and Experimental Type Hints for Python 3.6+" @@ -489,9 +489,9 @@ content_hash = "sha256:f18a6d6ee6b08697dc4b4ab33ecb41cf6cfe597cbf60877d816cb884f {file = "tomlkit-0.9.2-py3-none-any.whl", hash = "sha256:daf4f9c5f2fbf6b861d6adfc51940b98dee36c13e1d88749a6dc9fb280fff304"}, {file = "tomlkit-0.9.2.tar.gz", hash = "sha256:ebd982d61446af95a1e082b103e250cb9e6d152eae2581d4a07d31a70b34ab0f"}, ] -"typing-extensions 4.0.1" = [ - {file = "typing_extensions-4.0.1-py3-none-any.whl", hash = "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"}, - {file = "typing_extensions-4.0.1.tar.gz", hash = "sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e"}, +"typing-extensions 4.1.0" = [ + {file = "typing_extensions-4.1.0-py3-none-any.whl", hash = "sha256:c13180fbaa7cd97065a4915ceba012bdb31dc34743e63ddee16360161d358414"}, + {file = "typing_extensions-4.1.0.tar.gz", hash = "sha256:ba97c5143e5bb067b57793c726dd857b1671d4b02ced273ca0538e71ff009095"}, ] "wrapt 1.13.3" = [ {file = "wrapt-1.13.3-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:e05e60ff3b2b0342153be4d1b597bbcfd8330890056b9619f4ad6b8d5c96a81a"}, From 1243dcf51a47765c39bc71466cb07d841c2ed05d Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 13 Feb 2022 10:21:35 -0500 Subject: [PATCH 46/55] Call install --- cppython/project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cppython/project.py b/cppython/project.py index adbf2e3..70ce83e 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -42,6 +42,7 @@ 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(interface.pyproject, generator_data) + self._generator.install_generator() # API Contract From 9de79048cb1dd0a84529f13537df3462551545f1 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 13 Feb 2022 12:14:12 -0500 Subject: [PATCH 47/55] Remove conftest --- tests/conftest.py | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index d24e181..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,21 +0,0 @@ -""" -TODO: -""" - -from pathlib import Path -from shutil import copytree - -import pytest - - -@pytest.fixture -def tmp_workspace(tmp_path): - """ - Load the dummy project to its initial state - """ - - template_directory = Path("tests/data/test_project").absolute() - directory = Path(tmp_path).absolute() - copytree(str(directory), str(template_directory), dirs_exist_ok=True) - - return directory From d76a8bf6b1cb7a91aabda82e615e7eec6e0e4994 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 13 Feb 2022 22:37:20 -0500 Subject: [PATCH 48/55] Comments --- tests/unit/test_interface.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index ed0aef8..7119c8e 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -17,18 +17,23 @@ class TestCLIInterface(InterfaceUnitTests): """ @pytest.fixture(name="interface") - def fixture_interface(self): + def fixture_interface(self) -> ConsoleInterface: + """ + Override of the plugin provided interface fixture. + + Returns: + ConsoleInterface -- The Interface object to use for the plugin defined tests + """ return ConsoleInterface(default_pyproject) @pytest.mark.parametrize("command", ["install", "update"]) def test_command(self, command: str, mocker: MockerFixture): """ - TODO + _summary_ Arguments: - interface {ConsoleInterface} -- [description] - command {str} -- [description] - mocker {[type]} -- [description] + command {str} -- _description_ + mocker {MockerFixture} -- _description_ """ # Patch the project initialization mocker.patch("cppython.project.Project.__init__", return_value=None) @@ -38,7 +43,7 @@ def test_command(self, command: str, mocker: MockerFixture): config = Config() - # Patch out the non-plugin implementation + # Patch out the implementation mocker.patch(f"cppython.project.Project.{command}") runner = CliRunner() From e06afad29fa14df43fb56c7742fa3a6fd75b7813 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Mon, 14 Feb 2022 12:37:53 -0500 Subject: [PATCH 49/55] Command Update --- cppython/plugins/interface/console.py | 9 +++++++++ tests/unit/test_interface.py | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index a23f29e..ae0d79a 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -101,6 +101,15 @@ def update(config): config.project.update() +@cli.command() +@pass_config +def build(config): + """ + TODO + """ + config.project.build() + + @cli.result_callback() @pass_config def cleanup(config, result): diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 7119c8e..58fc778 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -9,6 +9,7 @@ from cppython.plugins.interface.console import Config, ConsoleInterface, cli from cppython.plugins.test.data import default_pyproject from cppython.plugins.test.pytest import InterfaceUnitTests +from cppython.schema import API class TestCLIInterface(InterfaceUnitTests): @@ -26,7 +27,9 @@ def fixture_interface(self) -> ConsoleInterface: """ return ConsoleInterface(default_pyproject) - @pytest.mark.parametrize("command", ["install", "update"]) + method_list = [func for func in dir(API) if callable(getattr(API, func)) and not func.startswith("__")] + + @pytest.mark.parametrize("command", method_list) def test_command(self, command: str, mocker: MockerFixture): """ _summary_ @@ -44,9 +47,10 @@ def test_command(self, command: str, mocker: MockerFixture): config = Config() # Patch out the implementation - mocker.patch(f"cppython.project.Project.{command}") + mocked_command = mocker.patch(f"cppython.project.Project.{command}") runner = CliRunner() result = runner.invoke(cli, [command], obj=config, catch_exceptions=False) assert result.exit_code == 0 + mocked_command.assert_called_once() From b754e0eafa6f120808c33ac2056f67cd0bc43dbb Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Mon, 14 Feb 2022 15:25:00 -0500 Subject: [PATCH 50/55] test_interface --- tests/unit/test_interface.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 58fc778..49fdac4 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -27,6 +27,7 @@ def fixture_interface(self) -> ConsoleInterface: """ return ConsoleInterface(default_pyproject) + # Grab the API methods and parameterize them for automatic testing of the entry_points method_list = [func for func in dir(API) if callable(getattr(API, func)) and not func.startswith("__")] @pytest.mark.parametrize("command", method_list) @@ -35,8 +36,8 @@ def test_command(self, command: str, mocker: MockerFixture): _summary_ Arguments: - command {str} -- _description_ - mocker {MockerFixture} -- _description_ + command {str} -- The CLI command with the same name as the CPPython API call + mocker {MockerFixture} -- pytest-mock fixture """ # Patch the project initialization mocker.patch("cppython.project.Project.__init__", return_value=None) From c746a1e2f521158fed99e6bb5ad70e84138a16ed Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 15 Feb 2022 05:11:12 -0500 Subject: [PATCH 51/55] Test Comments --- tests/integration/test_generator.py | 8 +++++++- tests/integration/test_interface.py | 5 +++++ tests/unit/test_generator.py | 10 ++++++++-- tests/unit/test_interface.py | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_generator.py b/tests/integration/test_generator.py index f00fd18..d3ccd5f 100644 --- a/tests/integration/test_generator.py +++ b/tests/integration/test_generator.py @@ -1,5 +1,5 @@ """ -TODO: +Test the integrations related to the internal generator implementation and the 'Generator' interface itself """ import pytest @@ -16,5 +16,11 @@ class TestCMakeGenerator(GeneratorIntegrationTests): @pytest.fixture(name="generator") def fixture_generator(self): + """ + Override of the plugin provided generator fixture. + + Returns: + CMakeGenerator -- The Generator object to use for the CPPython defined tests + """ cmake_data = CMakeData() return CMakeGenerator(default_pyproject, cmake_data) diff --git a/tests/integration/test_interface.py b/tests/integration/test_interface.py index abd89e9..8ae9da4 100644 --- a/tests/integration/test_interface.py +++ b/tests/integration/test_interface.py @@ -16,5 +16,10 @@ class TestCLIInterface(InterfaceIntegrationTests): @pytest.fixture(name="interface") def fixture_interface(self): + """ + Override of the plugin provided interface fixture. + Returns: + ConsoleInterface -- The Interface object to use for the CPPython defined tests + """ return ConsoleInterface(default_pyproject) diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py index 93417c2..d8871fb 100644 --- a/tests/unit/test_generator.py +++ b/tests/unit/test_generator.py @@ -1,5 +1,5 @@ """ -TODO: +Test the functions related to the internal generator implementation and the 'Generator' interface itself """ import pytest @@ -15,6 +15,12 @@ class TestCMakeGenerator(GeneratorUnitTests): """ @pytest.fixture(name="generator") - def fixture_generator(self): + def fixture_generator(self) -> CMakeGenerator: + """ + Override of the plugin provided generator fixture. + + Returns: + CMakeGenerator -- The Generator object to use for the CPPython defined tests + """ cmake_data = CMakeData() return CMakeGenerator(default_pyproject, cmake_data) diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 49fdac4..4ac97fd 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -1,5 +1,5 @@ """ -TODO: +Test the functions related to the internal interface implementation and the 'Interface' interface itself """ import pytest From ff80734fb936c0ca506c9bfe37720d84be1d5bec Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 15 Feb 2022 05:31:17 -0500 Subject: [PATCH 52/55] SchemaTODOs --- cppython/schema.py | 20 +++++++++++--------- tests/data/__init__.py | 1 - 2 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 tests/data/__init__.py diff --git a/cppython/schema.py b/cppython/schema.py index ae4b731..79d6c69 100644 --- a/cppython/schema.py +++ b/cppython/schema.py @@ -22,7 +22,7 @@ class TargetEnum(Enum): class PEP621(BaseModel): """ - Subset of PEP 621 + PEP 621 conforming data The entirety of PEP 621 is not relevant for interface plugins Schema: https://www.python.org/dev/peps/pep-0621/ """ @@ -45,7 +45,7 @@ class CPPythonData(BaseModel): class PyProject(BaseModel): """ - TODO + pyproject.toml schema """ pep_621: PEP621 @@ -101,14 +101,14 @@ def __init__(self) -> None: @abstractmethod def plugin_group() -> str: """ - TODO + The plugin group name as used by 'setuptools' """ raise NotImplementedError() class GeneratorData(BaseModel): """ - Base class for the configuration data that will be given to the generator constructor + Base class for the configuration data that will be read by the interface and given to the generator """ @@ -128,14 +128,14 @@ def __init__(self, pyproject: PyProject) -> None: @property def pyproject(self) -> PyProject: """ - TODO + PyProject getter """ return self._pyproject @pyproject.setter def pyproject(self, value: PyProject): """ - TODO + PyProject setter """ self._pyproject = value @@ -143,8 +143,10 @@ def pyproject(self, value: PyProject): @abstractmethod def read_generator_data(self, generator_data_type: Type[GeneratorDataType]) -> GeneratorDataType: """ - TODO + Dynamic pyproject.toml data that is determined by the generator plugin requested by [tool.cppython.generator] + The Schema defined by 'generator_data_type' must be filled by the [tool.cppython.{generator_value}] slot. """ + raise NotImplementedError() @abstractmethod def write_pyproject(self) -> None: @@ -166,7 +168,7 @@ def __init__(self, pyproject: PyProject, generator_data: GeneratorData) -> None: @staticmethod def plugin_group() -> str: """ - TODO + The plugin group name as used by 'setuptools' """ return "generator_plugins" @@ -174,7 +176,7 @@ def plugin_group() -> str: @abstractmethod def name() -> str: """ - TODO + The string that is matched with the [tool.cppython.generator] string """ raise NotImplementedError() diff --git a/tests/data/__init__.py b/tests/data/__init__.py deleted file mode 100644 index 5f28270..0000000 --- a/tests/data/__init__.py +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file From 9a468a55e5db0d02cc6f85effb56aed66521e87d Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 15 Feb 2022 05:54:22 -0500 Subject: [PATCH 53/55] More TODOs --- cppython/exceptions.py | 6 ++++++ cppython/plugins/test/pytest.py | 23 +++++++++++++---------- cppython/project.py | 8 +++++--- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/cppython/exceptions.py b/cppython/exceptions.py index b705a6e..c9d3102 100644 --- a/cppython/exceptions.py +++ b/cppython/exceptions.py @@ -15,4 +15,10 @@ def __init__(self, error: str) -> None: @property def error(self) -> str: + """ + Returns the underlying error + + Returns: + str -- The underlying error + """ return self._error diff --git a/cppython/plugins/test/pytest.py b/cppython/plugins/test/pytest.py index 5c1622b..68eb48c 100644 --- a/cppython/plugins/test/pytest.py +++ b/cppython/plugins/test/pytest.py @@ -1,5 +1,6 @@ """ -TODO: +Helper fixtures and plugin definitions for pytest +TODO: Should by a pytest plugin, removing the need for this module in production code. """ from abc import ABC from importlib.metadata import entry_points @@ -12,7 +13,7 @@ class GeneratorTests(ABC): """ - TODO + Shared functionality between the different Generator testing categories """ @pytest.fixture(name="generator") @@ -26,7 +27,7 @@ def fixture_generator(self) -> Generator: class GeneratorIntegrationTests(GeneratorTests): """ - TODO + Base class for all generator integration tests that test plugin agnostic behavior """ def test_plugin_registration(self, generator: Generator): @@ -40,12 +41,13 @@ def test_plugin_registration(self, generator: Generator): class GeneratorUnitTests(GeneratorTests): """ Custom implementations of the Generator class should inherit from this class for its tests. - This class provides a generic test suite that all custom types must function with. + Base class for all generator unit tests that test plugin agnostic behavior """ def test_name(self, generator: Generator): """ - TODO + Test name restrictions + TODO: This should be a pydantic schema """ name = generator.name() @@ -53,7 +55,8 @@ def test_name(self, generator: Generator): def test_data_type(self, generator: Generator): """ - TODO + Test data_type restrictions + TODO: This should be a pydantic schema """ data_type = generator.data_type() @@ -62,7 +65,7 @@ def test_data_type(self, generator: Generator): class InterfaceTests(ABC): """ - TODO + Shared functionality between the different Interface testing categories """ @pytest.fixture(name="interface") @@ -76,12 +79,12 @@ def fixture_interface(self) -> Interface: class InterfaceIntegrationTests(InterfaceTests): """ - TODO + Base class for all interface integration tests that test plugin agnostic behavior """ def test_project(self, interface: Interface): """ - TODO + Test that the project can be constructed from the given interface """ Project(interface) @@ -89,5 +92,5 @@ def test_project(self, interface: Interface): class InterfaceUnitTests(InterfaceTests): """ Custom implementations of the Interface class should inherit from this class for its tests. - This class provides a generic test suite that all custom types must function with. + Base class for all interface unit tests that test plugin agnostic behavior """ diff --git a/cppython/project.py b/cppython/project.py index 70ce83e..7765761 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -1,3 +1,7 @@ +""" +The central delegation of the CPPython project +""" + from importlib import metadata from typing import Callable, Optional, Type, TypeVar @@ -7,9 +11,7 @@ class Project(API): """ - TODO - - + The object constructed at each entry_point """ def __init__(self, interface: Interface) -> None: From aea4635228a03d6bee8f0d857fc4c75da358042b Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 15 Feb 2022 06:08:32 -0500 Subject: [PATCH 54/55] Fix TODOs --- cppython/plugins/generator/cmake.py | 4 +-- cppython/plugins/interface/console.py | 51 ++++++++------------------- cppython/plugins/test/data.py | 4 ++- tests/integration/test_interface.py | 2 +- tests/unit/test_interface.py | 2 +- 5 files changed, 22 insertions(+), 41 deletions(-) diff --git a/cppython/plugins/generator/cmake.py b/cppython/plugins/generator/cmake.py index 65bdcc9..ff859ce 100644 --- a/cppython/plugins/generator/cmake.py +++ b/cppython/plugins/generator/cmake.py @@ -1,5 +1,5 @@ """ -TODO: +The default generator implementation for CPPython """ from typing import Type @@ -8,7 +8,7 @@ class CMakeData(GeneratorData): """ - TODO: + The data schema required for the CMake tooling """ diff --git a/cppython/plugins/interface/console.py b/cppython/plugins/interface/console.py index ae0d79a..5f9d30c 100644 --- a/cppython/plugins/interface/console.py +++ b/cppython/plugins/interface/console.py @@ -1,39 +1,15 @@ """ -TODO: +A click CLI for CPPython interfacing """ from pathlib import Path -from typing import Any, Type +from typing import Type import click import tomlkit -from tomlkit.api import TOMLDocument from cppython.project import Project -from cppython.schema import GeneratorData, Interface, PyProject - - -def _path_search() -> Path: - """ - TODO - """ - path = Path.cwd() - - while not path.glob("pyproject.toml"): - if path.is_absolute(): - assert ( - False - ), "This is not a valid project. No pyproject.toml found in the current directory or any of its parents." - - return Path(path / "pyproject.toml") - - -def _read_data(path: Path) -> TOMLDocument: - """ - TODO - """ - - return tomlkit.loads(path.read_text(encoding="utf-8")) +from cppython.schema import GeneratorData, GeneratorDataType, Interface, PyProject def _create_pyproject(): @@ -78,7 +54,7 @@ def __init__(self): @click.pass_context def cli(context): """ - TODO + entry_point group for the CLI commands """ context.ensure_object(Config) @@ -87,7 +63,7 @@ def cli(context): @pass_config def install(config): """ - TODO + Fulfills the 'install' API requirement """ config.project.install() @@ -96,7 +72,7 @@ def install(config): @pass_config def update(config): """ - TODO + Fulfills the 'update' API requirement """ config.project.update() @@ -105,7 +81,7 @@ def update(config): @pass_config def build(config): """ - TODO + Fulfills the 'build' API requirement """ config.project.build() @@ -114,20 +90,23 @@ def build(config): @pass_config def cleanup(config, result): """ - TODO + Post-command cleanup """ class ConsoleInterface(Interface): """ - TODO: Description + Interface implementation to pass to the project """ - def generator_data(self, generator_data: Type[GeneratorData]) -> GeneratorData: + def read_generator_data(self, generator_data_type: Type[GeneratorDataType]) -> GeneratorDataType: """ Requests generator information """ - raise NotImplementedError() + return generator_data_type() def write_pyproject(self) -> None: - raise NotImplementedError() + """ + Write output + """ + pass diff --git a/cppython/plugins/test/data.py b/cppython/plugins/test/data.py index 9df1e88..76a30e7 100644 --- a/cppython/plugins/test/data.py +++ b/cppython/plugins/test/data.py @@ -1,5 +1,5 @@ """ -TODO +Defaulted data to help testing """ from pathlib import Path @@ -8,6 +8,8 @@ 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(pep_621=default_pep621, cppython_data=default_cppython_data) diff --git a/tests/integration/test_interface.py b/tests/integration/test_interface.py index 8ae9da4..df10d42 100644 --- a/tests/integration/test_interface.py +++ b/tests/integration/test_interface.py @@ -1,5 +1,5 @@ """ -TODO: +Test the integrations related to the internal interface implementation and the 'Interface' interface itself """ import pytest diff --git a/tests/unit/test_interface.py b/tests/unit/test_interface.py index 4ac97fd..5cc74e9 100644 --- a/tests/unit/test_interface.py +++ b/tests/unit/test_interface.py @@ -23,7 +23,7 @@ def fixture_interface(self) -> ConsoleInterface: Override of the plugin provided interface fixture. Returns: - ConsoleInterface -- The Interface object to use for the plugin defined tests + ConsoleInterface -- The Interface object to use for the CPPython defined tests """ return ConsoleInterface(default_pyproject) From caac57e6852cd1a02d31d280a48d84b647dcdf8d Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Wed, 16 Feb 2022 06:46:55 -0500 Subject: [PATCH 55/55] Update Workflow --- .github/workflows/release.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c8c96d0..0399b1e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,22 @@ -name: Publish +name: Publish Python Package on: release: types: [published] + push: jobs: - call_synodic_workflow: - uses: synodic-software/.github/.github/workflows/publish.yml@stable + publish_development: + if: github.event_name == 'push' + steps: + - uses: synodic-software/.github/.github/workflows/python-publish.yml@stable + with: + repository_url: https://test.pypi.org/ + token: ${{ secrets.TEST_PYPI_API_TOKEN }} + + publish_release: + if: github.event_name == 'release' && github.event.action == 'published' + steps: + - uses: synodic-software/.github/.github/workflows/python-publish.yml@stable + with: + repository_url: https://pypi.org/ + token: ${{ secrets.PYPI_API_TOKEN }}