Skip to content

Commit f4ce2e5

Browse files
authored
Fixes #13: Enable use of TagRange to locate an install to run (#14)
1 parent ebda801 commit f4ce2e5

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/manage/installs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ def get_matching_install_tags(
155155
exact_matches.append((i, t))
156156
matched_any = True
157157
elif not tag or tag.satisfied_by(ct):
158-
if tag and not companies_match(tag.company, i["company"]):
158+
if (
159+
isinstance(tag, CompanyTag)
160+
and not companies_match(tag.company, i["company"])
161+
):
159162
fallback_matches.append((i, t))
160163
matched_any = True
161164
elif i.get("unmanaged"):

src/manage/tagutils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def __hash__(self):
219219
return hash(self._sortkey)
220220

221221
def __eq__(self, other):
222-
if other is None:
222+
if not isinstance(other, type(self)):
223223
return False
224224
if self._company != other._company:
225225
return False
@@ -232,6 +232,8 @@ def __eq__(self, other):
232232
def __gt__(self, other):
233233
if other is None:
234234
return True
235+
if not isinstance(other, type(self)):
236+
return False
235237
if self._company != other._company:
236238
return self._company > other._company
237239
if self._sortkey != other._sortkey:
@@ -243,6 +245,8 @@ def __gt__(self, other):
243245
def matches_bound(self, other):
244246
if other is None:
245247
return True
248+
if not isinstance(other, type(self)):
249+
return False
246250
if not self._company.startswith(other._company):
247251
return False
248252
if other.platform not in (self.platform, ""):
@@ -260,6 +264,8 @@ def matches_bound(self, other):
260264
def above_lower_bound(self, other):
261265
if other is None:
262266
return True
267+
if not isinstance(other, type(self)):
268+
return False
263269
if not self._company.startswith(other._company):
264270
return False
265271
if other.platform not in (self.platform, ""):
@@ -275,7 +281,7 @@ def above_lower_bound(self, other):
275281
return True
276282

277283
def __lt__(self, other):
278-
if other is None:
284+
if not isinstance(other, type(self)):
279285
return False
280286
if self._company != other._company:
281287
return self._company < other._company
@@ -288,6 +294,8 @@ def __lt__(self, other):
288294
def below_upper_bound(self, other):
289295
if other is None:
290296
return True
297+
if not isinstance(other, type(self)):
298+
return False
291299
if not self._company.startswith(other._company):
292300
return False
293301
if other.platform not in (self.platform, ""):

tests/test_installs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def test_get_install_to_run_with_default_platform(patched_installs):
147147
assert i["id"] == "PythonCore-2.0-64"
148148
assert i["executable"].match("python.exe")
149149

150+
150151
def test_get_install_to_run_with_default_platform_prerelease(patched_installs2):
151152
# Specifically testing issue #25, where a native prerelease is preferred
152153
# over a non-native stable release. We should prefer the stable release
@@ -158,3 +159,12 @@ def test_get_install_to_run_with_default_platform_prerelease(patched_installs2):
158159
assert i["id"] == "PythonCore-1.0-32"
159160
i = installs.get_install_to_run("<none>", None, None, default_platform="-arm64")
160161
assert i["id"] == "PythonCore-1.0-32"
162+
163+
164+
def test_get_install_to_run_with_range(patched_installs):
165+
i = installs.get_install_to_run("<none>", None, "<=1.0")
166+
assert i["id"] == "PythonCore-1.0"
167+
assert i["executable"].match("python.exe")
168+
i = installs.get_install_to_run("<none>", None, ">1.0")
169+
assert i["id"] == "PythonCore-2.0-64"
170+
assert i["executable"].match("python.exe")

0 commit comments

Comments
 (0)