Coverage for src / local_deep_research / settings / env_registry.py: 86%

31 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2026-01-11 00:51 +0000

1""" 

2Registry of all environment-only settings. 

3 

4This module creates the global registry and registers all environment settings 

5defined in the env_definitions subfolder. 

6""" 

7 

8from typing import Optional, Any 

9 

10from .env_settings import SettingsRegistry 

11from .env_definitions import ALL_SETTINGS 

12 

13 

14def _create_registry() -> SettingsRegistry: 

15 """Create and initialize the global registry with all defined settings.""" 

16 registry = SettingsRegistry() 

17 

18 # Register all setting categories 

19 for category_name, settings_list in ALL_SETTINGS.items(): 

20 registry.register_category(category_name, settings_list) 

21 

22 return registry 

23 

24 

25# Global registry instance (singleton) 

26registry = _create_registry() 

27 

28 

29# Convenience functions for direct access 

30def get_env_setting(key: str, default: Optional[Any] = None) -> Any: 

31 """ 

32 Get an environment setting value. 

33 

34 Args: 

35 key: Setting key (e.g., "testing.test_mode") 

36 default: Default value if not set 

37 

38 Returns: 

39 Setting value or default 

40 """ 

41 return registry.get(key, default) 

42 

43 

44def is_test_mode() -> bool: 

45 """Quick check for test mode.""" 

46 return bool(registry.get("testing.test_mode", False)) 

47 

48 

49def use_fallback_llm() -> bool: 

50 """Quick check for fallback LLM mode.""" 

51 return bool(registry.get("testing.use_fallback_llm", False)) 

52 

53 

54def is_ci_environment() -> bool: 

55 """Quick check for CI environment.""" 

56 # CI is now an external variable, read it dynamically 

57 import os 

58 

59 return os.environ.get("CI", "false").lower() in ("true", "1", "yes") 

60 

61 

62def is_github_actions() -> bool: 

63 """Check if running in GitHub Actions.""" 

64 # GITHUB_ACTIONS is now an external variable, read it dynamically 

65 import os 

66 

67 return os.environ.get("GITHUB_ACTIONS", "false").lower() in ( 

68 "true", 

69 "1", 

70 "yes", 

71 ) 

72 

73 

74def is_rate_limiting_enabled() -> bool: 

75 """ 

76 Check if rate limiting should be enabled. 

77 

78 Returns: 

79 True if rate limiting should be enabled, False otherwise 

80 

81 Logic: 

82 - If DISABLE_RATE_LIMITING=true, disable rate limiting 

83 - Otherwise, enable rate limiting (default) 

84 

85 Note: 

86 This function intentionally does NOT check CI environment. 

87 Rate limiting control should be explicit via the dedicated flag. 

88 """ 

89 import os 

90 from loguru import logger 

91 

92 disable_flag = os.environ.get("DISABLE_RATE_LIMITING", "").lower() 

93 

94 if disable_flag in ("true", "1", "yes"): 94 ↛ 95line 94 didn't jump to line 95 because the condition on line 94 was never true

95 logger.debug("Rate limiting DISABLED due to DISABLE_RATE_LIMITING=true") 

96 return False 

97 

98 logger.debug("Rate limiting ENABLED (default)") 

99 return True 

100 

101 

102# Export the registry and convenience functions 

103__all__ = [ 

104 "registry", 

105 "get_env_setting", 

106 "is_test_mode", 

107 "use_fallback_llm", 

108 "is_ci_environment", 

109 "is_github_actions", 

110 "is_rate_limiting_enabled", 

111]