Skip to content

Commit e3c07bd

Browse files
committed
Fix error caused by weakly referenced package not specifying version range
Signed-off-by: loonghao <[email protected]>
1 parent 9610630 commit e3c07bd

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = "test_weakly_reference_requires"
2+
version = "2.0"
3+
4+
requires = ["~test_variant_split_mid1", "~test_variant_split_mid2"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name = "test_weakly_reference_variant"
2+
version = "2.0"
3+
4+
requires = ["~nada"]
5+
6+
variants = [["test_variant_split_mid1", "~test_variant_split_mid2-1..3"]]

src/rez/package_order.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,28 @@ def sort_key(self, package_name, version_like):
124124
The returned object must be sortable, which means that it must implement __lt__.
125125
The specific return type is not important.
126126
"""
127+
if version_like is None:
128+
# As no version range is provided for this package,
129+
# Python's sort preserves the order of equal elements.
130+
# Thus, to maintain the original order,
131+
# we return the same object for all None values.
132+
return 0
127133
if isinstance(version_like, VersionRange):
128134
return tuple(self.sort_key(package_name, bound) for bound in version_like.bounds)
129-
elif isinstance(version_like, _Bound):
135+
if isinstance(version_like, _Bound):
130136
return (self.sort_key(package_name, version_like.lower),
131137
self.sort_key(package_name, version_like.upper))
132-
elif isinstance(version_like, _LowerBound):
138+
if isinstance(version_like, _LowerBound):
133139
inclusion_key = -2 if version_like.inclusive else -1
134140
return self.sort_key(package_name, version_like.version), inclusion_key
135-
elif isinstance(version_like, _UpperBound):
141+
if isinstance(version_like, _UpperBound):
136142
inclusion_key = 2 if version_like.inclusive else 1
137143
return self.sort_key(package_name, version_like.version), inclusion_key
138-
elif isinstance(version_like, Version):
144+
if isinstance(version_like, Version):
139145
# finally, the bit that we actually use the sort_key_implementation for.
140146
return FallbackComparable(
141147
self.sort_key_implementation(package_name, version_like), version_like)
142-
else:
143-
raise TypeError(version_like)
148+
raise TypeError(version_like)
144149

145150
def sort_key_implementation(self, package_name, version):
146151
"""Returns a sort key usable for sorting these packages within the

src/rez/tests/test_completion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def _eq(prefix, expected_completions):
5252
_eq("", ["bahish", "nada", "nopy", "pybah", "pydad", "pyfoo", "pymum",
5353
"pyodd", "pyson", "pysplit", "python", "pyvariants",
5454
"test_variant_split_start", "test_variant_split_mid1",
55-
"test_variant_split_mid2", "test_variant_split_end", "missing_variant_requires"])
55+
"test_variant_split_mid2", "test_variant_split_end", "missing_variant_requires",
56+
"test_weakly_reference_requires", "test_weakly_reference_variant"])
5657
_eq("py", ["pybah", "pydad", "pyfoo", "pymum", "pyodd", "pyson",
5758
"pysplit", "python", "pyvariants"])
5859
_eq("pys", ["pyson", "pysplit"])

src/rez/tests/test_packages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
'timestamped-1.0.5', 'timestamped-1.0.6', 'timestamped-1.1.0', 'timestamped-1.1.1',
5959
'timestamped-1.2.0', 'timestamped-2.0.0', 'timestamped-2.1.0', 'timestamped-2.1.5',
6060
'multi-1.0', 'multi-1.1', 'multi-1.2', 'multi-2.0',
61-
'missing_variant_requires-1'
61+
'missing_variant_requires-1',
62+
'test_weakly_reference_requires-2.0',
63+
'test_weakly_reference_variant-2.0',
6264
])
6365

6466

src/rez/tests/test_solver.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ def test_12_missing_variant_requires(self):
256256
config.override("error_on_missing_variant_requires", False)
257257
self._solve(["missing_variant_requires"], ["nada[]", "missing_variant_requires-1[1]"])
258258

259+
def test_13_resolve_weakly_reference_requires(self):
260+
self._solve(["test_weakly_reference_requires", "test_variant_split_mid2-2"],
261+
['test_weakly_reference_requires-2.0[]',
262+
'test_variant_split_end-3.0[0]',
263+
'test_variant_split_mid2-2.0[1]'])
264+
265+
def test_14_resolve_weakly_reference_variant(self):
266+
self._solve(["test_weakly_reference_variant-2.0", "test_variant_split_mid2-2", "pyfoo"],
267+
['test_variant_split_end-1.0[1]',
268+
'test_variant_split_mid1-1.0[1]',
269+
'test_weakly_reference_variant-2.0[0]',
270+
'test_variant_split_mid2-2.0[0]',
271+
'python-2.6.8[]',
272+
'pyfoo-3.1.0[]'])
273+
259274

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

0 commit comments

Comments
 (0)