-
Notifications
You must be signed in to change notification settings - Fork 122
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
Deprecation of the env
resolver for variable environment interpolations
#573
Milestone
Comments
This was referenced Feb 26, 2021
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
odelalleau
added a commit
to odelalleau/omegaconf
that referenced
this issue
Mar 15, 2021
* Restore and deprecate the old `env` resolver for backward compatibility with OmegaConf 2.0 * The new `oc.env` resolver keeps the string representation of environment variables, and does not use the cache * The new `oc.decode` resolver can be used to parse and evaluate strings according to the OmegaConf grammar Fixes omry#383 Fixes omry#573 Fixes omry#574
odelalleau
added a commit
to odelalleau/omegaconf
that referenced
this issue
Mar 15, 2021
* Restore and deprecate the old `env` resolver for backward compatibility with OmegaConf 2.0 * The new `oc.env` resolver keeps the string representation of environment variables, and does not use the cache * The new `oc.decode` resolver can be used to parse and evaluate strings according to the OmegaConf grammar Fixes omry#383 Fixes omry#573 Fixes omry#574
odelalleau
added a commit
to odelalleau/omegaconf
that referenced
this issue
Mar 18, 2021
* Restore and deprecate the old `env` resolver for backward compatibility with OmegaConf 2.0 * The new `oc.env` resolver keeps the string representation of environment variables, and does not use the cache * The new `oc.decode` resolver can be used to parse and evaluate strings according to the OmegaConf grammar Fixes omry#383 Fixes omry#573 Fixes omry#574
odelalleau
added a commit
that referenced
this issue
Mar 18, 2021
* Introduce new `oc.env` and `oc.decode` resolvers * Restore and deprecate the old `env` resolver for backward compatibility with OmegaConf 2.0 * The new `oc.env` resolver keeps the string representation of environment variables, does not use the cache, and accepts None as default value * The new `oc.decode` resolver can be used to parse and evaluate strings according to the OmegaConf grammar Fixes #383 Fixes #573 Fixes #574 * Allow `oc.decode` to evaluate interpolations * Improve documentation of `oc.decode` In particular it explains that dictionaries and lists are automatically converted to transient config nodes. * Update docs/source/usage.rst Co-authored-by: Omry Yadan <[email protected]> * Update news/573.api_change Co-authored-by: Omry Yadan <[email protected]> * Update omegaconf/_utils.py Co-authored-by: Omry Yadan <[email protected]> * Update omegaconf/_utils.py Co-authored-by: Omry Yadan <[email protected]> * Remove the USERID example * Show example of quoted string as default value for `oc.env` * Remove duplicated comments (# #) * Validate default value of `oc.env` even when not used * Simplify tests with recwarn * Use convenience `show()` function in doc to show type and value * Update doc on string interpolations * More readable test formatting * Improve comment formatting * Restore interpolation examples * Update docs/notebook/Tutorial.ipynb Co-authored-by: Omry Yadan <[email protected]> * Update docs/source/usage.rst Co-authored-by: Omry Yadan <[email protected]> * Update docs/source/usage.rst Co-authored-by: Omry Yadan <[email protected]> * Rephrasing in doc * Use `show()` function in doc * Raise a KeyError instead of ValidationError for missing env variables * Remove handling of "null" as default in legacy env resolver * Update news * Explicit typing for the default value of the `oc.env` resolver * Use a more appropriate exception type * Update tests/test_interpolation.py Co-authored-by: Omry Yadan <[email protected]> * Safer markers for default values * Fix coverage * Use more appropriate TypeError * Refactor: consistent use of _DEFAULT_MARKER_ Co-authored-by: Omry Yadan <[email protected]>
This is an example of how to take advantage of the automatic conversion for typed nodes (see also the documentation): import os
from dataclasses import dataclass
from typing import Any
from omegaconf import II, OmegaConf
@dataclass
class Config:
some_int: int = II("oc.env: SOME_INT, '123'") # converted to int
some_bool: bool = II("oc.env: SOME_BOOL, 'True'") # converted to bool
some_any: Any = II("oc.env: SOME_ANY, '123'") # not converted (untyped)
cfg = OmegaConf.structured(Config)
assert cfg.some_int == 123
assert cfg.some_bool is True
assert cfg.some_any == "123"
os.environ["SOME_INT"] = "456"
os.environ["SOME_BOOL"] = "false"
os.environ["SOME_ANY"] = "false"
assert cfg.some_int == 456
assert cfg.some_bool is False
assert cfg.some_any == "false" |
4 tasks
shagunsodhani
added a commit
to shagunsodhani/mjrl_dev
that referenced
this issue
Apr 23, 2022
env resolver has been deprecated. For more details, refers omry/omegaconf#573
facebook-github-bot
pushed a commit
to facebookresearch/mmf
that referenced
this issue
Jun 22, 2022
Summary: `env` is deprecated in OmegaConf 2.1 (currently running in fbcode) in favor of `oc.env` `env` is deleted in OC 2.2 (we are upgrading fbcode to omegaconf 2.2) see omry/omegaconf#573 for more context Reviewed By: ebsmothers Differential Revision: D37330921 fbshipit-source-id: 7d48da6d08fe8585825038e0707738b6ecaf0644
RichJackson
pushed a commit
to AstraZeneca/KAZU
that referenced
this issue
Nov 30, 2022
The old one is deprecated in OmegaConf 2.1 (which our version of hydra uses): omry/omegaconf#573
RichJackson
pushed a commit
to AstraZeneca/KAZU
that referenced
this issue
Nov 30, 2022
The old one is deprecated in OmegaConf 2.1 (which our version of hydra uses): omry/omegaconf#573
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In OmegaConf 2.1, the
env
resolver is being deprecated in favor of a newoc.env
resolver.To migrate to this new resolver:
${env:MYVAR}
with${oc.env:MYVAR}
oc.env
:env
,oc.env
does not convert environment variables to primitives automatically (booleans, integers and floats) and always return the string representation. If you wish to convert from string to a different type, you may either take advantage of automatic conversion for typed nodes (see example below), or use the newoc.decode
resolver (see its documentation)oc.env
is converted to string usingstr(default)
unless it'snull
(representing PythonNone
). For instance,${env:OMP_NUM_THREADS,1}
will return the string"1"
if OMP_NUM_THREADS is not set. And${env:OMP_NUM_THREADS,null}
will returnNone
if if OMP_NUM_THREADS is not set.env
,oc.env
is un-cached. this means that ifMYVAR
is updated within the program's process, the change will appear when accessing${oc.env:MYVAR}
.The text was updated successfully, but these errors were encountered: