Skip to content

Commit 1b1dcd7

Browse files
authored
Update chore (#128)
1 parent 633b841 commit 1b1dcd7

File tree

8 files changed

+128
-118
lines changed

8 files changed

+128
-118
lines changed

cppython/configuration.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
This module handles loading configuration from multiple sources:
44
1. Global configuration (~/.cppython/config.toml) - User-wide settings for all projects
55
2. Project configuration (pyproject.toml or cppython.toml) - Project-specific settings
6-
3. Local overrides (.cppython.toml) - Overrides for global configuration
6+
3. Local overrides (.cppython.toml) - User-specific overrides, repository ignored
7+
8+
Local overrides (.cppython.toml) can override any field from both CPPythonLocalConfiguration
9+
and CPPythonGlobalConfiguration. Validation occurs on the merged result, not on the override
10+
file itself, allowing flexible user-specific customization.
711
"""
812

913
from pathlib import Path
@@ -77,7 +81,12 @@ def load_global_config(self) -> dict[str, Any] | None:
7781
def load_local_overrides(self) -> dict[str, Any] | None:
7882
"""Load local overrides from .cppython.toml if it exists
7983
80-
These overrides only affect the global configuration, not project configuration.
84+
These overrides have the highest priority and override both global
85+
and project configuration. This file should be gitignored as it
86+
contains machine-specific or user-specific settings.
87+
88+
The override file can contain any fields from CPPythonLocalConfiguration
89+
or CPPythonGlobalConfiguration. Validation occurs on the merged result.
8190
8291
Returns:
8392
Dictionary containing local override data, or None if file doesn't exist
@@ -113,23 +122,15 @@ def load_cppython_table(self) -> dict[str, Any] | None:
113122
"""Load and merge the CPPython configuration table from all sources
114123
115124
Priority (highest to lowest):
116-
1. Project configuration (pyproject.toml or cppython.toml)
117-
2. Local overrides (.cppython.toml) merged with global config
118-
3. Global configuration (~/.cppython/config.toml)
125+
1. Local overrides (.cppython.toml) - Machine/user-specific settings
126+
2. Project configuration (pyproject.toml or cppython.toml) - Project-specific settings
127+
3. Global configuration (~/.cppython/config.toml) - User-wide defaults
119128
120129
Returns:
121130
Merged CPPython configuration dictionary, or None if no config found
122131
"""
123-
# Start with global configuration
124-
global_config = self.load_global_config()
125-
126-
# Apply local overrides to global config
127-
local_overrides = self.load_local_overrides()
128-
if local_overrides is not None and global_config is not None:
129-
global_config = self.merge_configurations(global_config, local_overrides)
130-
elif local_overrides is not None and global_config is None:
131-
# Local overrides exist but no global config - use overrides as base
132-
global_config = local_overrides
132+
# Start with global configuration (lowest priority)
133+
result_config = self.load_global_config()
133134

134135
# Load project configuration (pyproject.toml or cppython.toml)
135136
pyproject_data = self.load_pyproject_data()
@@ -145,16 +146,21 @@ def load_cppython_table(self) -> dict[str, Any] | None:
145146
)
146147
project_config = cppython_toml_config
147148

148-
# Merge: global config (with local overrides) + project config
149-
# Project config has highest priority
150-
if project_config is not None and global_config is not None:
151-
return self.merge_configurations(global_config, project_config)
149+
# Merge project config over global config
150+
if project_config is not None and result_config is not None:
151+
result_config = self.merge_configurations(result_config, project_config)
152152
elif project_config is not None:
153-
return project_config
154-
elif global_config is not None:
155-
return global_config
153+
result_config = project_config
154+
155+
# Apply local overrides with highest priority
156+
local_overrides = self.load_local_overrides()
157+
if local_overrides is not None:
158+
if result_config is not None:
159+
result_config = self.merge_configurations(result_config, local_overrides)
160+
else:
161+
result_config = local_overrides
156162

157-
return None
163+
return result_config
158164

159165
def get_project_data(self) -> dict[str, Any]:
160166
"""Get the complete pyproject data with merged CPPython configuration

cppython/core/schema.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ class CPPythonGlobalConfiguration(CPPythonModel, extra='forbid'):
269269

270270

271271
class CPPythonLocalConfiguration(CPPythonModel, extra='forbid'):
272-
"""Data required by the tool"""
272+
"""Project-level CPPython configuration
273+
274+
This configuration is stored in pyproject.toml or cppython.toml.
275+
User-specific overrides can be placed in .cppython.toml (which should be gitignored).
276+
"""
273277

274278
configuration_path: Annotated[
275279
Path | None,

cppython/plugins/cmake/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class CMakeData(CPPythonModel):
115115

116116

117117
class CMakeConfiguration(CPPythonModel):
118-
"""Configuration"""
118+
"""Configuration for the CMake generator plugin"""
119119

120120
preset_file: Annotated[
121121
Path,

cppython/plugins/conan/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class ConanData(CPPythonModel):
298298

299299

300300
class ConanConfiguration(CPPythonModel):
301-
"""Raw conan data"""
301+
"""Conan provider configuration"""
302302

303303
remotes: Annotated[
304304
list[str],
@@ -312,7 +312,7 @@ class ConanConfiguration(CPPythonModel):
312312
str,
313313
Field(
314314
description='Directory containing Conan profiles. Profiles will be looked up relative to this directory. '
315-
'If profiles do not exist in this directory, Conan will fall back to default profiles.'
315+
'If profiles do not exist in this directory, Conan will fall back to default profiles. '
316316
"If a relative path is provided, it will be resolved relative to the tool's working directory."
317317
),
318318
] = 'profiles'

cppython/plugins/vcpkg/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ class VcpkgData(CPPythonModel):
4949

5050

5151
class VcpkgConfiguration(CPPythonModel):
52-
"""vcpkg provider data"""
52+
"""vcpkg provider configuration"""
5353

5454
install_directory: Annotated[
5555
Path,
5656
Field(
5757
alias='install-directory',
58-
description='The referenced dependencies defined by the local vcpkg.json manifest file',
58+
description='The directory where vcpkg artifacts will be installed.',
5959
),
6060
] = Path('build')
6161

0 commit comments

Comments
 (0)