Skip to content

Commit f0d57d1

Browse files
authored
Remove PyProject From Interface __init__ (#24)
The `PyProject` data object was stored alongside the interface class, an unnecessary restriction that prevented deferred `PyProject` creation with no benefit.
1 parent aedc1dc commit f0d57d1

File tree

9 files changed

+79
-117
lines changed

9 files changed

+79
-117
lines changed

.github/workflows/draft.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

cppython/plugins/interface/console.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import tomlkit
1010

1111
from cppython.project import Project
12-
from cppython.schema import GeneratorData, GeneratorDataType, Interface, PyProject
12+
from cppython.schema import GeneratorDataType, Interface, PyProject
1313

1414

1515
def _create_pyproject():
@@ -41,10 +41,10 @@ def __init__(self):
4141
pyproject = _create_pyproject()
4242

4343
# Initialize the object hook into CPPython
44-
interface = ConsoleInterface(pyproject)
44+
interface = ConsoleInterface()
4545

4646
# Initialize the CPPython context
47-
self.project = Project(interface)
47+
self.project = Project(interface, pyproject)
4848

4949

5050
pass_config = click.make_pass_decorator(Config)

cppython/plugins/test/pytest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
from cppython.plugins.test.data import default_pyproject
1011
from cppython.project import Project
1112
from cppython.schema import Generator, Interface
1213

@@ -32,7 +33,7 @@ class GeneratorIntegrationTests(GeneratorTests):
3233

3334
def test_plugin_registration(self, generator: Generator):
3435
"""
35-
TODO
36+
Test the registration with setuptools entry_points
3637
"""
3738
plugin_entries = entry_points(group=f"cppython.{generator.plugin_group()}")
3839
assert len(plugin_entries) > 0
@@ -86,7 +87,7 @@ def test_project(self, interface: Interface):
8687
"""
8788
Test that the project can be constructed from the given interface
8889
"""
89-
Project(interface)
90+
Project(interface, default_pyproject)
9091

9192

9293
class InterfaceUnitTests(InterfaceTests):

cppython/project.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from typing import Callable, Optional, Type, TypeVar
77

88
from cppython.exceptions import ConfigError
9-
from cppython.schema import API, Generator, Interface, Plugin
9+
from cppython.schema import API, Generator, Interface, Plugin, PyProject
1010

1111

1212
class Project(API):
1313
"""
1414
The object constructed at each entry_point
1515
"""
1616

17-
def __init__(self, interface: Interface) -> None:
17+
def __init__(self, interface: Interface, pyproject: PyProject) -> None:
1818

1919
self._interface = interface
2020

@@ -35,15 +35,13 @@ def find_plugin_type(plugin_type: PluginType, condition: Callable[[str], bool])
3535

3636
return None
3737

38-
plugin_type = find_plugin_type(Generator, lambda name: name == interface.pyproject.cppython_data.generator)
38+
plugin_type = find_plugin_type(Generator, lambda name: name == pyproject.cppython_data.generator)
3939

4040
if plugin_type is None:
41-
raise ConfigError(
42-
f"No generator plugin with the name '{interface.pyproject.cppython_data.generator}' was found."
43-
)
41+
raise ConfigError(f"No generator plugin with the name '{pyproject.cppython_data.generator}' was found.")
4442

4543
generator_data = interface.read_generator_data(plugin_type.data_type())
46-
self._generator = plugin_type(interface.pyproject, generator_data)
44+
self._generator = plugin_type(pyproject, generator_data)
4745
self._generator.install_generator()
4846

4947
# API Contract

cppython/schema.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ class Plugin(ABC):
9393
Abstract plugin type
9494
"""
9595

96-
@abstractmethod
97-
def __init__(self) -> None:
98-
pass
99-
10096
@staticmethod
10197
@abstractmethod
10298
def plugin_group() -> str:
@@ -120,26 +116,6 @@ class Interface:
120116
Abstract type to be inherited by CPPython interfaces
121117
"""
122118

123-
def __init__(self, pyproject: PyProject) -> None:
124-
super().__init__()
125-
126-
self.pyproject = pyproject
127-
128-
@property
129-
def pyproject(self) -> PyProject:
130-
"""
131-
PyProject getter
132-
"""
133-
return self._pyproject
134-
135-
@pyproject.setter
136-
def pyproject(self, value: PyProject):
137-
"""
138-
PyProject setter
139-
"""
140-
141-
self._pyproject = value
142-
143119
@abstractmethod
144120
def read_generator_data(self, generator_data_type: Type[GeneratorDataType]) -> GeneratorDataType:
145121
"""
@@ -194,3 +170,4 @@ def install_generator(self) -> bool:
194170
Installs the external tooling required by the generator if necessary
195171
Returns whether anything was installed or not
196172
"""
173+
raise NotImplementedError()

pdm.lock

Lines changed: 65 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ cppython = "cppython.plugins.interface.console:cli"
4646
[project.entry-points."cppython.generator_plugins"]
4747
cmake = "cppython.plugins.generator.cmake:CMakeGenerator"
4848

49-
[project.entry-points."cppython.interface_plugins"]
50-
console = "cppython.plugins.interface.console:ConsoleInterface"
51-
5249
# Pytest plugins
5350
[tool.entry-points.pytest11]
5451
pytest_cppython = "cppython.plugins.test.pytest"

tests/integration/test_interface.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66

77
from cppython.plugins.interface.console import ConsoleInterface
8-
from cppython.plugins.test.data import default_pyproject
98
from cppython.plugins.test.pytest import InterfaceIntegrationTests
109

1110

@@ -22,4 +21,4 @@ def fixture_interface(self):
2221
Returns:
2322
ConsoleInterface -- The Interface object to use for the CPPython defined tests
2423
"""
25-
return ConsoleInterface(default_pyproject)
24+
return ConsoleInterface()

tests/unit/test_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def fixture_interface(self) -> ConsoleInterface:
2525
Returns:
2626
ConsoleInterface -- The Interface object to use for the CPPython defined tests
2727
"""
28-
return ConsoleInterface(default_pyproject)
28+
return ConsoleInterface()
2929

3030
# Grab the API methods and parameterize them for automatic testing of the entry_points
3131
method_list = [func for func in dir(API) if callable(getattr(API, func)) and not func.startswith("__")]

0 commit comments

Comments
 (0)