1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 # config.py - configuration settings and global variables for Arvados clients
7 # Arvados configuration settings are taken from $HOME/.config/arvados.
8 # Environment variables override settings in the config file.
20 from ._internal import basedirs
23 default_config_file = ''
25 .. WARNING:: Deprecated
26 Default configuration initialization now searches for the "default"
27 configuration in several places. This value no longer has any effect.
30 KEEP_BLOCK_SIZE = 2**26
31 EMPTY_BLOCK_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0'
37 Callable[[str], Iterable[os.PathLike]],
38 ]=basedirs.BaseDirectories('CONFIG').search,
43 if callable(config_file):
44 search_paths = iter(config_file('settings.conf'))
45 config_file = next(search_paths, '')
47 # load the specified config file if available
49 _settings = load(config_file)
53 # override any settings with environment vars
54 for var in os.environ:
55 if var.startswith('ARVADOS_'):
56 _settings[var] = os.environ[var]
58 def load(config_file):
60 with open(config_file, "r") as f:
62 if re.match(r'^\s*(?:#|$)', config_line):
64 var, val = config_line.rstrip().split('=', 2)
68 def flag_is_true(key, d=None):
71 return d.get(key, '').lower() in set(['1', 't', 'true', 'y', 'yes'])
73 def get(key, default_val=None):
74 return settings().get(key, default_val)