Skip to content

Verbosity #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ad434ea
Conditional Running
Behemyth Mar 6, 2022
a8765b4
Install Generator
Behemyth Mar 6, 2022
426b6f7
Download and Print
Behemyth Mar 6, 2022
49f99f5
Update data.py
Behemyth Mar 6, 2022
d578676
Add Download Print
Behemyth Mar 6, 2022
1001334
Early out construction
Behemyth Mar 6, 2022
e94c90f
Merge branch 'development' of https://github.com/Synodic-Software/CPP…
Behemyth Mar 6, 2022
7fd7824
Remove Abstract Requirement From Generator
Behemyth Mar 8, 2022
6287c1c
Update Metadata
Behemyth Mar 9, 2022
45deb10
Readd Abstract Init
Behemyth Mar 10, 2022
6dd8e32
Add Tooling Update Requirement
Behemyth Mar 10, 2022
00ebb4f
Merge branch 'development' of https://github.com/Synodic-Software/CPP…
Behemyth Mar 10, 2022
2a0588c
Move Data
Behemyth Mar 10, 2022
e638007
Proper Data Labelling
Behemyth Mar 10, 2022
bee420f
Remove Core + Test
Behemyth Mar 12, 2022
2bcc97f
Update Tests
Behemyth Mar 14, 2022
d5b07bd
Rework Early Out Condition
Behemyth Mar 14, 2022
9faf3aa
Fix Condition
Behemyth Mar 14, 2022
b257bde
Merge branch 'development' of https://github.com/Synodic-Software/CPP…
Behemyth Mar 14, 2022
8515f2d
Remove CMake Requirement
Behemyth Mar 14, 2022
fc8f198
Remove Pydantic
Behemyth Mar 14, 2022
6e5bee8
Merge branch 'development' of https://github.com/Synodic-Software/CPP…
Behemyth Mar 14, 2022
bcc5a85
Update Chore
Behemyth Mar 17, 2022
b79a3cb
Basic Verbosity
Behemyth Mar 17, 2022
251a271
Update Test With Config
Behemyth Mar 17, 2022
1b82bcf
Remove Cleanup + Add Verbosity
Behemyth Mar 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions cppython/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

from pathlib import Path
from typing import Type
from xmlrpc.client import Boolean

import click
import tomlkit
from cppython_core.schema import GeneratorDataType, Interface, PyProject

from cppython.project import Project
from cppython.project import Project, ProjectConfiguration


def _create_pyproject():
Expand Down Expand Up @@ -38,60 +39,67 @@ class Config:
"""

def __init__(self):
pyproject = _create_pyproject()
self.pyproject = _create_pyproject()
self.interface = ConsoleInterface()
self.configuration = ProjectConfiguration()

# Initialize the object hook into CPPython
interface = ConsoleInterface()

# Initialize the CPPython context
self.project = Project(interface, pyproject)
def create_project(self) -> Project:
"""
TODO
"""
return Project(self.configuration, self.interface, self.pyproject)


pass_config = click.make_pass_decorator(Config)
pass_config = click.make_pass_decorator(Config, ensure=True)


@click.group()
@click.pass_context
def cli(context):
@click.option("-v", "--verbose", is_flag=True, help="Print additional output")
@pass_config
def cli(config, verbose: Boolean):
"""
entry_point group for the CLI commands
"""
context.ensure_object(Config)
config.configuration.verbose = verbose


@cli.command()
@pass_config
def install(config):
def info(config):
"""
Fulfills the 'install' API requirement
TODO
"""
config.project.install()
project = config.create_project()


@cli.command()
@pass_config
def update(config):
def install(config):
"""
Fulfills the 'update' API requirement
TODO
"""
config.project.update()
project = config.create_project()
project.install()


@cli.command()
@pass_config
def build(config):
def update(config):
"""
Fulfills the 'build' API requirement
TODO
"""
config.project.build()
project = config.create_project()
project.update()


@cli.result_callback()
@cli.command()
@pass_config
def cleanup(config, result):
def build(config):
"""
Post-command cleanup
TODO
"""
project = config.create_project()
project.build()


class ConsoleInterface(Interface):
Expand Down
1 change: 0 additions & 1 deletion cppython/plugins/__init__.py

This file was deleted.

30 changes: 29 additions & 1 deletion cppython/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,45 @@
The central delegation of the CPPython project
"""

from dataclasses import dataclass
from importlib import metadata
from typing import Callable, Optional, Type, TypeVar
from xmlrpc.client import Boolean

from cppython_core.exceptions import ConfigError
from cppython_core.schema import API, Generator, Interface, Plugin, PyProject


@dataclass
class ProjectConfiguration:
"""
TODO
"""

verbose: Boolean = False


class Project(API):
"""
The object constructed at each entry_point
"""

def __init__(self, interface: Interface, pyproject: PyProject) -> None:
def __init__(self, configuration: ProjectConfiguration, interface: Interface, pyproject: PyProject) -> None:

self.enabled = False
self.verbose = configuration.verbose

if self.verbose:
interface.print("Starting CPPython project initialization")

if pyproject.tool is None:
if self.verbose:
interface.print("Table [tool] is not defined")
return

if pyproject.tool.cppython is None:
if self.verbose:
interface.print("Table [tool.cppython] is not defined")
return

self.enabled = True
Expand Down Expand Up @@ -53,6 +72,9 @@ def find_plugin_type(plugin_type: PluginType, condition: Callable[[str], bool])
generator_data = interface.read_generator_data(plugin_type.data_type())
self._generator = plugin_type(pyproject, generator_data)

if self.verbose:
interface.print("CPPython project initialized")

def download(self):
"""
Download the generator tooling if required
Expand All @@ -68,13 +90,19 @@ def download(self):

def install(self) -> None:
if self.enabled:
if self.verbose:
self._interface.print("CPPython: Installing...")
self.download()
self._generator.install()

def update(self) -> None:
if self.enabled:
if self.verbose:
self._interface.print("CPPython: Updating...")
self._generator.update()

def build(self) -> None:
if self.enabled:
if self.verbose:
self._interface.print("CPPython: Building...")
self._generator.build()
41 changes: 9 additions & 32 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ requires-python = ">=3.10"

dependencies = [
"click>=8.0.3",
"cmake>=3.22.3",
"pydantic>=1.9",
"tomlkit>=0.10.0",
"cppython-core>=0.1.0",
"cppython-core>=0.1.1",
]

[project.license-files]
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from cppython.console import Config, ConsoleInterface, cli
from cppython.data import default_pyproject
from cppython.project import ProjectConfiguration


class TestCLIInterface(InterfaceUnitTests):
Expand Down Expand Up @@ -55,3 +56,24 @@ def test_command(self, command: str, mocker: MockerFixture):

assert result.exit_code == 0
mocked_command.assert_called_once()

def test_config(self):
"""
TODO
"""

Config()

def test_verbosity(self):
"""
TODO
"""

config = Config()

runner = CliRunner()
result = runner.invoke(cli, "-v info", obj=config, catch_exceptions=False)

assert result.exit_code == 0

assert config.configuration.verbose