Skip to content

Commit 27aa21b

Browse files
authored
Merge Repositories (#110)
All plugins, test plugins, and schemas are now housed in a single repository using optional dependencies.
1 parent 43b613e commit 27aa21b

File tree

101 files changed

+5749
-865
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+5749
-865
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ __pypackages__/
2323
!.vscode/settings.json
2424
!.vscode/tasks.json
2525
!.vscode/launch.json
26-
!.vscode/extensions.json
26+
!.vscode/extensions.json
27+
/.mypy_cache
28+
node_modules/
29+
build/

.vscode/extensions.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"recommendations": [
33
"ms-python.mypy-type-checker",
4-
"ms-python.pylint",
5-
"ms-python.black-formatter"
4+
"ms-python.black-formatter",
5+
"asciidoctor.asciidoctor-vscode",
6+
"charliermarsh.ruff"
67
]
78
}

cppython/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-

1+
"""The CPPython project.
2+
3+
This module serves as the entry point for the CPPython project, a Python-based
4+
solution for managing C++ dependencies. It includes core functionality, plugin
5+
interfaces, and utility functions that facilitate the integration and management
6+
of various tools and systems.
7+
"""

cppython/builder.py

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
"""Defines the data and routines for building a CPPython project type"""
22

33
import logging
4-
from importlib import metadata
4+
from importlib.metadata import entry_points
55
from inspect import getmodule
66
from logging import Logger
77
from typing import Any
88

