refactor: Unify .env loading logic, eliminate code duplication#338
Open
SHINING2024 wants to merge 1 commit into
Open
refactor: Unify .env loading logic, eliminate code duplication#338SHINING2024 wants to merge 1 commit into
SHINING2024 wants to merge 1 commit into
Conversation
- Enhance lib/env_loader.py with manual parsing logic for full compatibility - Remove duplicate _load_dotenv() function from tools/base_tool.py - Remove duplicate _load_dotenv() static method from tools/tool_registry.py - Replace duplicate implementations with unified load_env() - Maintain all existing functionality and behavior unchanged - No new dependencies introduced, no breaking changes#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Unify the .env file loading logic across the OpenMontage project, eliminating code duplication between
base_tool.pyandtool_registry.pywhile maintaining full backward compatibility.Motivation
tools/base_tool.pyandtools/tool_registry.pylib/env_loader.pyalready exists but wasn't being fully leveragedTechnical Implementation
1. Enhanced
lib/env_loader.py_load_env_manual()function with exact same manual parsing logic as original codepython-dotenvsupport viause_dotenvparameterload_env(),get_env(),require_env()) remain unchanged2. Refactored
tools/base_tool.py_load_dotenv()function (lines 25-60)lib.env_loader import load_envload_env()instead of the removed_load_dotenv()3. Refactored
tools/tool_registry.py_load_dotenv()static method (lines 87-116)from lib.env_loader import load_envload_env()instead ofself._load_dotenv()indiscover()methodCompatibility Guarantees
✅ Functionally Identical: Manual parsing logic matches original line-by-line
✅ No Breaking Changes: All public APIs remain unchanged
✅ No New Dependencies: Doesn't introduce any additional Python packages
✅ Backward Compatible: Existing .env file formats fully supported
Testing Recommendations
Files Modified
lib/env_loader.py- Enhanced functionalitytools/base_tool.py- Removed duplicate codetools/tool_registry.py- Removed duplicate code