Skip to content

Commit 59bbec3

Browse files
committed
Project Root
1 parent 2714198 commit 59bbec3

File tree

16 files changed

+52
-92
lines changed

16 files changed

+52
-92
lines changed

cppython/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def select_scm(self, scm_plugins: list[type[SCM]], project_data: ProjectData) ->
262262
The selected SCM plugin type
263263
"""
264264
for scm_type in scm_plugins:
265-
if scm_type.features(project_data.pyproject_file.parent).repository:
265+
if scm_type.features(project_data.project_root).repository:
266266
return scm_type
267267

268268
self._logger.info('No SCM plugin was found that supports the given path')

cppython/console/entry.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ def main(
4949
debug: Debug mode
5050
"""
5151
path = _find_pyproject_file()
52-
file_path = path / 'pyproject.toml'
5352

54-
project_configuration = ProjectConfiguration(verbosity=verbose, debug=debug, pyproject_file=file_path, version=None)
53+
project_configuration = ProjectConfiguration(verbosity=verbose, debug=debug, project_root=path, version=None)
5554

5655
interface = ConsoleInterface()
5756
context.obj = ConsoleConfiguration(project_configuration=project_configuration, interface=interface)
@@ -79,7 +78,7 @@ def install(
7978
if (configuration := context.find_object(ConsoleConfiguration)) is None:
8079
raise ValueError('The configuration object is missing')
8180

82-
path = configuration.project_configuration.pyproject_file
81+
path = configuration.project_configuration.project_root / 'pyproject.toml'
8382
pyproject_data = loads(path.read_text(encoding='utf-8'))
8483

8584
project = Project(configuration.project_configuration, configuration.interface, pyproject_data)
@@ -101,7 +100,7 @@ def update(
101100
if (configuration := context.find_object(ConsoleConfiguration)) is None:
102101
raise ValueError('The configuration object is missing')
103102

104-
path = configuration.project_configuration.pyproject_file
103+
path = configuration.project_configuration.project_root / 'pyproject.toml'
105104
pyproject_data = loads(path.read_text(encoding='utf-8'))
106105

107106
project = Project(configuration.project_configuration, configuration.interface, pyproject_data)

cppython/core/resolution.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def resolve_project_configuration(project_configuration: ProjectConfiguration) -
3333
Returns:
3434
The resolved data
3535
"""
36-
return ProjectData(pyproject_file=project_configuration.pyproject_file, verbosity=project_configuration.verbosity)
36+
return ProjectData(project_root=project_configuration.project_root, verbosity=project_configuration.verbosity)
3737

3838

3939
def resolve_pep621(
@@ -58,7 +58,7 @@ def resolve_pep621(
5858
if project_configuration.version is not None:
5959
modified_version = project_configuration.version
6060
elif scm is not None:
61-
modified_version = scm.version(project_configuration.pyproject_file.parent)
61+
modified_version = scm.version(project_configuration.project_root)
6262
else:
6363
raise ValueError("Version can't be resolved. No SCM")
6464

@@ -110,7 +110,7 @@ def resolve_cppython(
110110
Returns:
111111
An instance of the resolved type
112112
"""
113-
root_directory = project_data.pyproject_file.parent.absolute()
113+
root_directory = project_data.project_root.absolute()
114114

115115
# Add the base path to all relative paths
116116
modified_install_path = local_configuration.install_path
@@ -128,11 +128,6 @@ def resolve_cppython(
128128
if not modified_build_path.is_absolute():
129129
modified_build_path = root_directory / modified_build_path
130130

131-
# Create directories if they do not exist
132-
modified_install_path.mkdir(parents=True, exist_ok=True)
133-
modified_tool_path.mkdir(parents=True, exist_ok=True)
134-
modified_build_path.mkdir(parents=True, exist_ok=True)
135-
136131
modified_provider_name = local_configuration.provider_name
137132
modified_generator_name = local_configuration.generator_name
138133

@@ -168,7 +163,6 @@ def resolve_cppython_plugin(cppython_data: CPPythonData, plugin_type: type[Plugi
168163
"""
169164
# Add plugin specific paths to the base path
170165
modified_install_path = cppython_data.install_path / plugin_type.name()
171-
modified_install_path.mkdir(parents=True, exist_ok=True)
172166

173167
plugin_data = CPPythonData(
174168
install_path=modified_install_path,
@@ -194,7 +188,6 @@ def _write_tool_directory(cppython_data: CPPythonData, directory: Path) -> Direc
194188
The written path
195189
"""
196190
plugin_directory = cppython_data.tool_path / 'cppython' / directory
197-
plugin_directory.mkdir(parents=True, exist_ok=True)
198191

199192
return plugin_directory
200193

@@ -209,7 +202,7 @@ def resolve_generator(project_data: ProjectData, cppython_data: CPPythonPluginDa
209202
Returns:
210203
The plugin specific configuration
211204
"""
212-
root_directory = project_data.pyproject_file.parent
205+
root_directory = project_data.project_root
213206
tool_directory = _write_tool_directory(cppython_data, Path('generators') / cppython_data.generator_name)
214207
configuration = GeneratorPluginGroupData(root_directory=root_directory, tool_directory=tool_directory)
215208
return configuration
@@ -225,7 +218,7 @@ def resolve_provider(project_data: ProjectData, cppython_data: CPPythonPluginDat
225218
Returns:
226219
The plugin specific configuration
227220
"""
228-
root_directory = project_data.pyproject_file.parent
221+
root_directory = project_data.project_root
229222
tool_directory = _write_tool_directory(cppython_data, Path('providers') / cppython_data.provider_name)
230223
configuration = ProviderPluginGroupData(root_directory=root_directory, tool_directory=tool_directory)
231224
return configuration
@@ -241,7 +234,7 @@ def resolve_scm(project_data: ProjectData, cppython_data: CPPythonPluginData) ->
241234
Returns:
242235
The plugin specific configuration
243236
"""
244-
root_directory = project_data.pyproject_file.parent
237+
root_directory = project_data.project_root
245238
tool_directory = _write_tool_directory(cppython_data, Path('managers') / cppython_data.scm_name)
246239
configuration = SCMPluginGroupData(root_directory=root_directory, tool_directory=tool_directory)
247240
return configuration

cppython/core/schema.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Annotated, Any, NewType, Protocol, runtime_checkable
66

77
from pydantic import BaseModel, Field, field_validator, model_validator
8-
from pydantic.types import DirectoryPath, FilePath
8+
from pydantic.types import DirectoryPath
99

1010
from cppython.utility.plugin import Plugin as SynodicPlugin
1111
from cppython.utility.utility import TypeName
@@ -20,14 +20,14 @@ class CPPythonModel(BaseModel):
2020
class ProjectData(CPPythonModel, extra='forbid'):
2121
"""Resolved data of 'ProjectConfiguration'"""
2222

23-
pyproject_file: Annotated[FilePath, Field(description='The path where the pyproject.toml exists')]
23+
project_root: Annotated[Path, Field(description='The path where the pyproject.toml exists')]
2424
verbosity: Annotated[int, Field(description='The verbosity level as an integer [0,2]')] = 0
2525

2626

2727
class ProjectConfiguration(CPPythonModel, extra='forbid'):
2828
"""Project-wide configuration"""
2929

30-
pyproject_file: Annotated[FilePath, Field(description='The path where the pyproject.toml exists')]
30+
project_root: Annotated[Path, Field(description='The path where the pyproject.toml exists')]
3131
version: Annotated[
3232
str | None,
3333
Field(
@@ -56,25 +56,6 @@ def min_max(cls, value: int) -> int:
5656
"""
5757
return min(max(value, 0), 2)
5858

59-
@field_validator('pyproject_file')
60-
@classmethod
61-
def pyproject_name(cls, value: FilePath) -> FilePath:
62-
"""Validator that verifies the name of the file
63-
64-
Args:
65-
value: Input to validate
66-
67-
Raises:
68-
ValueError: The given filepath is not named "pyproject.toml"
69-
70-
Returns:
71-
The file path
72-
"""
73-
if value.name != 'pyproject.toml':
74-
raise ValueError('The given file is not named "pyproject.toml"')
75-
76-
return value
77-
7859

7960
class PEP621Data(CPPythonModel):
8061
"""Resolved PEP621Configuration data"""
@@ -130,17 +111,17 @@ def _default_install_location() -> Path:
130111
class CPPythonData(CPPythonModel, extra='forbid'):
131112
"""Resolved CPPython data with local and global configuration"""
132113

133-
install_path: DirectoryPath
134-
tool_path: DirectoryPath
135-
build_path: DirectoryPath
114+
install_path: Path
115+
tool_path: Path
116+
build_path: Path
136117
current_check: bool
137118
provider_name: TypeName
138119
generator_name: TypeName
139120
scm_name: TypeName
140121

141122
@field_validator('install_path', 'tool_path', 'build_path')
142123
@classmethod
143-
def validate_absolute_path(cls, value: DirectoryPath) -> DirectoryPath:
124+
def validate_absolute_path(cls, value: Path) -> Path:
144125
"""Enforce the input is an absolute path
145126
146127
Args:
@@ -184,7 +165,7 @@ class PluginGroupData(CPPythonModel, extra='forbid'):
184165

185166
root_directory: Annotated[DirectoryPath, Field(description='The directory of the project')]
186167
tool_directory: Annotated[
187-
DirectoryPath,
168+
Path,
188169
Field(
189170
description=(
190171
'Points to the project plugin directory within the tool directory. '

cppython/plugins/cmake/resolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def resolve_cmake_data(data: dict[str, Any], core_data: CorePluginData) -> CMake
1818
"""
1919
parsed_data = CMakeConfiguration(**data)
2020

21-
root_directory = core_data.project_data.pyproject_file.parent.absolute()
21+
root_directory = core_data.project_data.project_root.absolute()
2222

2323
modified_preset = parsed_data.preset_file
2424
if not modified_preset.is_absolute():

cppython/plugins/conan/plugin.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
class ConanProvider(Provider):
2020
"""Conan Provider"""
2121

22+
_provider_url = 'https://raw.githubusercontent.com/conan-io/cmake-conan/refs/heads/develop2/conan_provider.cmake'
23+
2224
def __init__(
2325
self, group_data: ProviderPluginGroupData, core_data: CorePluginData, configuration_data: dict[str, Any]
2426
) -> None:
@@ -27,11 +29,6 @@ def __init__(
2729
self.core_data: CorePluginData = core_data
2830
self.data: ConanData = resolve_conan_data(configuration_data, core_data)
2931

30-
self._provider_file = self.core_data.cppython_data.tool_path / 'conan' / 'conan_provider.cmake'
31-
self._provider_url = (
32-
'https://raw.githubusercontent.com/conan-io/cmake-conan/refs/heads/develop2/conan_provider.cmake'
33-
)
34-
3532
@staticmethod
3633
def _download_file(url: str, file: Path) -> None:
3734
"""Replaces the given file with the contents of the url"""
@@ -64,17 +61,9 @@ def information() -> Information:
6461

6562
def install(self) -> None:
6663
"""Installs the provider"""
67-
self._download_file(
68-
self._provider_url,
69-
self._provider_file,
70-
)
7164

7265
def update(self) -> None:
7366
"""Updates the provider"""
74-
self._download_file(
75-
self._provider_url,
76-
self._provider_file,
77-
)
7867

7968
@staticmethod
8069
def supported_sync_type(sync_type: type[SyncData]) -> bool:
@@ -99,6 +88,14 @@ def sync_data(self, consumer: SyncConsumer) -> SyncData:
9988
"""
10089
for sync_type in consumer.sync_types():
10190
if sync_type == CMakeSyncData:
102-
return CMakeSyncData(provider_name=TypeName('conan'), top_level_includes=self._provider_file)
91+
return CMakeSyncData(
92+
provider_name=TypeName('conan'),
93+
top_level_includes=self.core_data.cppython_data.tool_path / 'conan' / 'conan_provider.cmake',
94+
)
10395

10496
raise NotSupportedError('OOF')
97+
98+
@classmethod
99+
async def download_tooling(cls, directory: Path) -> None:
100+
"""Downloads the conan provider file"""
101+
cls._download_file(cls._provider_url, directory / 'conan_provider.cmake')

cppython/plugins/pdm/plugin.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ def on_post_install(self, project: Project, dry_run: bool, **_kwargs: Any) -> No
3333
dry_run: If true, won't perform any actions
3434
_kwargs: Sink for unknown arguments
3535
"""
36-
pyproject_file = project.root.absolute() / project.PYPROJECT_FILENAME
36+
root = project.root.absolute()
3737

3838
# Attach configuration for CPPythonPlugin callbacks
3939
version = project.pyproject.metadata.get('version')
4040
verbosity = project.core.ui.verbosity
4141

42-
project_configuration = ProjectConfiguration(
43-
pyproject_file=pyproject_file, verbosity=verbosity, version=version
44-
)
42+
project_configuration = ProjectConfiguration(project_root=root, verbosity=verbosity, version=version)
4543

4644
self.logger.info("CPPython: Entered 'on_post_install'")
4745

cppython/plugins/vcpkg/plugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def install(self) -> None:
184184
Raises:
185185
ProcessError: Failed vcpkg calls
186186
"""
187-
manifest_directory = self.core_data.project_data.pyproject_file.parent
187+
manifest_directory = self.core_data.project_data.project_root
188188
manifest = generate_manifest(self.core_data, self.data)
189189

190190
# Write out the manifest
@@ -214,7 +214,8 @@ def update(self) -> None:
214214
Raises:
215215
ProcessError: Failed vcpkg calls
216216
"""
217-
manifest_directory = self.core_data.project_data.pyproject_file.parent
217+
manifest_directory = self.core_data.project_data.project_root
218+
218219
manifest = generate_manifest(self.core_data, self.data)
219220

220221
# Write out the manifest

cppython/plugins/vcpkg/resolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def resolve_vcpkg_data(data: dict[str, Any], core_data: CorePluginData) -> Vcpkg
4242
"""
4343
parsed_data = VcpkgConfiguration(**data)
4444

45-
root_directory = core_data.project_data.pyproject_file.parent.absolute()
45+
root_directory = core_data.project_data.project_root.absolute()
4646

4747
modified_install_directory = parsed_data.install_directory
4848

cppython/plugins/vcpkg/schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Annotated
55

66
from pydantic import Field, HttpUrl
7-
from pydantic.types import DirectoryPath
87

98
from cppython.core.schema import CPPythonModel
109

@@ -18,7 +17,7 @@ class VcpkgDependency(CPPythonModel):
1817
class VcpkgData(CPPythonModel):
1918
"""Resolved vcpkg data"""
2019

21-
install_directory: DirectoryPath
20+
install_directory: Path
2221
dependencies: list[VcpkgDependency]
2322

2423

0 commit comments

Comments
 (0)