9-
from cppython_core.exceptions import PluginError
10-
from cppython_core.plugin_schema.generator import Generator
11-
from cppython_core.plugin_schema.provider import Provider
12-
from cppython_core.plugin_schema.scm import SCM
13-
from cppython_core.resolution import (
9+
from cppython.core.plugin_schema.generator import Generator
10+
from cppython.core.plugin_schema.provider import Provider
11+
from cppython.core.plugin_schema.scm import SCM
12+
from cppython.core.resolution import (
1413
PluginBuildData,
1514
PluginCPPythonData,
1615
resolve_cppython,
@@ -21,7 +20,7 @@
2120
resolve_provider,
2221
resolve_scm,
2322
)
24-
from cppython_core.schema import (
23+
from cppython.core.schema import (
2524
CoreData,
2625
CorePluginData,
2726
CPPythonGlobalConfiguration,
@@ -32,15 +31,16 @@
3231
ProjectConfiguration,
3332
ProjectData,
3433
)
35-
3634
from cppython.data import Data, Plugins
35+
from cppython.defaults import DefaultSCM
36+
from cppython.utility.exception import PluginError
3737

3838

3939
class Resolver:
4040
"""The resolution of data sources for the builder"""
4141

4242
def __init__(self, project_configuration: ProjectConfiguration, logger: Logger) -> None:
43-
43+
"""Initializes the resolver"""
4444
self._project_configuration = project_configuration
4545
self._logger = logger
4646

@@ -56,19 +56,18 @@ def generate_plugins(
5656
Returns:
5757
The resolved plugin data
5858
"""
59-
6059
raw_generator_plugins = self.find_generators()
6160
generator_plugins = self.filter_plugins(
6261
raw_generator_plugins,
6362
cppython_local_configuration.generator_name,
64-
"Generator",
63+
'Generator',
6564
)
6665

6766
raw_provider_plugins = self.find_providers()
6867
provider_plugins = self.filter_plugins(
6968
raw_provider_plugins,
7069
cppython_local_configuration.provider_name,
71-
"Provider",
70+
'Provider',
7271
)
7372

7473
scm_plugins = self.find_source_managers()
@@ -80,7 +79,8 @@ def generate_plugins(
8079

8180
return PluginBuildData(generator_type=generator_type, provider_type=provider_type, scm_type=scm_type)
8281

83-
def generate_cppython_plugin_data(self, plugin_build_data: PluginBuildData) -> PluginCPPythonData:
82+
@staticmethod
83+
def generate_cppython_plugin_data(plugin_build_data: PluginBuildData) -> PluginCPPythonData:
8484
"""Generates the CPPython plugin data from the resolved plugins
8585
8686
Args:
@@ -89,15 +89,15 @@ def generate_cppython_plugin_data(self, plugin_build_data: PluginBuildData) -> P
8989
Returns:
9090
The plugin data used by CPPython
9191
"""
92-
9392
return PluginCPPythonData(
9493
generator_name=plugin_build_data.generator_type.name(),
9594
provider_name=plugin_build_data.provider_type.name(),
9695
scm_name=plugin_build_data.scm_type.name(),
9796
)
9897

98+
@staticmethod
9999
def generate_pep621_data(
100-
self, pep621_configuration: PEP621Configuration, project_configuration: ProjectConfiguration, scm: SCM | None
100+
pep621_configuration: PEP621Configuration, project_configuration: ProjectConfiguration, scm: SCM | None
101101
) -> PEP621Data:
102102
"""Generates the PEP621 data from configuration sources
103103
@@ -111,13 +111,13 @@ def generate_pep621_data(
111111
"""
112112
return resolve_pep621(pep621_configuration, project_configuration, scm)
113113

114-
def resolve_global_config(self) -> CPPythonGlobalConfiguration:
114+
@staticmethod
115+
def resolve_global_config() -> CPPythonGlobalConfiguration:
115116
"""Generates the global configuration object
116117
117118
Returns:
118119
The global configuration object
119120
"""
120-
121121
return CPPythonGlobalConfiguration()
122122

123123
def find_generators(self) -> list[type[Generator]]:
@@ -129,24 +129,23 @@ def find_generators(self) -> list[type[Generator]]:
129129
Returns:
130130
The list of generator plugin types
131131
"""
132-
133-
group_name = "generator"
132+
group_name = 'generator'
134133
plugin_types: list[type[Generator]] = []
135134

136135
# Filter entries by type
137-
for entry_point in list(metadata.entry_points(group=f"cppython.{group_name}")):
136+
for entry_point in list(entry_points(group=f'cppython.{group_name}')):
138137
loaded_type = entry_point.load()
139138
if not issubclass(loaded_type, Generator):
140139
self._logger.warning(
141140
f"Found incompatible plugin. The '{loaded_type.name()}' plugin must be an instance of"
142141
f" '{group_name}'"
143142
)
144143
else:
145-
self._logger.warning(f"{group_name} plugin found: {loaded_type.name()} from {getmodule(loaded_type)}")
144+
self._logger.warning(f'{group_name} plugin found: {loaded_type.name()} from {getmodule(loaded_type)}')
146145
plugin_types.append(loaded_type)
147146

148147
if not plugin_types:
149-
raise PluginError(f"No {group_name} plugin was found")
148+
raise PluginError(f'No {group_name} plugin was found')
150149

151150
return plugin_types
152151

@@ -159,24 +158,23 @@ def find_providers(self) -> list[type[Provider]]:
159158
Returns:
160159
The list of provider plugin types
161160
"""
162-
163-
group_name = "provider"
161+
group_name = 'provider'
164162
plugin_types: list[type[Provider]] = []
165163

166164
# Filter entries by type
167-
for entry_point in list(metadata.entry_points(group=f"cppython.{group_name}")):
165+
for entry_point in list(entry_points(group=f'cppython.{group_name}')):
168166
loaded_type = entry_point.load()
169167
if not issubclass(loaded_type, Provider):
170168
self._logger.warning(
171169
f"Found incompatible plugin. The '{loaded_type.name()}' plugin must be an instance of"
172170
f" '{group_name}'"
173171
)
174172
else:
175-
self._logger.warning(f"{group_name} plugin found: {loaded_type.name()} from {getmodule(loaded_type)}")
173+
self._logger.warning(f'{group_name} plugin found: {loaded_type.name()} from {getmodule(loaded_type)}')
176174
plugin_types.append(loaded_type)
177175

178176
if not plugin_types:
179-
raise PluginError(f"No {group_name} plugin was found")
177+
raise PluginError(f'No {group_name} plugin was found')
180178

181179
return plugin_types
182180

@@ -189,30 +187,29 @@ def find_source_managers(self) -> list[type[SCM]]:
189187
Returns:
190188
The list of source control manager plugin types
191189
"""
192-
193-
group_name = "scm"
190+
group_name = 'scm'
194191
plugin_types: list[type[SCM]] = []
195192

196193
# Filter entries by type
197-
for entry_point in list(metadata.entry_points(group=f"cppython.{group_name}")):
194+
for entry_point in list(entry_points(group=f'cppython.{group_name}')):
198195
loaded_type = entry_point.load()
199196
if not issubclass(loaded_type, SCM):
200197
self._logger.warning(
201198
f"Found incompatible plugin. The '{loaded_type.name()}' plugin must be an instance of"
202199
f" '{group_name}'"
203200
)
204201
else:
205-
self._logger.warning(f"{group_name} plugin found: {loaded_type.name()} from {getmodule(loaded_type)}")
202+
self._logger.warning(f'{group_name} plugin found: {loaded_type.name()} from {getmodule(loaded_type)}')
206203
plugin_types.append(loaded_type)
207204

208205
if not plugin_types:
209-
raise PluginError(f"No {group_name} plugin was found")
206+
raise PluginError(f'No {group_name} plugin was found')
210207

211208
return plugin_types
212209

213-
def filter_plugins[
214-
T: DataPlugin
215-
](self, plugin_types: list[type[T]], pinned_name: str | None, group_name: str) -> list[type[T]]:
210+
def filter_plugins[T: DataPlugin](
211+
self, plugin_types: list[type[T]], pinned_name: str | None, group_name: str
212+
) -> list[type[T]]:
216213
"""Finds and filters data plugins
217214
218215
Args:
@@ -226,13 +223,12 @@ def filter_plugins[
226223
Returns:
227224
The list of applicable plugins
228225
"""
229-
230226
# Lookup the requested plugin if given
231227
if pinned_name is not None:
232228
for loaded_type in plugin_types:
233229
if loaded_type.name() == pinned_name:
234230
self._logger.warning(
235-
f"Using {group_name} plugin: {loaded_type.name()} from {getmodule(loaded_type)}"
231+
f'Using {group_name} plugin: {loaded_type.name()} from {getmodule(loaded_type)}'
236232
)
237233
return [loaded_type]
238234

@@ -243,13 +239,13 @@ def filter_plugins[
243239
# Deduce types
244240
for loaded_type in plugin_types:
245241
self._logger.warning(
246-
f"A {group_name} plugin is supported: {loaded_type.name()} from {getmodule(loaded_type)}"
242+
f'A {group_name} plugin is supported: {loaded_type.name()} from {getmodule(loaded_type)}'
247243
)
248244
supported_types.append(loaded_type)
249245

250246
# Fail
251247
if supported_types is None:
252-
raise PluginError(f"No {group_name} could be deduced from the root directory.")
248+
raise PluginError(f'No {group_name} could be deduced from the root directory.')
253249

254250
return supported_types
255251

@@ -260,21 +256,20 @@ def select_scm(self, scm_plugins: list[type[SCM]], project_data: ProjectData) ->
260256
scm_plugins: The list of SCM plugin types
261257
project_data: The project data
262258
263-
Raises:
264-
PluginError: Raised if no SCM plugin was found that supports the given data
265-
266259
Returns:
267260
The selected SCM plugin type
268261
"""
269-
270262
for scm_type in scm_plugins:
271263
if scm_type.features(project_data.pyproject_file.parent).repository:
272264
return scm_type
273265

274-
raise PluginError("No SCM plugin was found that supports the given path")
266+
self._logger.info('No SCM plugin was found that supports the given path')
267+
268+
return DefaultSCM
275269

270+
@staticmethod
276271
def solve(
277-
self, generator_types: list[type[Generator]], provider_types: list[type[Provider]]
272+
generator_types: list[type[Generator]], provider_types: list[type[Provider]]
278273
) -> tuple[type[Generator], type[Provider]]:
279274
"""Selects the first generator and provider that can work together
280275
@@ -288,7 +283,6 @@ def solve(
288283
Returns:
289284
A tuple of the selected generator and provider plugin types
290285
"""
291-
292286
combos: list[tuple[type[Generator], type[Provider]]] = []
293287

294288
for generator_type in generator_types:
@@ -300,12 +294,12 @@ def solve(
300294
break
301295

302296
if not combos:
303-
raise PluginError("No provider that supports a given generator could be deduced")
297+
raise PluginError('No provider that supports a given generator could be deduced')
304298

305299
return combos[0]
306300

301+
@staticmethod
307302
def create_scm(
308-
self,
309303
core_data: CoreData,
310304
scm_type: type[SCM],
311305
) -> SCM:
@@ -318,7 +312,6 @@ def create_scm(
318312
Returns:
319313
The constructed source control manager
320314
"""
321-
322315
cppython_plugin_data = resolve_cppython_plugin(core_data.cppython_data, scm_type)
323316
scm_data = resolve_scm(core_data.project_data, cppython_plugin_data)
324317

@@ -344,7 +337,6 @@ def create_generator(
344337
Returns:
345338
The constructed generator
346339
"""
347-
348340
cppython_plugin_data = resolve_cppython_plugin(core_data.cppython_data, generator_type)
349341

350342
generator_data = resolve_generator(core_data.project_data, cppython_plugin_data)
@@ -380,7 +372,6 @@ def create_provider(
380372
Returns:
381373
A constructed provider plugins
382374
"""
383-
384375
cppython_plugin_data = resolve_cppython_plugin(core_data.cppython_data, provider_type)
385376

386377
provider_data = resolve_provider(core_data.project_data, cppython_plugin_data)
@@ -403,6 +394,7 @@ class Builder:
403394
"""Helper class for building CPPython projects"""
404395

405396
def __init__(self, project_configuration: ProjectConfiguration, logger: Logger) -> None:
397+
"""Initializes the builder"""
406398
self._project_configuration = project_configuration
407399
self._logger = logger
408400

@@ -413,7 +405,7 @@ def __init__(self, project_configuration: ProjectConfiguration, logger: Logger)
413405
self._logger.addHandler(logging.StreamHandler())
414406
self._logger.setLevel(levels[project_configuration.verbosity])
415407

416-
self._logger.info("Logging setup complete")
408+
self._logger.info('Logging setup complete')
417409

418410
self._resolver = Resolver(self._project_configuration, self._logger)
419411

@@ -428,12 +420,12 @@ def build(
428420
Args:
429421
pep621_configuration: The PEP621 configuration
430422
cppython_local_configuration: The local configuration
431-
plugin_build_data: Plugin override data. If it exists, the build will use the given types instead of resolving them
423+
plugin_build_data: Plugin override data. If it exists, the build will use the given types
424+
instead of resolving them
432425
433426
Returns:
434427
The built data object
435428
"""
436-
437429
project_data = resolve_project_configuration(self._project_configuration)
438430

439431
if plugin_build_data is None:

cppython/console/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-

1+
"""Console interface for the CPPython project.
2+
3+
This module provides a command-line interface (CLI) for interacting with the
4+
CPPython project. It includes commands for managing project configurations,
5+
installing dependencies, and updating project data.
6+
"""

0 commit comments

Comments
 (0)