refactor(src): standardize os.environ usage in inference upload script#194
Merged
WilliamBerryiii merged 2 commits intomainfrom Feb 18, 2026
Merged
Conversation
- add set_env_defaults import from training.utils in main() - centralize default values for 8 environment variables - replace os.environ.get with os.environ[] for defaulted vars - keep os.environ.get for optional and dependent vars 🔧 - Generated by Copilot
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
This PR refactors environment variable handling in src/inference/scripts/upload_artifacts.py to align with the pattern used in training scripts. It centralizes default values using set_env_defaults from training.utils.env, eliminating scattered inline defaults and making the distinction between required-with-defaults and truly-optional variables more explicit.
Changes:
- Import and use
set_env_defaultsto centralize 8 environment variable defaults (TASK, EXPORT_DIR, ONNX_SUCCESS, JIT_SUCCESS, NUM_ENVS, MAX_STEPS, VIDEO_LENGTH, INFERENCE_FORMAT) - Replace
os.environ.get("KEY", default)withos.environ["KEY"]for variables now managed byset_env_defaults - Preserve
os.environ.get()for truly optional variables and dependent defaults
agreaves-ms
approved these changes
Feb 18, 2026
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
Resolves #130
Standardizes
os.environ.get()usage insrc/inference/scripts/upload_artifacts.pyby adoptingset_env_defaultsfromtraining.utils.env.Changes
set_env_defaultsfromtraining.utilsinsidemain()aftersys.pathsetupset_env_defaults():TASK,EXPORT_DIR,ONNX_SUCCESS,JIT_SUCCESS,NUM_ENVS,MAX_STEPS,VIDEO_LENGTH,INFERENCE_FORMATos.environ.get("KEY", default)withos.environ["KEY"]for variables covered byset_env_defaults(safe becausesetdefaultguarantees the key exists)os.environ.get()for truly optional variables (SRC_ROOT,CHECKPOINT_URI,BLOB_STORAGE_ACCOUNT,BLOB_CONTAINER) and dependent defaults (METRICS_DIRdepends on computedEXPORT_DIR)Intentional Exclusions
infer.shheredocs — The 3os.environ.get()calls in embedded Python heredocs are left unchanged. Azure ML variables are genuinely optional for checkpoint download, and the script gracefully degrades with a warning when they are missing. Adding imports to heredocs increases complexity without functional benefit.upload_to_blob_fallback()—AZURE_STORAGE_ACCOUNT_NAMEandAZURE_STORAGE_CONTAINER_NAMEremain asos.environ.get()since they are optional fallback paths.Behavior
No functional behavior change.
set_env_defaultsusesos.environ.setdefault, which preserves any existing values. All default values match the originals exactly.