2023-11-01 13:10:08 +00:00
|
|
|
from os import environ
|
2019-10-25 19:28:44 +00:00
|
|
|
|
2023-11-01 13:10:08 +00:00
|
|
|
from clearml_agent.helper.environment import EnvEntry
|
2020-04-01 16:11:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
def backward_compatibility_support():
|
|
|
|
from ..definitions import ENVIRONMENT_CONFIG, ENVIRONMENT_SDK_PARAMS, ENVIRONMENT_BACKWARD_COMPATIBLE
|
2020-12-22 21:00:57 +00:00
|
|
|
if ENVIRONMENT_BACKWARD_COMPATIBLE.get():
|
|
|
|
# Add TRAINS_ prefix on every CLEARML_ os environment we support
|
|
|
|
for k, v in ENVIRONMENT_CONFIG.items():
|
2023-11-01 13:10:08 +00:00
|
|
|
# noinspection PyBroadException
|
2020-12-22 21:00:57 +00:00
|
|
|
try:
|
|
|
|
trains_vars = [var for var in v.vars if var.startswith('CLEARML_')]
|
|
|
|
if not trains_vars:
|
|
|
|
continue
|
|
|
|
alg_var = trains_vars[0].replace('CLEARML_', 'TRAINS_', 1)
|
|
|
|
if alg_var not in v.vars:
|
|
|
|
v.vars = tuple(list(v.vars) + [alg_var])
|
|
|
|
except:
|
2020-04-01 16:11:37 +00:00
|
|
|
continue
|
2020-12-22 21:00:57 +00:00
|
|
|
for k, v in ENVIRONMENT_SDK_PARAMS.items():
|
2023-11-01 13:10:08 +00:00
|
|
|
# noinspection PyBroadException
|
2020-12-22 21:00:57 +00:00
|
|
|
try:
|
|
|
|
trains_vars = [var for var in v if var.startswith('CLEARML_')]
|
|
|
|
if not trains_vars:
|
|
|
|
continue
|
|
|
|
alg_var = trains_vars[0].replace('CLEARML_', 'TRAINS_', 1)
|
|
|
|
if alg_var not in v:
|
|
|
|
ENVIRONMENT_SDK_PARAMS[k] = tuple(list(v) + [alg_var])
|
|
|
|
except:
|
2020-04-01 16:11:37 +00:00
|
|
|
continue
|
2020-12-22 21:00:57 +00:00
|
|
|
|
|
|
|
# set OS environ:
|
2021-01-24 06:47:33 +00:00
|
|
|
keys = list(environ.keys())
|
2020-12-22 21:00:57 +00:00
|
|
|
for k in keys:
|
|
|
|
if not k.startswith('CLEARML_'):
|
2020-04-01 16:11:37 +00:00
|
|
|
continue
|
2020-12-22 21:00:57 +00:00
|
|
|
backwards_k = k.replace('CLEARML_', 'TRAINS_', 1)
|
|
|
|
if backwards_k not in keys:
|
|
|
|
environ[backwards_k] = environ[k]
|
2023-11-01 13:10:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
"EnvEntry",
|
|
|
|
"backward_compatibility_support"
|
|
|
|
]
|