moose-lib 0.4.228__py3-none-any.whl → 0.4.229__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,82 @@
1
+ """
2
+ Configuration file handling for Moose.
3
+
4
+ This module provides functionality for reading and parsing the moose.config.toml file,
5
+ which contains project-wide configuration settings.
6
+ """
7
+ import os
8
+ import tomllib
9
+ from dataclasses import dataclass
10
+ from typing import Optional
11
+
12
+ @dataclass
13
+ class ClickHouseConfig:
14
+ """ClickHouse configuration settings from moose.config.toml."""
15
+ host: str
16
+ host_port: int
17
+ user: str
18
+ password: str
19
+ db_name: str
20
+ use_ssl: bool = False
21
+ native_port: Optional[int] = None
22
+
23
+ @dataclass
24
+ class ProjectConfig:
25
+ """Project configuration from moose.config.toml."""
26
+ language: str
27
+ clickhouse_config: ClickHouseConfig
28
+
29
+ def find_config_file(start_dir: str = os.getcwd()) -> Optional[str]:
30
+ """Find moose.config.toml by walking up directory tree.
31
+
32
+ Args:
33
+ start_dir: Directory to start searching from. Defaults to current directory.
34
+
35
+ Returns:
36
+ Path to moose.config.toml if found, None otherwise.
37
+ """
38
+ current_dir = os.path.abspath(start_dir)
39
+ while True:
40
+ config_path = os.path.join(current_dir, "moose.config.toml")
41
+ if os.path.exists(config_path):
42
+ return config_path
43
+
44
+ parent_dir = os.path.dirname(current_dir)
45
+ # Reached root directory
46
+ if parent_dir == current_dir:
47
+ break
48
+ current_dir = parent_dir
49
+ return None
50
+
51
+ def read_project_config() -> ProjectConfig:
52
+ """Read and parse moose.config.toml.
53
+
54
+ Returns:
55
+ ProjectConfig object containing parsed configuration.
56
+ """
57
+ config_path = find_config_file()
58
+ if not config_path:
59
+ raise FileNotFoundError(
60
+ "moose.config.toml not found in current directory or any parent directory"
61
+ )
62
+
63
+ try:
64
+ with open(config_path, "rb") as f:
65
+ config_data = tomllib.load(f)
66
+
67
+ clickhouse_config = ClickHouseConfig(
68
+ host=config_data["clickhouse_config"]["host"],
69
+ host_port=config_data["clickhouse_config"]["host_port"],
70
+ user=config_data["clickhouse_config"]["user"],
71
+ password=config_data["clickhouse_config"]["password"],
72
+ db_name=config_data["clickhouse_config"]["db_name"],
73
+ use_ssl=config_data["clickhouse_config"].get("use_ssl", False),
74
+ native_port=config_data["clickhouse_config"].get("native_port")
75
+ )
76
+
77
+ return ProjectConfig(
78
+ language=config_data["language"],
79
+ clickhouse_config=clickhouse_config
80
+ )
81
+ except Exception as e:
82
+ raise RuntimeError(f"Failed to parse moose.config.toml: {e}")
@@ -0,0 +1,83 @@
1
+ """
2
+ Runtime configuration management for Moose.
3
+
4
+ This module provides a singleton registry for managing runtime configuration settings,
5
+ particularly for ClickHouse connections.
6
+ """
7
+ from dataclasses import dataclass
8
+ from typing import Optional
9
+
10
+ @dataclass
11
+ class RuntimeClickHouseConfig:
12
+ """Runtime ClickHouse configuration settings."""
13
+ host: str
14
+ port: str
15
+ username: str
16
+ password: str
17
+ database: str
18
+ use_ssl: bool
19
+
20
+ class ConfigurationRegistry:
21
+ """Singleton registry for managing runtime configuration.
22
+
23
+ This class provides a centralized way to manage and access runtime configuration
24
+ settings, with fallback to file-based configuration when runtime settings are not set.
25
+ """
26
+ _instance: Optional['ConfigurationRegistry'] = None
27
+ _clickhouse_config: Optional[RuntimeClickHouseConfig] = None
28
+
29
+ @classmethod
30
+ def get_instance(cls) -> 'ConfigurationRegistry':
31
+ """Get the singleton instance of ConfigurationRegistry.
32
+
33
+ Returns:
34
+ The singleton ConfigurationRegistry instance.
35
+ """
36
+ if not cls._instance:
37
+ cls._instance = cls()
38
+ return cls._instance
39
+
40
+ def set_clickhouse_config(self, config: RuntimeClickHouseConfig) -> None:
41
+ """Set the runtime ClickHouse configuration.
42
+
43
+ Args:
44
+ config: The ClickHouse configuration to use.
45
+ """
46
+ self._clickhouse_config = config
47
+
48
+ def get_clickhouse_config(self) -> RuntimeClickHouseConfig:
49
+ """Get the current ClickHouse configuration.
50
+
51
+ If runtime configuration is not set, falls back to reading from moose.config.toml.
52
+
53
+ Returns:
54
+ The current ClickHouse configuration.
55
+ """
56
+ if self._clickhouse_config:
57
+ return self._clickhouse_config
58
+
59
+ # Fallback to reading from config file
60
+ from .config_file import read_project_config
61
+ try:
62
+ config = read_project_config()
63
+ return RuntimeClickHouseConfig(
64
+ host=config.clickhouse_config.host,
65
+ port=str(config.clickhouse_config.host_port),
66
+ username=config.clickhouse_config.user,
67
+ password=config.clickhouse_config.password,
68
+ database=config.clickhouse_config.db_name,
69
+ use_ssl=config.clickhouse_config.use_ssl
70
+ )
71
+ except Exception as e:
72
+ raise RuntimeError(f"Failed to get ClickHouse configuration: {e}")
73
+
74
+ def has_runtime_config(self) -> bool:
75
+ """Check if runtime configuration is set.
76
+
77
+ Returns:
78
+ True if runtime configuration is set, False otherwise.
79
+ """
80
+ return self._clickhouse_config is not None
81
+
82
+ # Create singleton instance
83
+ config_registry = ConfigurationRegistry.get_instance()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moose_lib
3
- Version: 0.4.228
3
+ Version: 0.4.229
4
4
  Home-page: https://www.fiveonefour.com/moose
