refactor: consolidate _build_args_str to utils.shell, fix env file inline comment parsing#2
Open
thor-guardrail wants to merge 1 commit into
Conversation
…line comment parsing Two improvements: 1. _build_args_str() was duplicated identically in both dds/providers/azure/container.py and dds/builders/docker.py. Moved the canonical implementation to dds/utils/shell.build_args_str() (with shell-quoting via shlex.quote — see PR digitalforgeca#1 for the safety fix). Both original sites now import and delegate to the shared version. Module-level _build_args_str aliases kept for backward compatibility. 2. load_env_file() in dds/secrets.py did not strip inline comments from unquoted values, so a line like: DATABASE_URL=postgres://localhost/mydb # local dev only would produce 'postgres://localhost/mydb # local dev only' as the value. This is incorrect — standard .env file parsers (dotenv et al.) strip inline comments from unquoted values. Quoted values are left untouched (the comment is considered part of the value when quoted). Added stripping for ' #' and '\t#' comment separators on unquoted values.
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.
Summary
Two related code quality improvements found during review.
1. Deduplicate
_build_args_str()Severity: Code quality / DRY violation
_build_args_str()was defined identically in two places:dds/providers/azure/container.pydds/builders/docker.pyBoth functions had the same signature, same logic, same docstring. No single-source-of-truth. Any future fix to one would need to be applied to both.
Fix: Moved the canonical (and now shell-safe — see PR #1) implementation to
dds/utils/shell.build_args_str(). Both original sites now import and delegate. Module-level_build_args_straliases are kept for backward compatibility.2.
load_env_file()doesn't strip inline comments from unquoted valuesSeverity: Bug / correctness
A line like:
...was being parsed as the value
postgres://localhost/mydb # local dev only. This would silently produce an invalid connection string at runtime.Standard
.envfile semantics (used bydotenv,python-dotenv,godotenv, etc.) strip inline comments from unquoted values. Quoted values are untouched — the comment is part of the value when inside quotes.Fix: After quote-stripping, scan unquoted values for
#or\t#separator and truncate there.Note: Quoted values with a
#inside them are still handled correctly:Files changed
dds/utils/shell.py— newbuild_args_str()dds/providers/azure/container.py— delegates to shared utildds/builders/docker.py— delegates to shared utildds/secrets.py— inline comment stripping