Bases: LightningArgumentParser
Custom ArgumentParser that substitutes environment variables in config files.
This parser extends LightningArgumentParser to automatically substitute
${VAR_NAME} patterns with environment variable values before parsing
configuration content. This allows config files to use environment
variables while still passing Lightning's validation.
Source code in rslearn/arg_parser.py
| class RslearnArgumentParser(LightningArgumentParser):
"""Custom ArgumentParser that substitutes environment variables in config files.
This parser extends LightningArgumentParser to automatically substitute
${VAR_NAME} patterns with environment variable values before parsing
configuration content. This allows config files to use environment
variables while still passing Lightning's validation.
"""
def parse_string(
self,
cfg_str: str,
*args: Any,
**kwargs: Any,
) -> Namespace:
"""Pre-processes string for environment variable substitution before parsing."""
# Substitute environment variables in the config string before parsing
substituted_cfg_str = substitute_env_vars_in_string(cfg_str)
# Call the parent method with the substituted config
return super().parse_string(substituted_cfg_str, *args, **kwargs)
|
parse_string
parse_string(cfg_str: str, *args: Any, **kwargs: Any) -> Namespace
Pre-processes string for environment variable substitution before parsing.
Source code in rslearn/arg_parser.py
| def parse_string(
self,
cfg_str: str,
*args: Any,
**kwargs: Any,
) -> Namespace:
"""Pre-processes string for environment variable substitution before parsing."""
# Substitute environment variables in the config string before parsing
substituted_cfg_str = substitute_env_vars_in_string(cfg_str)
# Call the parent method with the substituted config
return super().parse_string(substituted_cfg_str, *args, **kwargs)
|