8
8
9
9
from cppython_core .core import cppython_logger
10
10
from cppython_core .schema import (
11
+ PEP621 ,
11
12
CPPythonData ,
13
+ CPPythonDataT ,
12
14
Generator ,
13
15
GeneratorConfiguration ,
14
16
Interface ,
@@ -73,17 +75,41 @@ def generate_model(self, plugins: list[Type[Generator]]) -> Type[PyProject]:
73
75
)
74
76
75
77
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 ,
77
83
) -> list [Generator ]:
78
84
"""
79
85
TODO
80
86
"""
81
87
_generators = []
82
88
for plugin_type in plugins :
83
- _generators .append (plugin_type (configuration , pyproject ))
89
+ _generators .append (plugin_type (configuration , project , cppython ))
84
90
85
91
return _generators
86
92
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
+
87
113
88
114
class Project (API ):
89
115
"""
@@ -96,7 +122,6 @@ def __init__(
96
122
97
123
self ._enabled = False
98
124
self ._configuration = configuration
99
- self ._pyproject = None
100
125
101
126
levels = [logging .WARNING , logging .INFO , logging .DEBUG ]
102
127
@@ -118,26 +143,30 @@ def __init__(
118
143
cppython_logger .warning (f"Generator plugin found: { plugin .name ()} " )
119
144
120
145
extended_pyproject_type = builder .generate_model (plugins )
121
- self . _pyproject = extended_pyproject_type (** pyproject_data )
146
+ pyproject = extended_pyproject_type (** pyproject_data )
122
147
123
- if self . pyproject is None :
148
+ if pyproject is None :
124
149
cppython_logger .error ("Data is not defined" )
125
150
return
126
151
127
- if self . pyproject .tool is None :
152
+ if pyproject .tool is None :
128
153
cppython_logger .error ("Table [tool] is not defined" )
129
154
return
130
155
131
- if self . pyproject .tool .cppython is None :
156
+ if pyproject .tool .cppython is None :
132
157
cppython_logger .error ("Table [tool.cppython] is not defined" )
133
158
return
134
159
135
160
self ._enabled = True
136
161
162
+ self ._project = pyproject .project
163
+
164
+ self ._modified_cppython_data = builder .generate_modified (pyproject .tool .cppython )
165
+
137
166
self ._interface = interface
138
167
139
168
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 )
141
170
142
171
cppython_logger .info ("Initialized project successfully" )
143
172
@@ -156,11 +185,18 @@ def configuration(self) -> ProjectConfiguration:
156
185
return self ._configuration
157
186
158
187
@property
159
- def pyproject (self ) -> PyProject | None :
188
+ def project (self ):
160
189
"""
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
162
198
"""
163
- return self ._pyproject
199
+ return self ._modified_cppython_data
164
200
165
201
def download (self ):
166
202
"""
@@ -170,7 +206,7 @@ def download(self):
170
206
cppython_logger .info ("Skipping download because the project is not enabled" )
171
207
return
172
208
173
- base_path = self .pyproject . tool . cppython .install_path
209
+ base_path = self .cppython .install_path
174
210
175
211
for generator in self ._generators :
176
212
@@ -199,7 +235,7 @@ def install(self) -> None:
199
235
cppython_logger .info ("Installing project" )
200
236
self .download ()
201
237
202
- tool_path = self .pyproject . tool . cppython .tool_path
238
+ tool_path = self .cppython .tool_path
203
239
tool_path .mkdir (parents = True , exist_ok = True )
204
240
205
241
generator_output = []
@@ -227,7 +263,7 @@ def update(self) -> None:
227
263
228
264
cppython_logger .info ("Updating project" )
229
265
230
- tool_path = self .pyproject . tool . cppython .tool_path
266
+ tool_path = self .cppython .tool_path
231
267
tool_path .mkdir (parents = True , exist_ok = True )
232
268
233
269
generator_output = []
0 commit comments