33This module handles loading configuration from multiple sources:
441. Global configuration (~/.cppython/config.toml) - User-wide settings for all projects
552. 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
913from 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
0 commit comments