Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the dnf -> dnf4 alias #1476

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions mock/py/mockbuild/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,25 @@

fallbacks = {
'dnf4': ['dnf4', 'dnf5', 'yum'],
'dnf': ['dnf4', 'dnf5', 'yum'], # backward-compat
'yum': ['yum', 'dnf4', 'dnf5'],
'microdnf': ['microdnf', 'dnf4', 'dnf5', 'yum'],
'dnf5': ['dnf5', 'dnf4', 'yum'],
}


def package_manager_from_string(name):
def _package_manager_from_string(name):
if name == 'dnf5':
return Dnf5
if name == 'yum':
return Yum
if name in ['dnf4', 'dnf']: # dnf for backward compat
if name in 'dnf4':
return Dnf
if name == 'microdnf':
return MicroDnf
raise Exception('Unrecognized package manager "{}"'.format(name))
raise RuntimeError(f'Unrecognized package manager "{name}"')


def package_manager_exists(pm_class, config_opts, chroot=None):
def _package_manager_exists(pm_class, config_opts, chroot=None):
name = pm_class.name
command = pm_class.get_command(config_opts)
pathname = (chroot or "") + command
Expand All @@ -52,10 +51,14 @@ def package_manager_exists(pm_class, config_opts, chroot=None):
return name in real_pathname


def package_manager_class_fallback(config_opts, buildroot, fallback):
def _package_manager_class_fallback(config_opts, buildroot, fallback):
desired = config_opts['package_manager']

if desired == 'dnf': # backward compat
desired = 'dnf4'

if not fallback:
return package_manager_from_string(desired)
return _package_manager_from_string(desired)

getLog().debug("searching for '%s' package manager or alternatives", desired)
if desired not in fallbacks:
Expand All @@ -69,10 +72,8 @@ def package_manager_class_fallback(config_opts, buildroot, fallback):
bootstrap = buildroot.is_bootstrap

for manager in fallbacks[desired]:
pm_class = package_manager_from_string(manager)
package_manager_exists(pm_class, config_opts)

if package_manager_exists(pm_class, config_opts, chroot=chroot_to_search_in):
pm_class = _package_manager_from_string(manager)
if _package_manager_exists(pm_class, config_opts, chroot=chroot_to_search_in):
if desired == manager:
return pm_class

Expand All @@ -83,6 +84,7 @@ def package_manager_class_fallback(config_opts, buildroot, fallback):
return pm_class

if not bootstrap:
# pylint: disable=consider-using-f-string
print("""WARNING! WARNING! WARNING!
You are building package for distribution which uses {0}. However your system
does not support {0}. You can continue with {1}, which will likely succeed,
Expand All @@ -96,11 +98,11 @@ def package_manager_class_fallback(config_opts, buildroot, fallback):

return pm_class

raise Exception(f"No package from {fallbacks[desired]} found, desired {desired}")
raise RuntimeError(f"No package from {fallbacks[desired]} found, desired {desired}")


def package_manager(buildroot, bootstrap_buildroot, fallback):
cls = package_manager_class_fallback(buildroot.config, buildroot, fallback)
cls = _package_manager_class_fallback(buildroot.config, buildroot, fallback)
return cls(buildroot.config, buildroot, buildroot.plugins,
bootstrap_buildroot)

Expand Down
3 changes: 3 additions & 0 deletions releng/release-notes-next/dnf-to-dnf4-fallback-fix.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A fix for the DNF → DNF4 fallback has been applied. Now Mock correctly selects
DNF4, even when the `--no-bootstrap-chroot` command is used. See
[issue#1475][] for more info.
Loading