1616Core abstractions for the enhanced configuration system.
1717
1818This module implements the foundational data structures and interfaces:
19- - SourcePriority: Defines precedence levels
2019- ConfigValue: Immutable value container with provenance
2120- ValueSource: Common protocol for all configuration sources
2221- ResolutionHistory: Tracks the complete resolution process
2726from abc import ABC , abstractmethod
2827from dataclasses import dataclass , field
2928from datetime import datetime
30- from enum import Enum
3129from typing import Any , Callable , Dict , List , Optional
3230
3331
34- class SourcePriority (Enum ):
35- """
36- Defines top-level precedence for configuration sources.
37- Lower numeric value = higher priority.
38- """
39-
40- CLI_ARGUMENT = 1 # Highest: command-line arguments
41- ENVIRONMENT = 2 # Medium: environment variables
42- FILE = 3 # Lowest: configuration files
43-
44-
4532@dataclass (frozen = True )
4633class ConfigValue :
4734 """
@@ -52,7 +39,6 @@ class ConfigValue:
5239 key : str
5340 value : Any
5441 source_name : str
55- priority : SourcePriority
5642 raw_value : Optional [Any ] = None
5743
5844 def __repr__ (self ) -> str :
@@ -68,17 +54,15 @@ def from_source(
6854 key : str ,
6955 raw_value : str ,
7056 source_name : str ,
71- priority : SourcePriority ,
7257 value_parser : Optional [Callable [[str ], Any ]] = None ,
7358 ) -> ConfigValue :
7459 """
75- Factory method to create ConfigValue from a source handler .
60+ Factory method to create ConfigValue from a source.
7661
7762 Args:
7863 key: Configuration key
7964 raw_value: Raw string value from the source
8065 source_name: Name of the configuration source
81- priority: Source priority level
8266 value_parser: Optional parser function; if None, raw_value is used as-is
8367
8468 Returns:
@@ -89,32 +73,26 @@ def from_source(
8973 key = key ,
9074 value = parsed_value ,
9175 source_name = source_name ,
92- priority = priority ,
9376 raw_value = raw_value ,
9477 )
9578
9679
9780class ValueSource (ABC ):
9881 """
99- Common interface for all configuration sources and handlers .
82+ Common interface for all configuration sources.
10083 All implementations are READ-ONLY discovery mechanisms.
84+ Precedence is determined by the order sources are provided to the resolver.
10185 """
10286
10387 @property
10488 @abstractmethod
10589 def source_name (self ) -> str :
10690 """
10791 Unique identifier for this source.
108- Examples: "cli_arguments", "snowflake_cli_env ", "toml:connections "
92+ Examples: "cli_arguments", "snowsql_config ", "cli_env "
10993 """
11094 ...
11195
112- @property
113- @abstractmethod
114- def priority (self ) -> SourcePriority :
115- """Top-level priority for this source."""
116- ...
117-
11896 @abstractmethod
11997 def discover (self , key : Optional [str ] = None ) -> Dict [str , ConfigValue ]:
12098 """
@@ -241,7 +219,6 @@ def to_dict(self) -> dict:
241219 "source" : entry .config_value .source_name ,
242220 "value" : entry .config_value .value ,
243221 "raw_value" : entry .config_value .raw_value ,
244- "priority" : entry .config_value .priority .name ,
245222 "was_used" : entry .was_used ,
246223 "overridden_by" : entry .overridden_by ,
247224 "timestamp" : entry .timestamp .isoformat (),
0 commit comments