-
Notifications
You must be signed in to change notification settings - Fork 665
Add environment variable support for report and command-borders #4530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
… module - Add environment variable support for --report and --command-borders CLI flags - Implement precedence order: defaults → env vars → CLI args - Add MOLECULE_REPORT and MOLECULE_COMMAND_BORDERS environment variables - Move util.py and boolean.py into src/molecule/utils/ package for better organization - Update all imports across codebase to use new utils package structure - Add comprehensive test coverage for environment variable functionality - Fix pre-commit linting issues and update import paths
e5d010b to
6460d8d
Compare
- Environment variables now read from both os.environ and env_file - Uses same merged environment pattern as existing Molecule config system - Maintains proper precedence: defaults → env_file → os.environ → CLI args
- Replace unittest.mock.patch with monkeypatch.setenv/delenv - Add proper pytest.MonkeyPatch type annotation - Maintain standalone test capability with mock implementation
- Delete test_env_file.py and test_env_file_support.py - Remove test_env_overrides_with_env_file from test_base.py - Env file support is validated through existing comprehensive tests - Focus on clean, maintainable test patterns consistent with codebase
d437d5e to
ea41b94
Compare
- Remove test_env_overrides_with_env_file function that didn't follow patterns - This was the source of the pydoclint DOC101/DOC103 errors
f9e4785 to
9058b76
Compare
- Create src/molecule/util.py stub for backward compatibility - Third-party plugins importing 'from molecule import util' will continue to work - Issues deprecation warning to encourage migration to new location - Fixes import errors in molecule-plugins-azure and other external drivers
- Add pylint disable for wildcard import warnings - This is acceptable for a compatibility shim that needs to expose all functions
- Test validates that invalid environment variable values are logged and ignored - Covers the error handling code paths in _apply_env_overrides method - Uses int conversion to trigger ValueError for comprehensive coverage
- Move ENV_VAR_CONFIG_MAPPING import to module level for better code organization - Follows Python import conventions by keeping imports at the top
- Use monkeypatch.setattr instead of manual dict manipulation - Patch both constants and config module imports - Remove try/finally cleanup as monkeypatch handles restoration automatically - Add type: ignore comments to suppress TypedDict warnings
shatakshiiii
approved these changes
Aug 18, 2025
Qalthos
pushed a commit
that referenced
this pull request
Aug 20, 2025
This PR consolidates the utils module structure by moving all utilities into a single util.py file at the root of the molecule package. Changes: - Move util.py from src/molecule/utils/ to src/molecule/ - Consolidate to_bool function from boolean.py into util.py - Update all imports from molecule.utils.util to molecule.util - Remove empty utils directory and associated files - All existing functionality preserved and tested This simplifies the module structure while maintaining backward compatibility for all utility functions. Reverts directory creation in #4530 now that circular imports issues have been resolved.
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.
Add environment variable support for CLI flags and refactor utilities module
Summary
This PR adds environment variable support for the
--reportand--command-bordersCLI flags with precedence orderdefaults → env_file → os.environ → CLI args. It also movesutil.pyandboolean.pyinto asrc/molecule/utils/package.User-Facing Changes
Environment Variable Support
New environment variables:
MOLECULE_REPORT=true- equivalent to--reportMOLECULE_COMMAND_BORDERS=false- equivalent to--command-bordersEnvironment variables are applied only when CLI arguments are not explicitly provided:
Supported boolean formats:
true/false,yes/no,on/off,1/0(case-insensitive).Implementation Details
Design Decision: New Pattern vs Existing
Molecule already supports some environment variables (
MOLECULE_DEBUG,MOLECULE_VERBOSITY) but uses a pattern that has limitations:Issues with existing pattern:
os.environ)New pattern:
Improvements:
set_env_from_file()Environment Variable Processing
os.environ,config.env, and env filesctx.get_parameter_source()to detect explicit CLI argumentsENV_VAR_CONFIG_MAPPING_apply_cli_overrides()to maintain precedenceConfiguration mapping:
Circular Import Resolution
Initial circular dependency:
ansi_output.py → util.py → console.py → ansi_output.pyResolution:
to_bool()to dedicatedboolean.pymodulesrc/molecule/utils/packagefrom molecule.utils.boolean import to_boolModule Refactoring
src/molecule/util.py→src/molecule/utils/util.pysrc/molecule/boolean.py→src/molecule/utils/boolean.pysrc/molecule/utils/__init__.pyTesting
Added comprehensive test coverage for environment variable application, CLI precedence validation, and type conversion. All existing tests continue to pass.
Future Migration Path
Other environment variables (
MOLECULE_DEBUG,MOLECULE_VERBOSITY,MOLECULE_PARALLEL) could be migrated to this new framework to gain:This would require updating their Click option definitions and adding entries to
ENV_VAR_CONFIG_MAPPING.