text stringlengths 0 828 |
|---|
env = env or os.environ |
for section_name, section in config: |
for option_name, _ in section: |
var_name = '{0}_{1}_{2}'.format( |
prefix.upper(), |
section_name.upper(), |
option_name.upper(), |
) |
env_var = env.get(var_name) |
if env_var: |
setattr(section, option_name, env_var) |
return config" |
1700,"def set_cli_options(config, arguments=None): |
""""""Set any configuration options which have a CLI value set. |
Args: |
config (confpy.core.config.Configuration): A configuration object which |
has been initialized with options. |
arguments (iter of str): An iterable of strings which contains the CLI |
arguments passed. If nothing is give then sys.argv is used. |
Returns: |
confpy.core.config.Configuration: A configuration object with CLI |
values set. |
The pattern to follow when setting CLI values is: |
<section>_<option> |
Each value should be lower case and separated by underscores. |
"""""" |
arguments = arguments or sys.argv[1:] |
parser = argparse.ArgumentParser() |
for section_name, section in config: |
for option_name, _ in section: |
var_name = '{0}_{1}'.format( |
section_name.lower(), |
option_name.lower(), |
) |
parser.add_argument('--{0}'.format(var_name)) |
args, _ = parser.parse_known_args(arguments) |
args = vars(args) |
for section_name, section in config: |
for option_name, _ in section: |
var_name = '{0}_{1}'.format( |
section_name.lower(), |
option_name.lower(), |
) |
value = args.get(var_name) |
if value: |
setattr(section, option_name, value) |
return config" |
1701,"def check_for_missing_options(config): |
""""""Iter over a config and raise if a required option is still not set. |
Args: |
config (confpy.core.config.Configuration): The configuration object |
to validate. |
Raises: |
MissingRequiredOption: If any required options are not set in the |
configuration object. |
Required options with default values are considered set and will not cause |
this function to raise. |
"""""" |
for section_name, section in config: |
for option_name, option in section: |
if option.required and option.value is None: |
raise exc.MissingRequiredOption( |
""Option {0} in namespace {1} is required."".format( |
option_name, |
section_name, |
) |
) |
return config" |
1702,"def parse_options(files, env_prefix='CONFPY', strict=True): |
""""""Parse configuration options and return a configuration object. |
Args: |
files (iter of str): File paths which identify configuration files. |
These files are processed in order with values in later files |
overwriting values in earlier files. |
env_prefix (str): The static prefix prepended to all options when set |
as environment variables. The default is CONFPY. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.