From 434294f4fb2bea17e2e5dcfa97034bb86770183c Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Fri, 6 May 2022 06:06:23 -0400 Subject: [PATCH 1/2] Update Core --- cppython/console.py | 1 - cppython/project.py | 31 +++++++++++++++---------------- pdm.lock | 16 ++++++++-------- tests/unit/test_project.py | 4 ++-- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/cppython/console.py b/cppython/console.py index 922c5a8..3944255 100644 --- a/cppython/console.py +++ b/cppython/console.py @@ -2,7 +2,6 @@ A click CLI for CPPython interfacing """ -from logging import Logger from pathlib import Path from typing import Any, Type diff --git a/cppython/project.py b/cppython/project.py index bd46e2d..dee17a4 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -7,6 +7,7 @@ from importlib import metadata from typing import Any, Type, TypeVar +from cppython_core.core import cppython_logger from cppython_core.schema import ( API, CPPythonData, @@ -58,7 +59,7 @@ def gather_plugins(self, plugin_type: Type[DerivedPlugin]) -> list[Type[DerivedP TODO """ plugins = [] - entry_points = metadata.entry_points(group=f"cppython.{plugin_type.plugin_group()}") + entry_points = metadata.entry_points(group=f"cppython.{plugin_type.group()}") for entry_point in entry_points: loaded_plugin_type = entry_point.load() @@ -121,35 +122,33 @@ def __init__( levels = [logging.WARNING, logging.INFO, logging.DEBUG] - self._logger = logging.getLogger("cppython") - # Add default output stream console_handler = logging.StreamHandler() - self._logger.addHandler(console_handler) - self._logger.setLevel(levels[configuration.verbosity]) + cppython_logger.addHandler(console_handler) + cppython_logger.setLevel(levels[configuration.verbosity]) - self._logger.info("Initializing project") + cppython_logger.info("Initializing project") builder = ProjectBuilder(self.configuration) plugins = builder.gather_plugins(Generator) if not plugins: - self._logger.info("No generator plugin was found") + cppython_logger.info("No generator plugin was found") return extended_pyproject_type = builder.generate_model(plugins) self._pyproject = extended_pyproject_type(**pyproject_data) if self.pyproject is None: - self._logger.info("Data is not defined") + cppython_logger.info("Data is not defined") return if self.pyproject.tool is None: - self._logger.info("Table [tool] is not defined") + cppython_logger.info("Table [tool] is not defined") return if self.pyproject.tool.cppython is None: - self._logger.info("Table [tool.cppython] is not defined") + cppython_logger.info("Table [tool.cppython] is not defined") return self._enabled = True @@ -159,7 +158,7 @@ def __init__( generator_configuration = GeneratorConfiguration() self._generators = builder.create_generators(plugins, generator_configuration, self.pyproject) - self._logger.info("Initialized project") + cppython_logger.info("Initialized project") @property def enabled(self) -> bool: @@ -196,17 +195,17 @@ def download(self): path.mkdir(parents=True, exist_ok=True) if not generator.generator_downloaded(path): - self._logger.info(f"Downloading the {generator.name()} tool") + cppython_logger.info(f"Downloading the {generator.name()} tool") # TODO: Make async with progress bar generator.download_generator(path) - self._logger.info("Download complete") + cppython_logger.info("Download complete") # API Contract def install(self) -> None: if self._enabled: - self._logger.info("Installing project") + cppython_logger.info("Installing project") self.download() for generator in self._generators: @@ -214,14 +213,14 @@ def install(self) -> None: def update(self) -> None: if self._enabled: - self._logger.info("Updating project") + cppython_logger.info("Updating project") for generator in self._generators: generator.update() def build(self) -> None: if self._enabled: - self._logger.info("Building project") + cppython_logger.info("Building project") for generator in self._generators: generator.build() diff --git a/pdm.lock b/pdm.lock index aa11766..1ca852f 100644 --- a/pdm.lock +++ b/pdm.lock @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "cppython-core" -version = "0.3.3.dev9" +version = "0.3.3.dev11" requires_python = ">=3.10" summary = "Data definitions for CPPython" dependencies = [ @@ -200,7 +200,7 @@ dependencies = [ [[package]] name = "pytest-cppython" -version = "0.1.7.dev5" +version = "0.1.7.dev7" requires_python = ">=3.10" summary = "A pytest plugin that imports CPPython testing types" dependencies = [ @@ -340,9 +340,9 @@ content_hash = "sha256:9842348d0ddc71440b500499ed71e9b60aea9edcf388f5d8ef170c125 {file = "coverage-6.3.2-pp36.pp37.pp38-none-any.whl", hash = "sha256:18d520c6860515a771708937d2f78f63cc47ab3b80cb78e86573b0a760161faf"}, {file = "coverage-6.3.2.tar.gz", hash = "sha256:03e2a7826086b91ef345ff18742ee9fc47a6839ccd517061ef8fa1976e652ce9"}, ] -"cppython-core 0.3.3.dev9" = [ - {file = "cppython_core-0.3.3.dev9-py3-none-any.whl", hash = "sha256:4131d749f2e5e6f79bed6899e05f3b98ba314347c4c38f6215a927b9857d1be3"}, - {file = "cppython-core-0.3.3.dev9.tar.gz", hash = "sha256:24ff5742afc4bd67ec9aaf05d547f08f4d41a24c9b932507aa8c0cbccc81f1e8"}, +"cppython-core 0.3.3.dev11" = [ + {file = "cppython_core-0.3.3.dev11-py3-none-any.whl", hash = "sha256:0eabfb0b16d0eb189a9aa0fddc0ba4969544b0fa23ca0c645446cb2cf99739e6"}, + {file = "cppython-core-0.3.3.dev11.tar.gz", hash = "sha256:d70407fe819fdfc1afcf0229f12374a87a2306ee34e641f3fd79ca56b0cec0e5"}, ] "dill 0.3.4" = [ {file = "dill-0.3.4-py2.py3-none-any.whl", hash = "sha256:7e40e4a70304fd9ceab3535d36e58791d9c4a776b38ec7f7ec9afc8d3dca4d4f"}, @@ -476,9 +476,9 @@ content_hash = "sha256:9842348d0ddc71440b500499ed71e9b60aea9edcf388f5d8ef170c125 {file = "pytest_cov-3.0.0-py3-none-any.whl", hash = "sha256:578d5d15ac4a25e5f961c938b85a05b09fdaae9deef3bb6de9a6e766622ca7a6"}, {file = "pytest-cov-3.0.0.tar.gz", hash = "sha256:e7f0f5b1617d2210a2cabc266dfe2f4c75a8d32fb89eafb7ad9d06f6d076d470"}, ] -"pytest-cppython 0.1.7.dev5" = [ - {file = "pytest_cppython-0.1.7.dev5-py3-none-any.whl", hash = "sha256:c750583c9032a2bc16a0e2d498a99b3f822cbb5999118a109e4237e81af05977"}, - {file = "pytest-cppython-0.1.7.dev5.tar.gz", hash = "sha256:8627722a9445a3f8964d7433edfeedbd472c6661e330b4f7caed72debbef0ebd"}, +"pytest-cppython 0.1.7.dev7" = [ + {file = "pytest_cppython-0.1.7.dev7-py3-none-any.whl", hash = "sha256:9633695811b4db94861cbd7e50ffa14915c8b219189343b2314a24488f030f01"}, + {file = "pytest-cppython-0.1.7.dev7.tar.gz", hash = "sha256:40fa340a05f1eea5c25dbf5221573378b831ef06cd4e5f5a965f9b0fde31f7a1"}, ] "pytest-mock 3.7.0" = [ {file = "pytest_mock-3.7.0-py3-none-any.whl", hash = "sha256:6cff27cec936bf81dc5ee87f07132b807bcda51106b5ec4b90a04331cba76231"}, diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index fe4c15a..c140605 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -74,7 +74,7 @@ def test_generator_data_construction(self, mocker: MockerFixture): assert model_type.__base__ == PyProject - generator_type = mocker.Mock(spec=Generator) + generator_type = mocker.Mock() generator_type.name.return_value = "mock" generator_type.data_type.return_value = MockGeneratorData @@ -104,7 +104,7 @@ def test_generator_creation(self, mocker: MockerFixture): assert not generators - generator = mocker.Mock(spec=Generator) + generator = mocker.Mock() generators = builder.create_generators([generator], generator_configuration, default_pyproject) assert len(generators) == 1 From 1838c9081c231a48ecb8113c684d964b3fd7156a Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Fri, 6 May 2022 06:23:57 -0400 Subject: [PATCH 2/2] Update Logs --- cppython/project.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cppython/project.py b/cppython/project.py index dee17a4..30582d4 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -133,22 +133,25 @@ def __init__( plugins = builder.gather_plugins(Generator) if not plugins: - cppython_logger.info("No generator plugin was found") + cppython_logger.error("No generator plugin was found") return + for plugin in plugins: + cppython_logger.warning(f"Generator plugin found: {plugin.name()}") + extended_pyproject_type = builder.generate_model(plugins) self._pyproject = extended_pyproject_type(**pyproject_data) if self.pyproject is None: - cppython_logger.info("Data is not defined") + cppython_logger.error("Data is not defined") return if self.pyproject.tool is None: - cppython_logger.info("Table [tool] is not defined") + cppython_logger.error("Table [tool] is not defined") return if self.pyproject.tool.cppython is None: - cppython_logger.info("Table [tool.cppython] is not defined") + cppython_logger.error("Table [tool.cppython] is not defined") return self._enabled = True @@ -158,7 +161,7 @@ def __init__( generator_configuration = GeneratorConfiguration() self._generators = builder.create_generators(plugins, generator_configuration, self.pyproject) - cppython_logger.info("Initialized project") + cppython_logger.info("Initialized project successfully") @property def enabled(self) -> bool: @@ -195,11 +198,11 @@ def download(self): path.mkdir(parents=True, exist_ok=True) if not generator.generator_downloaded(path): - cppython_logger.info(f"Downloading the {generator.name()} tool") + cppython_logger.warning(f"Downloading the {generator.name()} requirements to {path}") # TODO: Make async with progress bar generator.download_generator(path) - cppython_logger.info("Download complete") + cppython_logger.warning("Download complete") # API Contract @@ -209,6 +212,7 @@ def install(self) -> None: self.download() for generator in self._generators: + cppython_logger.info(f"Installing {generator.name()} generator") generator.install() def update(self) -> None: @@ -216,6 +220,7 @@ def update(self) -> None: cppython_logger.info("Updating project") for generator in self._generators: + cppython_logger.info(f"Updating {generator.name()} generator") generator.update() def build(self) -> None: @@ -223,4 +228,5 @@ def build(self) -> None: cppython_logger.info("Building project") for generator in self._generators: + cppython_logger.info(f"Building {generator.name()} generator") generator.build()