Skip to content

Commit 771e866

Browse files
authored
Fall back to building the package if prefer_system_check fails (alisw#884)
1 parent cfcb0eb commit 771e866

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

alibuild_helpers/utilities.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -493,27 +493,28 @@ def getPackageList(packages, specs, configDir, preferSystem, noSystem,
493493
if re.match(replacement_matcher, key):
494494
replacement = spec["prefer_system_replacement_specs"][replacement_matcher]
495495
break
496-
dieOnError(replacement is None, "Could not find named replacement spec for "
497-
"%s: %s" % (spec["package"], key))
498-
assert(replacement)
499-
# We must keep the package name the same, since it is used to
500-
# specify dependencies.
501-
replacement["package"] = spec["package"]
502-
# The version is required for all specs. What we put there will
503-
# influence the package's hash, so allow the user to override it.
504-
replacement.setdefault("version", requested_version)
505-
spec = replacement
506-
# Allows generalising the version based on the actual key provided
507-
spec["version"] = spec["version"].replace("%(key)s", key)
508-
recipe = replacement.get("recipe", "")
509-
# If there's an explicitly-specified recipe, we're still building
510-
# the package. If not, aliBuild will still "build" it, but it's
511-
# basically instantaneous, so report to the user that we're taking
512-
# it from the system.
513-
if recipe:
514-
ownPackages.add(spec["package"])
496+
if replacement:
497+
# We must keep the package name the same, since it is used to
498+
# specify dependencies.
499+
replacement["package"] = spec["package"]
500+
# The version is required for all specs. What we put there will
501+
# influence the package's hash, so allow the user to override it.
502+
replacement.setdefault("version", requested_version)
503+
spec = replacement
504+
# Allows generalising the version based on the actual key provided
505+
spec["version"] = spec["version"].replace("%(key)s", key)
506+
recipe = replacement.get("recipe", "")
507+
# If there's an explicitly-specified recipe, we're still building
508+
# the package. If not, aliBuild will still "build" it, but it's
509+
# basically instantaneous, so report to the user that we're taking
510+
# it from the system.
511+
if recipe:
512+
ownPackages.add(spec["package"])
513+
else:
514+
systemPackages.add(spec["package"])
515515
else:
516-
systemPackages.add(spec["package"])
516+
warning(f"Could not find named replacement spec for {spec['package']}: {key}, "
517+
"falling back to building the package ourselves.")
517518

518519
dieOnError(("system_requirement" in spec) and recipe.strip("\n\t "),
519520
"System requirements %s cannot have a recipe" % spec["package"])

tests/test_packagelist.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,20 @@ def test_replacement_recipe_given(self):
154154
self.assertNotIn("with-replacement-recipe", systemPkgs)
155155
self.assertIn("with-replacement-recipe", ownPkgs)
156156

157-
@mock.patch("alibuild_helpers.utilities.dieOnError")
158-
def test_missing_replacement_spec(self, mock_dieOnError):
159-
"""Check an error is thrown when the replacement spec is not found."""
160-
assert_msg = "Could not find named replacement spec for missing-spec: missing_tag"
161-
# Change the behaviour from sys.exit to a regular exception. Without it
162-
# we don't stop execution properly and other asserts might trigger
163-
mock_dieOnError.side_effect = lambda cond, _: (_ for _ in ()).throw(Exception("dieOnError called")) if cond else None
164-
with self.assertRaises(Exception, msg=assert_msg) as context:
165-
specs, systemPkgs, ownPkgs, failedReqs, validDefaults = \
166-
getPackageListWithDefaults(["missing-spec"])
167-
self.assertEqual(str(context.exception), "dieOnError called", msg=assert_msg)
157+
@mock.patch("alibuild_helpers.utilities.warning")
158+
def test_missing_replacement_spec(self, mock_warning):
159+
"""Check a warning is displayed when the replacement spec is not found."""
160+
warning_msg = "falling back to building the package ourselves"
161+
warning_exists = False
162+
def side_effect(msg, *args, **kwargs):
163+
nonlocal warning_exists
164+
if warning_msg in str(msg):
165+
warning_exists = True
166+
mock_warning.side_effect = side_effect
167+
specs, systemPkgs, ownPkgs, failedReqs, validDefaults = \
168+
getPackageListWithDefaults(["missing-spec"])
169+
self.assertTrue(warning_exists)
170+
168171

169172

170173
@mock.patch("alibuild_helpers.utilities.getRecipeReader", new=MockReader)

0 commit comments

Comments
 (0)