5
5
  Author: Fiveonefour Labs Inc.
6
6
  Author-email: support@fiveonefour.com
@@ -9,6 +9,9 @@ moose_lib/query_param.py,sha256=AB5BKu610Ji-h1iYGMBZKfnEFqt85rS94kzhDwhWJnc,6288
9
9
  moose_lib/tasks.py,sha256=6MXA0j7nhvQILAJVTQHCAsquwrSOi2zAevghAc_7kXs,1554
10
10
  moose_lib/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  moose_lib/clients/redis_client.py,sha256=UBCdxwgZpIOIOy2EnPyxJIAYjw_qmNwGsJQCQ66SxUI,8117
12
+ moose_lib/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ moose_lib/config/config_file.py,sha256=NyjY6YFraBel7vBk18lLkpGaPR1viKMAEv4ZldyfLIA,2585
14
+ moose_lib/config/runtime.py,sha256=gF1wrUCbp0MxRU92k0vyItvWX2x6P1FuBRzM61nJE_U,2776
12
15
  moose_lib/dmv2/__init__.py,sha256=zyGK2YDN4zQ2SMn9-SAiOuhpU46STePuJjK18LEserg,2269
13
16
  moose_lib/dmv2/_registry.py,sha256=agdZ7xzS99Caou60Q2pEErzEwyNYHqwy6XqV79eEmwg,504
14
17
  moose_lib/dmv2/consumption.py,sha256=71wdv6ZuEi8Om7aX3Lq-d6bAoc1-iw3Wudb8dHESJKI,4072
@@ -28,7 +31,7 @@ tests/__init__.py,sha256=0Gh4yzPkkC3TzBGKhenpMIxJcRhyrrCfxLSfpTZnPMQ,53
28
31
  tests/conftest.py,sha256=ZVJNbnr4DwbcqkTmePW6U01zAzE6QD0kNAEZjPG1f4s,169
29
32
  tests/test_moose.py,sha256=mBsx_OYWmL8ppDzL_7Bd7xR6qf_i3-pCIO3wm2iQNaA,2136
30
33
  tests/test_redis_client.py,sha256=d9_MLYsJ4ecVil_jPB2gW3Q5aWnavxmmjZg2uYI3LVo,3256
31
- moose_lib-0.4.228.dist-info/METADATA,sha256=01yY_cIhFC-MaaKFT7nmXNG1gvT6qlhz0yuf7BL_u14,729
32
- moose_lib-0.4.228.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
- moose_lib-0.4.228.dist-info/top_level.txt,sha256=XEns2-4aCmGp2XjJAeEH9TAUcGONLnSLy6ycT9FSJh8,16
34
- moose_lib-0.4.228.dist-info/RECORD,,
34
+ moose_lib-0.4.229.dist-info/METADATA,sha256=ZblYKIznk4YNqvuBDBn_3LIreuxEl_y1ERY7vZCh3yk,729
35
+ moose_lib-0.4.229.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
36
+ moose_lib-0.4.229.dist-info/top_level.txt,sha256=XEns2-4aCmGp2XjJAeEH9TAUcGONLnSLy6ycT9FSJh8,16
37
+ moose_lib-0.4.229.dist-info/RECORD,,