Skip to content
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

[Enhance] Substitute the environment variable in config file. #744

Merged
merged 12 commits into from
Feb 1, 2023
Prev Previous commit
Next Next commit
Fix comments
  • Loading branch information
jbwang1997 committed Jan 31, 2023
commit 4de2554aefb05800d0b2f565f796cbb9f2f36b85
2 changes: 1 addition & 1 deletion docs/en/advanced_tutorials/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ Config (path: replace_data_root.py): {'dataset_type': 'CocoDataset', 'data_root'

The value of `data_root` has been substituted with the value of `DATASET` as `/new/dataset/path`.

It is noteworthy that both `--cfg-options` and `{{$ENV_VAR:DEF_VAL}}` allow users modified fields in command line. But there is a small difference between those two methods. Environment variable substitution occurs before the configuration parsing. If the replaced field is also involved in other fields assignment, the environment variable substitution will also affect the other fields.
It is noteworthy that both `--cfg-options` and `{{$ENV_VAR:DEF_VAL}}` allow users to modify fields in command line. But there is a small difference between those two methods. Environment variable substitution occurs before the configuration parsing. If the replaced field is also involved in other fields assignment, the environment variable substitution will also affect the other fields.

We take `demo_train.py` and `replace_data_root.py` for example. If we replace `data_root` by setting `--cfg-options data_root='/new/dataset/path'`:

Expand Down
2 changes: 1 addition & 1 deletion mmengine/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self,
else:
text = ''
super().__setattr__('_text', text)
if not env_variables:
if env_variables is None:
env_variables = dict()
super().__setattr__('_env_variables', env_variables)

Expand Down