Skip to content

Commit

Permalink
Fix error caused by weakly referenced package not specifying version …
Browse files Browse the repository at this point in the history
…range (#1712)

Signed-off-by: loonghao <[email protected]>
  • Loading branch information
loonghao authored Apr 13, 2024
1 parent 9b01d0b commit 8decb45
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "test_weakly_reference_requires"
version = "2.0"

requires = ["~test_variant_split_mid1", "~test_variant_split_mid2"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "test_weakly_reference_variant"
version = "2.0"

requires = ["~pyfoo"]

variants = [["test_variant_split_mid1", "~test_variant_split_mid2-1..3"]]
22 changes: 14 additions & 8 deletions src/rez/package_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def sort_key(self, package_name, version_like):
Args:
package_name: (str) The family name of the package we are sorting
version_like: (Version|_LowerBound|_UpperBound|_Bound|VersionRange)
the version-like object you wish to generate a key for
version_like: (Version|_LowerBound|_UpperBound|_Bound|VersionRange|None)
The version-like object to be used as a basis for generating a sort key.
Note that 'None' is also a supported value, which maintains the default sorting order.
Returns:
Sortable object
Expand All @@ -126,21 +127,26 @@ def sort_key(self, package_name, version_like):
"""
if isinstance(version_like, VersionRange):
return tuple(self.sort_key(package_name, bound) for bound in version_like.bounds)
elif isinstance(version_like, _Bound):
if isinstance(version_like, _Bound):
return (self.sort_key(package_name, version_like.lower),
self.sort_key(package_name, version_like.upper))
elif isinstance(version_like, _LowerBound):
if isinstance(version_like, _LowerBound):
inclusion_key = -2 if version_like.inclusive else -1
return self.sort_key(package_name, version_like.version), inclusion_key
elif isinstance(version_like, _UpperBound):
if isinstance(version_like, _UpperBound):
inclusion_key = 2 if version_like.inclusive else 1
return self.sort_key(package_name, version_like.version), inclusion_key
elif isinstance(version_like, Version):
if isinstance(version_like, Version):
# finally, the bit that we actually use the sort_key_implementation for.
return FallbackComparable(
self.sort_key_implementation(package_name, version_like), version_like)
else:
raise TypeError(version_like)
if version_like is None:
# As no version range is provided for this package,
# Python's sort preserves the order of equal elements.
# Thus, to maintain the original order,
# we return the same object for all None values.
return 0
raise TypeError(version_like)

def sort_key_implementation(self, package_name, version):
"""Returns a sort key usable for sorting these packages within the
Expand Down
3 changes: 2 additions & 1 deletion src/rez/tests/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def _eq(prefix, expected_completions):
_eq("", ["bahish", "nada", "nopy", "pybah", "pydad", "pyfoo", "pymum",
"pyodd", "pyson", "pysplit", "python", "pyvariants",
"test_variant_split_start", "test_variant_split_mid1",
"test_variant_split_mid2", "test_variant_split_end", "missing_variant_requires"])
"test_variant_split_mid2", "test_variant_split_end", "missing_variant_requires",
"test_weakly_reference_requires", "test_weakly_reference_variant"])
_eq("py", ["pybah", "pydad", "pyfoo", "pymum", "pyodd", "pyson",
"pysplit", "python", "pyvariants"])
_eq("pys", ["pyson", "pysplit"])
Expand Down
4 changes: 3 additions & 1 deletion src/rez/tests/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
'timestamped-1.0.5', 'timestamped-1.0.6', 'timestamped-1.1.0', 'timestamped-1.1.1',
'timestamped-1.2.0', 'timestamped-2.0.0', 'timestamped-2.1.0', 'timestamped-2.1.5',
'multi-1.0', 'multi-1.1', 'multi-1.2', 'multi-2.0',
'missing_variant_requires-1'
'missing_variant_requires-1',
'test_weakly_reference_requires-2.0',
'test_weakly_reference_variant-2.0',
])


Expand Down
17 changes: 17 additions & 0 deletions src/rez/tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ def test_12_missing_variant_requires(self):
config.override("error_on_missing_variant_requires", False)
self._solve(["missing_variant_requires"], ["nada[]", "missing_variant_requires-1[1]"])

def test_13_resolve_weakly_reference_requires(self):
"""Test resolving a package with a weakly referenced requirement."""
self._solve(["test_weakly_reference_requires", "test_variant_split_mid2-2"],
['test_weakly_reference_requires-2.0[]',
'test_variant_split_end-3.0[0]',
'test_variant_split_mid2-2.0[1]'])

def test_14_resolve_weakly_reference_variant(self):
"""Test resolving a package with a weakly referenced variant."""
self._solve(["test_weakly_reference_variant-2.0", "test_variant_split_mid2-2", "pyfoo"],
['test_variant_split_end-1.0[1]',
'test_variant_split_mid1-1.0[1]',
'test_weakly_reference_variant-2.0[0]',
'test_variant_split_mid2-2.0[0]',
'python-2.6.8[]',
'pyfoo-3.1.0[]'])


if __name__ == '__main__':
unittest.main()

0 comments on commit 8decb45

Please sign in to comment.