Skip to content

Commit 78ca645

Browse files
authored
Decompose Into Plugins (#13)
Break apart the codebase into plugins.
1 parent 12ca107 commit 78ca645

26 files changed

+1010
-1333
lines changed

.github/pr-labeler.yml

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

.github/release-drafter.yml

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

.github/workflows/pr-check.yml

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

.github/workflows/publish.yml

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

.github/workflows/push-development.yml

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

.github/workflows/push-release.yml

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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Poetic Conan
2-
A Plugin for Poetry that enables a transparent Conan and CMake workflow.
1+
# CPPython
2+
A library for managing dependencies with CMake for C++ projects.

cppython/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


cppython/exceptions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Custom exceptions used by CPPython
3+
"""
4+
5+
class ConfigError(Exception):
6+
def __init__(self, error: Exception) -> None:
7+
self._error = error
8+
9+
super().__init__(str(error))
10+
11+
@property
12+
def error(self) -> Exception:
13+
return self._error

cppython/plugins/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


cppython/plugins/generator/cmake.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from cppython.schema import Generator, Metadata
2+
3+
4+
class CMakeGenerator(Generator):
5+
"""
6+
A CPPython generator implementing a CMake backend
7+
"""
8+
9+
def __init__(self) -> None:
10+
pass
11+
12+
"""
13+
Plugin Contract
14+
"""
15+
16+
@staticmethod
17+
def name() -> str:
18+
"""
19+
The name of the generator
20+
"""
21+
return "cmake"
22+
23+
"""
24+
Generator Contract
25+
"""
26+
27+
def populate_metadata(self, data: dict):
28+
"""
29+
data - The CPPoetry data taken from pyproject.toml
30+
"""
31+
pass
32+
33+
def populate_plugin(self, data: dict):
34+
"""
35+
data - The data taken from pyproject.toml that belongs to this generator
36+
"""
37+
pass
38+
39+
"""
40+
API Contract
41+
"""
42+
43+
def install(self) -> None:
44+
raise NotImplementedError()
45+
46+
def update(self) -> None:
47+
raise NotImplementedError()
48+
49+
def build(self) -> None:
50+
raise NotImplementedError()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


cppython/plugins/interface/console.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
from cppython.project import Project
2+
from cppython.schema import Interface, PEP621
3+
from pathlib import Path
4+
5+
import click
6+
import tomlkit
7+
8+
9+
def _read_data():
10+
path = Path.cwd()
11+
12+
while not path.glob("pyproject.toml"):
13+
if path.is_absolute():
14+
assert (
15+
"This is not a valid project. No pyproject.toml found in the current directory or any of its parents."
16+
)
17+
18+
return tomlkit.loads(Path(path / "pyproject.toml").read_text(encoding="utf-8"))
19+
20+
21+
class Config(object):
22+
"""
23+
The data object that will be expanded alongside 'pass_obj'
24+
"""
25+
26+
def __init__(self):
27+
28+
data = _read_data()
29+
30+
# Initialize the object hook into CPPython
31+
interface = ConsoleInterface(data)
32+
33+
# Initialize the CPPython context
34+
self.project = Project(interface)
35+
36+
def load(self):
37+
self.project.load()
38+
39+
40+
pass_config = click.make_pass_decorator(Config)
41+
42+
43+
@click.group()
44+
@click.pass_context
45+
def cli(context):
46+
context.ensure_object(Config)
47+
48+
# Initialize cppython
49+
context.obj.load()
50+
51+
52+
@cli.command()
53+
@pass_config
54+
def install(config):
55+
config.project.install()
56+
57+
58+
@cli.command()
59+
@pass_config
60+
def update(config):
61+
config.project.update()
62+
63+
64+
@cli.result_callback()
65+
@pass_config
66+
def cleanup(config, result):
67+
pass
68+
69+
70+
class ConsoleInterface(Interface):
71+
"""
72+
TODO: Description
73+
"""
74+
75+
def __init__(self, data: dict) -> None:
76+
self._data = data
77+
78+
"""
79+
Plugin Contract
80+
"""
81+
82+
@staticmethod
83+
def name() -> str:
84+
"""
85+
The name of the generator
86+
"""
87+
return "console"
88+
89+
"""
90+
Interface Contract
91+
"""
92+
93+
@staticmethod
94+
def external_config() -> bool:
95+
"""
96+
True if the plugin can read its own configuration.
97+
False otherwise
98+
"""
99+
100+
return False
101+
102+
@staticmethod
103+
def parse_pep_621(data: dict) -> PEP621:
104+
"""
105+
Requests the plugin to read the available PEP 621 information. Only requested if the plugin is not the entrypoint
106+
"""
107+
raise NotImplementedError()
108+
109+
def pep_621(self) -> PEP621:
110+
"""
111+
Requests PEP 621 information from the pyproject
112+
"""
113+
return self.parse_pep_621(self._data)
114+
115+
def write_pyproject(self) -> None:
116+
raise NotImplementedError()
117+
118+
def read_pyproject(self) -> dict:
119+
return self._data

cppython/plugins/test/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


0 commit comments

Comments
 (0)