Skip to content

Commit 51b63ee

Browse files
authored
Verbosity (#31)
1 parent 4c1f4ca commit 51b63ee

File tree

6 files changed

+91
-34
lines changed

6 files changed

+91
-34
lines changed

cppython/console.py

+31-23
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
from pathlib import Path
66
from typing import Type
7+
from xmlrpc.client import Boolean
78

89
import click
910
import tomlkit
1011
from cppython_core.schema import GeneratorDataType, Interface, PyProject
1112

12-
from cppython.project import Project
13+
from cppython.project import Project, ProjectConfiguration
1314

1415

1516
def _create_pyproject():
@@ -38,60 +39,67 @@ class Config:
3839
"""
3940

4041
def __init__(self):
41-
pyproject = _create_pyproject()
42+
self.pyproject = _create_pyproject()
43+
self.interface = ConsoleInterface()
44+
self.configuration = ProjectConfiguration()
4245

43-
# Initialize the object hook into CPPython
44-
interface = ConsoleInterface()
45-
46-
# Initialize the CPPython context
47-
self.project = Project(interface, pyproject)
46+
def create_project(self) -> Project:
47+
"""
48+
TODO
49+
"""
50+
return Project(self.configuration, self.interface, self.pyproject)
4851

4952

50-
pass_config = click.make_pass_decorator(Config)
53+
pass_config = click.make_pass_decorator(Config, ensure=True)
5154

5255

5356
@click.group()
54-
@click.pass_context
55-
def cli(context):
57+
@click.option("-v", "--verbose", is_flag=True, help="Print additional output")
58+
@pass_config
59+
def cli(config, verbose: Boolean):
5660
"""
5761
entry_point group for the CLI commands
5862
"""
59-
context.ensure_object(Config)
63+
config.configuration.verbose = verbose
6064

6165

6266
@cli.command()
6367
@pass_config
64-
def install(config):
68+
def info(config):
6569
"""
66-
Fulfills the 'install' API requirement
70+
TODO
6771
"""
68-
config.project.install()
72+
project = config.create_project()
6973

7074

7175
@cli.command()
7276
@pass_config
73-
def update(config):
77+
def install(config):
7478
"""
75-
Fulfills the 'update' API requirement
79+
TODO
7680
"""
77-
config.project.update()
81+
project = config.create_project()
82+
project.install()
7883

7984

8085
@cli.command()
8186
@pass_config
82-
def build(config):
87+
def update(config):
8388
"""
84-
Fulfills the 'build' API requirement
89+
TODO
8590
"""
86-
config.project.build()
91+
project = config.create_project()
92+
project.update()
8793

8894

89-
@cli.result_callback()
95+
@cli.command()
9096
@pass_config
91-
def cleanup(config, result):
97+
def build(config):
9298
"""
93-
Post-command cleanup
99+
TODO
94100
"""
101+
project = config.create_project()
102+
project.build()
95103

96104

97105
class ConsoleInterface(Interface):

cppython/plugins/__init__.py

-1
This file was deleted.

cppython/project.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,45 @@
22
The central delegation of the CPPython project
33
"""
44

5+
from dataclasses import dataclass
56
from importlib import metadata
67
from typing import Callable, Optional, Type, TypeVar
8+
from xmlrpc.client import Boolean
79

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

1113

14+
@dataclass
15+
class ProjectConfiguration:
16+
"""
17+
TODO
18+
"""
19+
20+
verbose: Boolean = False
21+
22+
1223
class Project(API):
1324
"""
1425
The object constructed at each entry_point
1526
"""
1627

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

1930
self.enabled = False
31+
self.verbose = configuration.verbose
32+
33+
if self.verbose:
34+
interface.print("Starting CPPython project initialization")
2035

2136
if pyproject.tool is None:
37+
if self.verbose:
38+
interface.print("Table [tool] is not defined")
2239
return
2340

2441
if pyproject.tool.cppython is None:
42+
if self.verbose:
43+
interface.print("Table [tool.cppython] is not defined")
2544
return
2645

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

75+
if self.verbose:
76+
interface.print("CPPython project initialized")
77+
5678
def download(self):
5779
"""
5880
Download the generator tooling if required
@@ -68,13 +90,19 @@ def download(self):
6890

6991
def install(self) -> None:
7092
if self.enabled:
93+
if self.verbose:
94+
self._interface.print("CPPython: Installing...")
7195
self.download()
7296
self._generator.install()
7397

7498
def update(self) -> None:
7599
if self.enabled:
100+
if self.verbose:
101+
self._interface.print("CPPython: Updating...")
76102
self._generator.update()
77103

78104
def build(self) -> None:
79105
if self.enabled:
106+
if self.verbose:
107+
self._interface.print("CPPython: Building...")
80108
self._generator.build()

pdm.lock

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ requires-python = ">=3.10"
1616
dependencies = [
1717
"click>=8.0.3",
1818
"tomlkit>=0.10.0",
19-
"cppython-core>=0.1.0",
19+
"cppython-core>=0.1.1",
2020
]
2121

2222
[project.license-files]

tests/unit/test_interface.py

+22
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from cppython.console import Config, ConsoleInterface, cli
1212
from cppython.data import default_pyproject
13+
from cppython.project import ProjectConfiguration
1314

1415

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

5657
assert result.exit_code == 0
5758
mocked_command.assert_called_once()
59+
60+
def test_config(self):
61+
"""
62+
TODO
63+
"""
64+
65+
Config()
66+
67+
def test_verbosity(self):
68+
"""
69+
TODO
70+
"""
71+
72+
config = Config()
73+
74+
runner = CliRunner()
75+
result = runner.invoke(cli, "-v info", obj=config, catch_exceptions=False)
76+
77+
assert result.exit_code == 0
78+
79+
assert config.configuration.verbose

0 commit comments

Comments
 (0)