Skip to content

Commit

Permalink
Remove any duplicated code loading configuration from ENV
Browse files Browse the repository at this point in the history
The current conf.get_config() function already handles loading from ENV.
Also, always use osc.build.calculate_build_root() instead of making a custom variable substitution.
  • Loading branch information
dmach committed Sep 27, 2023
1 parent 91a3096 commit 2f1cb0e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
28 changes: 4 additions & 24 deletions osc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,19 +606,19 @@ def calculate_prj_pac(store, opts, descr):


def calculate_build_root(apihost, prj, pac, repo, arch):
buildroot = os.environ.get('OSC_BUILD_ROOT', conf.config['build-root']) \
buildroot = conf.config["build-root"] \
% {'repo': repo, 'arch': arch, 'project': prj, 'package': pac, 'apihost': apihost}
return buildroot


def build_as_user():
if os.environ.get('OSC_SU_WRAPPER', conf.config['su-wrapper']).split():
if conf.config["su-wrapper"]:
return False
return True


def su_wrapper(cmd):
sucmd = os.environ.get('OSC_SU_WRAPPER', conf.config['su-wrapper']).split()
sucmd = conf.config['su-wrapper'].split()
if sucmd:
if sucmd[0] == 'su':
if sucmd[-1] == '-c':
Expand Down Expand Up @@ -782,18 +782,6 @@ def main(apiurl, store, opts, argv):
if opts.wipe:
buildargs.append("--wipe")

orig_build_root = config['build-root']
# make it possible to override configuration of the rc file
for var in ['OSC_PACKAGECACHEDIR', 'OSC_SU_WRAPPER', 'OSC_BUILD_ROOT']:
val = os.getenv(var)
if val:
if var.startswith('OSC_'):
var = var[4:]
var = var.lower().replace('_', '-')
if var in config:
print('Overriding config value for %s=\'%s\' with \'%s\'' % (var, config[var], val))
config[var] = val

pacname = pac
if pacname == '_repository':
if not opts.local_package:
Expand All @@ -805,15 +793,7 @@ def main(apiurl, store, opts, argv):
pacname = os.path.splitext(os.path.basename(build_descr))[0]
apihost = urlsplit(apiurl)[1]
if not build_root:
build_root = config['build-root']
if build_root == orig_build_root:
# ENV var was not set
build_root = config['api_host_options'][apiurl].get('build-root', build_root)
try:
build_root = build_root % {'repo': repo, 'arch': arch,
'project': prj, 'package': pacname, 'apihost': apihost}
except KeyError:
pass
build_root = calculate_build_root(apihost, prj, pacname, repo, arch)

# We configure sccache after pacname, so that in default cases we can have an sccache for each
# package to prevent cross-cache polutions. It helps to make the local-use case a bit nicer.
Expand Down
5 changes: 2 additions & 3 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6419,10 +6419,9 @@ def do_localbuildlog(self, subcmd, opts, *args):
raise oscerr.WrongArgs('Wrong number of arguments.')

# TODO: refactor/unify buildroot calculation and move it to core.py
buildroot = os.environ.get('OSC_BUILD_ROOT', conf.config['build-root'])
apihost = urlsplit(self.get_api_url())[1]
buildroot = buildroot % {'project': project, 'package': package,
'repo': repo, 'arch': arch, 'apihost': apihost}
buildroot = osc_build.calculate_build_root(apihost, project, package, repo, arch)

offset = 0
if opts.offset:
offset = int(opts.offset)
Expand Down
4 changes: 3 additions & 1 deletion osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,8 @@ def apiurl_aliases(self):
Supported substitutions: ``%(repo)s``, ``%(arch)s``, ``%(project)s``, ``%(package)s`` and ``%(apihost)s``
where ``apihost`` is the hostname extracted from the currently used ``apiurl``.
NOTE: The configuration holds the original unexpanded string. Call ``osc.build.get_build_root()`` with proper arguments to retrieve an actual path.
Passed as ``--root <VALUE>`` to the build tool.
"""
),
Expand Down Expand Up @@ -1745,7 +1747,7 @@ def get_config(override_conffile=None,
Configure osc.
The configuration options are loaded with the following priority:
1. environment variables: OSC_<uppercase-option>
1. environment variables: OSC_<uppercase_option>
2. override arguments provided to get_config()
3. oscrc config file
"""
Expand Down

0 comments on commit 2f1cb0e

Please sign in to comment.