Skip to content

Commit 9c02105

Browse files
committed
Split Generator Args
1 parent c182d6d commit 9c02105

File tree

4 files changed

+115
-79
lines changed

4 files changed

+115
-79
lines changed

cppython/project.py

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
from cppython_core.core import cppython_logger
1010
from cppython_core.schema import (
11+
PEP621,
1112
CPPythonData,
13+
CPPythonDataT,
1214
Generator,
1315
GeneratorConfiguration,
1416
Interface,
@@ -73,17 +75,41 @@ def generate_model(self, plugins: list[Type[Generator]]) -> Type[PyProject]:
7375
)
7476

7577
def create_generators(
76-
self, plugins: list[Type[Generator]], configuration: GeneratorConfiguration, pyproject: PyProject
78+
self,
79+
plugins: list[Type[Generator]],
80+
configuration: GeneratorConfiguration,
81+
project: PEP621,
82+
cppython: CPPythonData,
7783
) -> list[Generator]:
7884
"""
7985
TODO
8086
"""
8187
_generators = []
8288
for plugin_type in plugins:
83-
_generators.append(plugin_type(configuration, pyproject))
89+
_generators.append(plugin_type(configuration, project, cppython))
8490

8591
return _generators
8692

93+
def generate_modified(self, original: CPPythonDataT) -> CPPythonDataT:
94+
"""
95+
Applies dynamic behaviors of the settings to itself
96+
Returns a copy of the original with dynamic modifications
97+
"""
98+
modified = original.copy(deep=True)
99+
100+
# Add the pyproject.toml location to all relative paths
101+
102+
if not modified.install_path.is_absolute():
103+
modified.install_path = self.configuration.root_path.absolute() / modified.install_path
104+
105+
if not modified.tool_path.is_absolute():
106+
modified.tool_path = self.configuration.root_path.absolute() / modified.tool_path
107+
108+
if not modified.build_path.is_absolute():
109+
modified.build_path = self.configuration.root_path.absolute() / modified.build_path
110+
111+
return modified
112+
87113

88114
class Project(API):
89115
"""
@@ -96,7 +122,6 @@ def __init__(
96122

97123
self._enabled = False
98124
self._configuration = configuration
99-
self._pyproject = None
100125

101126
levels = [logging.WARNING, logging.INFO, logging.DEBUG]
102127

@@ -118,26 +143,30 @@ def __init__(
118143
cppython_logger.warning(f"Generator plugin found: {plugin.name()}")
119144

120145
extended_pyproject_type = builder.generate_model(plugins)
121-
self._pyproject = extended_pyproject_type(**pyproject_data)
146+
pyproject = extended_pyproject_type(**pyproject_data)
122147

123-
if self.pyproject is None:
148+
if pyproject is None:
124149
cppython_logger.error("Data is not defined")
125150
return
126151

127-
if self.pyproject.tool is None:
152+
if pyproject.tool is None:
128153
cppython_logger.error("Table [tool] is not defined")
129154
return
130155

131-
if self.pyproject.tool.cppython is None:
156+
if pyproject.tool.cppython is None:
132157
cppython_logger.error("Table [tool.cppython] is not defined")
133158
return
134159

135160
self._enabled = True
136161

162+
self._project = pyproject.project
163+
164+
self._modified_cppython_data = builder.generate_modified(pyproject.tool.cppython)
165+
137166
self._interface = interface
138167

139168
generator_configuration = GeneratorConfiguration()
140-
self._generators = builder.create_generators(plugins, generator_configuration, self.pyproject)
169+
self._generators = builder.create_generators(plugins, generator_configuration, self.project, self.cppython)
141170

142171
cppython_logger.info("Initialized project successfully")
143172

@@ -156,11 +185,18 @@ def configuration(self) -> ProjectConfiguration:
156185
return self._configuration
157186

158187
@property
159-
def pyproject(self) -> PyProject | None:
188+
def project(self):
160189
"""
161-
TODO
190+
The pyproject project table
191+
"""
192+
return self._project
193+
194+
@property
195+
def cppython(self):
196+
"""
197+
The resolved CPPython data
162198
"""
163-
return self._pyproject
199+
return self._modified_cppython_data
164200

165201
def download(self):
166202
"""
@@ -170,7 +206,7 @@ def download(self):
170206
cppython_logger.info("Skipping download because the project is not enabled")
171207
return
172208

173-
base_path = self.pyproject.tool.cppython.install_path
209+
base_path = self.cppython.install_path
174210

175211
for generator in self._generators:
176212

@@ -199,7 +235,7 @@ def install(self) -> None:
199235
cppython_logger.info("Installing project")
200236
self.download()
201237

202-
tool_path = self.pyproject.tool.cppython.tool_path
238+
tool_path = self.cppython.tool_path
203239
tool_path.mkdir(parents=True, exist_ok=True)
204240

205241
generator_output = []
@@ -227,7 +263,7 @@ def update(self) -> None:
227263

228264
cppython_logger.info("Updating project")
229265

230-
tool_path = self.pyproject.tool.cppython.tool_path
266+
tool_path = self.cppython.tool_path
231267
tool_path.mkdir(parents=True, exist_ok=True)
232268

233269
generator_output = []

cppython/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class ConfigurePreset(Preset):
3232
toolchainFile: Optional[str]
3333

3434
@validator("toolchainFile")
35-
def validate_path(cls, v):
35+
def validate_path(cls, value): # pylint: disable=E0213
3636
"""
3737
TODO
3838
"""
39-
return Path(v).as_posix()
39+
return Path(value).as_posix()
4040

4141

4242
class BuildPreset(Preset):

0 commit comments

Comments
 (0)