forked from synodic/cppython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
115 lines (84 loc) · 3.79 KB
/
project.py
File metadata and controls
115 lines (84 loc) · 3.79 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
106
107
108
109
110
111
112
113
114
115
"""Manages data flow to and from plugins"""
import asyncio
import logging
from typing import Any
from cppython.builder import Builder
from cppython.core.exception import ConfigException
from cppython.core.resolution import resolve_model
from cppython.core.schema import Interface, ProjectConfiguration, PyProject
from cppython.schema import API
class Project(API):
"""The object that should be constructed at each entry_point"""
def __init__(
self, project_configuration: ProjectConfiguration, interface: Interface, pyproject_data: dict[str, Any]
) -> None:
"""Initializes the project"""
self._enabled = False
self._interface = interface
self.logger = logging.getLogger('cppython')
builder = Builder(project_configuration, self.logger)
self.logger.info('Initializing project')
try:
pyproject = resolve_model(PyProject, pyproject_data)
except ConfigException as error:
# Log the exception message explicitly
self.logger.error('Configuration error:\n%s', error, exc_info=False)
raise SystemExit('Error: Invalid configuration. Please check your pyproject.toml.') from None
if not pyproject.tool or not pyproject.tool.cppython:
self.logger.info("The pyproject.toml file doesn't contain the `tool.cppython` table")
return
self._data = builder.build(pyproject.project, pyproject.tool.cppython)
self._enabled = True
self.logger.info('Initialized project successfully')
@property
def enabled(self) -> bool:
"""Queries if the project was is initialized for full functionality
Returns:
The query result
"""
return self._enabled
def install(self) -> None:
"""Installs project dependencies
Raises:
Exception: Provider-specific exceptions are propagated with full context
"""
if not self._enabled:
self.logger.info('Skipping install because the project is not enabled')
return
self.logger.info('Installing tools')
asyncio.run(self._data.download_provider_tools())
self.logger.info('Installing project')
self.logger.info('Installing %s provider', self._data.plugins.provider.name())
# Sync before install to allow provider to access generator's resolved configuration
self._data.sync()
# Let provider handle its own exceptions for better error context
self._data.plugins.provider.install()
def update(self) -> None:
"""Updates project dependencies
Raises:
Exception: Provider-specific exception
"""
if not self._enabled:
self.logger.info('Skipping update because the project is not enabled')
return
self.logger.info('Updating tools')
asyncio.run(self._data.download_provider_tools())
self.logger.info('Updating project')
self.logger.info('Updating %s provider', self._data.plugins.provider.name())
# Sync before update to allow provider to access generator's resolved configuration
self._data.sync()
# Let provider handle its own exceptions for better error context
self._data.plugins.provider.update()
def publish(self) -> None:
"""Publishes the project
Raises:
Exception: Provider-specific exception
"""
if not self._enabled:
self.logger.info('Skipping publish because the project is not enabled')
return
self.logger.info('Publishing project')
# Ensure sync is performed before publishing to generate necessary files
self._data.sync()
# Let provider handle its own exceptions for better error context
self._data.plugins.provider.publish()