-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata.py
More file actions
105 lines (78 loc) · 3.66 KB
/
data.py
File metadata and controls
105 lines (78 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""Defines the post-construction data management for CPPython"""
from dataclasses import dataclass
from logging import Logger
from packaging.requirements import Requirement
from cppython.core.plugin_schema.generator import Generator
from cppython.core.plugin_schema.provider import Provider
from cppython.core.plugin_schema.scm import SCM
from cppython.core.schema import CoreData
from cppython.utility.exception import PluginError
@dataclass
class Plugins:
"""The plugin data for CPPython"""
generator: Generator
provider: Provider
scm: SCM
class Data:
"""Contains and manages the project data"""
def __init__(self, core_data: CoreData, plugins: Plugins, logger: Logger) -> None:
"""Initializes the data"""
self._core_data = core_data
self._plugins = plugins
self.logger = logger
self._active_groups: list[str] | None = None
@property
def plugins(self) -> Plugins:
"""The plugin data for CPPython"""
return self._plugins
def set_active_groups(self, groups: list[str] | None) -> None:
"""Set the active dependency groups for the current operation.
Args:
groups: List of group names to activate, or None for no additional groups
"""
self._active_groups = groups
if groups:
self.logger.info('Active dependency groups: %s', ', '.join(groups))
# Validate that requested groups exist
available_groups = set(self._core_data.cppython_data.dependency_groups.keys())
requested_groups = set(groups)
missing_groups = requested_groups - available_groups
if missing_groups:
self.logger.warning(
'Requested dependency groups not found: %s. Available groups: %s',
', '.join(sorted(missing_groups)),
', '.join(sorted(available_groups)) if available_groups else 'none',
)
def apply_dependency_groups(self, groups: list[str] | None) -> None:
"""Validate and log the dependency groups to be used.
Args:
groups: List of group names to apply, or None for base dependencies only
"""
if groups:
self.set_active_groups(groups)
def get_active_dependencies(self) -> list:
"""Get the combined list of base dependencies and active group dependencies.
Returns:
Combined list of Requirement objects from base and active groups
"""
dependencies: list[Requirement] = list(self._core_data.cppython_data.dependencies)
if self._active_groups:
for group_name in self._active_groups:
if group_name in self._core_data.cppython_data.dependency_groups:
dependencies.extend(self._core_data.cppython_data.dependency_groups[group_name])
return dependencies
def sync(self) -> None:
"""Gathers sync information from providers and passes it to the generator
Raises:
PluginError: Plugin error
"""
if (sync_data := self.plugins.provider.sync_data(self.plugins.generator)) is None:
raise PluginError("The provider doesn't support the generator")
self.plugins.generator.sync(sync_data)
async def download_provider_tools(self) -> None:
"""Download the provider tooling if required"""
base_path = self._core_data.cppython_data.install_path
path = base_path / self.plugins.provider.name()
path.mkdir(parents=True, exist_ok=True)
self.logger.warning('Downloading the %s requirements to %s', self.plugins.provider.name(), path)
await self.plugins.provider.download_tooling(path)