MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / load_config

Function load_config

src/codegraphcontext/cli/config_manager.py:326–373  ·  view source on GitHub ↗

Load configuration with priority support. Priority order (highest to lowest): 1. Environment variables 2. Local .env file (in current or parent directories) 3. Global ~/.codegraphcontext/.env Note: Does NOT create config directory - caller must call ensure_config_dir()

()

Source from the content-addressed store, hash-verified

324
325
326def load_config() -> Dict[str, str]:
327 """
328 Load configuration with priority support.
329 Priority order (highest to lowest):
330 1. Environment variables
331 2. Local .env file (in current or parent directories)
332 3. Global ~/.codegraphcontext/.env
333
334 Note: Does NOT create config directory - caller must call ensure_config_dir() first if needed.
335 """
336 # Start with defaults
337 config = DEFAULT_CONFIG.copy()
338
339 # Load global config
340 if CONFIG_FILE.exists():
341 try:
342 with open(CONFIG_FILE, "r", encoding="utf-8") as f:
343 for line in f:
344 line = line.strip()
345 if line and not line.startswith("#") and "=" in line:
346 key, value = line.split("=", 1)
347 config[key.strip()] = value.strip()
348 except Exception as e:
349 console.print(f"[red]Error loading global config: {e}[/red]")
350
351 # Load local .env file if it exists (overrides global)
352 local_env = find_local_env()
353 if local_env and local_env.exists():
354 try:
355 with open(local_env, "r", encoding="utf-8") as f:
356 for line in f:
357 line = line.strip()
358 if line and not line.startswith("#") and "=" in line:
359 key, value = line.split("=", 1)
360 key = key.strip()
361 # Only override if it's a config key (not database credentials in local file)
362 if key in DEFAULT_CONFIG or key in DATABASE_CREDENTIAL_KEYS:
363 config[key] = value.strip()
364 except Exception as e:
365 console.print(f"[yellow]Warning: Error loading local .env: {e}[/yellow]")
366
367 # Environment variables have highest priority
368 for key in DEFAULT_CONFIG.keys():
369 env_value = os.getenv(key)
370 if env_value is not None:
371 config[key] = env_value
372
373 return config
374
375
376def should_apply_project_dotenv() -> bool:

Callers 9

find_by_nameFunction · 0.90
_save_neo4j_credentialsFunction · 0.90
configure_mcp_clientFunction · 0.90
switch_context_toolMethod · 0.85
get_config_valueFunction · 0.85
set_config_valueFunction · 0.85
show_configFunction · 0.85
_default_global_db_pathFunction · 0.85
resolve_contextFunction · 0.85

Calls 4

find_local_envFunction · 0.85
printMethod · 0.80
keysMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected