Skip to content

Commit

Permalink
switch to semver package internally
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Doris committed May 12, 2024
1 parent f978091 commit 641701f
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 162 deletions.
15 changes: 4 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
name = "juliapkg"
version = "0.1.12"
description = "Julia version manager and package manager"
authors = [
{ name = "Christopher Doris" }
]
dependencies = [
"semantic_version~=2.9",
]
authors = [{ name = "Christopher Doris" }]
dependencies = ["semver~=3.0"]
readme = "README.md"
requires-python = ">= 3.8"
requires-python = "~=3.8"
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
Expand All @@ -30,10 +26,7 @@ select = ["E", "W", "F", "I"]

[tool.rye]
managed = true
dev-dependencies = [
"pytest>=8.2.0",
"pre-commit>=3.7.1",
]
dev-dependencies = ["pytest ~=8.2", "pre-commit ~=3.7"]

[tool.hatch.build.targets.wheel]
packages = ["src/juliapkg"]
39 changes: 18 additions & 21 deletions src/juliapkg/compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

from semantic_version import Version
from semver import Version

_re_partial_version = re.compile(r"^([0-9]+)(?:\.([0-9]+)(?:\.([0-9]+))?)?$")

Expand All @@ -10,10 +10,7 @@ def _parse_partial_version(x):
if m is None:
return None, None
major, minor, patch = m.groups()
major = int(major)
minor = None if minor is None else int(minor)
patch = None if patch is None else int(patch)
v = Version(major=major, minor=minor or 0, patch=patch or 0)
v = Version(major, minor or 0, patch or 0)
n = 1 if minor is None else 2 if patch is None else 3
return (v, n)

Expand Down Expand Up @@ -65,51 +62,51 @@ def parse(cls, verstr):

class Range:
def __init__(self, lo, hi):
self.lo = lo if isinstance(lo, Version) else Version(lo)
self.hi = hi if isinstance(hi, Version) else Version(hi)
self.lo = lo
self.hi = hi

@classmethod
def tilde(cls, v, n):
lo = Version(
major=v.major,
minor=v.minor if n >= 2 else 0,
patch=v.patch if n >= 3 else 0,
v.major,
v.minor if n >= 2 else 0,
v.patch if n >= 3 else 0,
)
hi = (
v.next_major()
v.bump_major()
if n < 2
else v.next_minor()
else v.bump_minor()
if v.major != 0 or v.minor != 0 or n < 3
else v.next_patch()
else v.bump_patch()
)
return Range(lo, hi)

@classmethod
def caret(cls, v, n):
lo = Version(
major=v.major,
minor=v.minor if n >= 2 else 0,
patch=v.patch if n >= 3 else 0,
v.major,
v.minor if n >= 2 else 0,
v.patch if n >= 3 else 0,
)
hi = (
v.next_major()
v.bump_major()
if v.major != 0 or n < 2
else v.next_minor()
else v.bump_minor()
if v.minor != 0 or n < 3
else v.next_patch()
else v.bump_patch()
)
return Range(lo, hi)

@classmethod
def equality(cls, v):
lo = v
hi = v.next_patch()
hi = v.bump_patch()
return Range(lo, hi)

@classmethod
def hyphen(cls, v1, v2, n):
lo = v1
hi = v2.next_major() if n < 2 else v2.next_minor() if n < 3 else v2.next_patch()
hi = v2.bump_major() if n < 2 else v2.bump_minor() if n < 3 else v2.bump_patch()
return Range(lo, hi)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/juliapkg/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def resolve(force=False, dry_run=False):
if deps:
STATE["resolved"] = True
STATE["executable"] = deps["executable"]
STATE["version"] = Version(deps["version"])
STATE["version"] = Version.parse(deps["version"])
return True
if dry_run:
return False
Expand Down
14 changes: 8 additions & 6 deletions src/juliapkg/find_julia.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def julia_version(exe):
.split()
)
if words[0].lower() == "julia" and words[1].lower() == "version":
return Version(words[2])
return Version.parse(words[2])
except Exception:
pass

Expand Down Expand Up @@ -120,14 +120,14 @@ def ju_list_julia_versions(compat=None):
if len(words) == 2:
c, v = words
try:
ver = Version(v)
ver = Version.parse(v)
except Exception:
continue
if ver.prerelease:
continue
if arch not in ver.build:
continue
ver = Version(major=ver.major, minor=ver.minor, patch=ver.patch)
ver = Version(ver.major, ver.minor, ver.patch)
if compat is None or ver in compat:
vers.setdefault(f"{ver.major}.{ver.minor}.{ver.patch}", []).append(c)
return vers
Expand All @@ -140,7 +140,7 @@ def ju_best_julia_version(compat=None):
f"no version of Julia is compatible with {compat} - perhaps you need to"
" update JuliaUp"
)
v = sorted(vers.keys(), key=Version, reverse=True)[0]
v = sorted(vers.keys(), key=Version.parse, reverse=True)[0]
return v, vers[v]


Expand Down Expand Up @@ -180,10 +180,12 @@ def ju_find_julia_noinstall(compat=None):
meta = json.load(fp)
versions = []
for verstr, info in meta.get("InstalledVersions", {}).items():
ver = Version(verstr.replace("~", ".")) # juliaup used to use VER~ARCH
ver = Version.parse(
verstr.replace("~", ".")
) # juliaup used to use VER~ARCH
if ver.prerelease or arch not in ver.build:
continue
ver = Version(major=ver.major, minor=ver.minor, patch=ver.patch)
ver = Version(ver.major, ver.minor, ver.patch)
if compat is None or ver in compat:
if "Path" in info:
ext = ".exe" if os.name == "nt" else ""
Expand Down
4 changes: 2 additions & 2 deletions src/juliapkg/install_julia.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def compatible_julia_versions(compat=None):
continue
if compat is not None:
try:
ver = Version(f["version"])
ver = Version.parse(f["version"])
except Exception:
continue
if ver not in compat:
Expand All @@ -128,7 +128,7 @@ def best_julia_version(compat=None):
vers = compatible_julia_versions(compat)
if not vers:
raise Exception(f"no version of Julia is compatible with {compat}")
v = sorted(vers.keys(), key=Version, reverse=True)[0]
v = sorted(vers.keys(), key=Version.parse, reverse=True)[0]
return v, vers[v]


Expand Down
Loading

0 comments on commit 641701f

Please sign in to comment.