Skip to content

Fix hardcoded paths with environment variable support#104

Open
xingzihai wants to merge 1 commit intomvanhorn:mainfrom
xingzihai:fix-hardcoded-paths
Open

Fix hardcoded paths with environment variable support#104
xingzihai wants to merge 1 commit intomvanhorn:mainfrom
xingzihai:fix-hardcoded-paths

Conversation

@xingzihai
Copy link
Copy Markdown

Summary

This PR fixes hardcoded path issues throughout the codebase by implementing a centralized path configuration system with environment variable support.

Changes

Core Path Configuration (scripts/lib/env.py)

  • Added centralized path functions that support environment variable overrides
  • Implemented XDG Base Directory specification compliance
  • Added fallback to temp directories when permission denied

Environment Variables Supported

Variable Default Description
LAST30DAYS_CONFIG_DIR ~/.config/last30days Config directory
LAST30DAYS_DATA_DIR ~/.local/share/last30days Data directory for database
LAST30DAYS_DATABASE_PATH {DATA_DIR}/research.db Full database path
LAST30DAYS_CACHE_DIR ~/.cache/last30days Cache directory
LAST30DAYS_OUTPUT_DIR ~/.local/share/last30days/out Output directory
LAST30DAYS_BRIEFS_DIR ~/.local/share/last30days/briefs Briefings directory

Files Modified

  • scripts/lib/env.py - Added path configuration functions
  • scripts/store.py - Updated to use get_database_path()
  • scripts/lib/cache.py - Updated to use get_cache_dir()
  • scripts/lib/render.py - Updated to use get_output_dir()
  • scripts/last30days.py - Updated help string for --store
  • scripts/lib/ui.py - Updated to dynamically show config paths
  • scripts/briefing.py - Updated to use get_briefs_dir()
  • README.md - Added path customization documentation

Benefits

  1. Portability - Users can now customize storage locations for different environments (containers, shared systems, etc.)
  2. XDG Compliance - Follows the XDG Base Directory specification
  3. Graceful Fallback - Automatically falls back to temp directories if permission denied
  4. Backward Compatible - All existing defaults are preserved

Testing

All modified Python files compile successfully without errors.

- Add centralized path configuration in env.py with XDG-compliant defaults
- Support environment variable overrides for all paths:
  - LAST30DAYS_CONFIG_DIR for config directory
  - LAST30DAYS_DATA_DIR for data directory
  - LAST30DAYS_DATABASE_PATH for database file
  - LAST30DAYS_CACHE_DIR for cache directory
  - LAST30DAYS_OUTPUT_DIR for output directory
  - LAST30DAYS_BRIEFS_DIR for briefs directory
- Update all modules to use centralized path functions
- Update UI to dynamically show actual config paths
- Add fallback to temp directories when permission denied
- Update README.md with path customization documentation

This allows users to customize storage locations for different
deployment environments (containers, shared systems, etc.)
@mvanhorn
Copy link
Copy Markdown
Owner

See my reply on #109 covering all your PRs. Can't commit to anything right now with the v3.0 refactor underway, but I promise I'll consider each one once it lands. Appreciate the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants