Skip to content

Commit 71eb805

Browse files
authored
Merge pull request #994 from tomyun/julia-versions
[MRG] Fetch available Julia versions from hosted json
2 parents 7430cba + 27a0ed8 commit 71eb805

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

repo2docker/buildpacks/julia/julia_project.py

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Generates a Dockerfile based on an input matrix for Julia"""
2+
import functools
23
import os
4+
import requests
35
import toml
46
from ..python import PythonBuildPack
5-
from .semver import find_semver_match
7+
from .semver import find_semver_match, semver
68

79

810
class JuliaProjectTomlBuildPack(PythonBuildPack):
@@ -13,48 +15,44 @@ class JuliaProjectTomlBuildPack(PythonBuildPack):
1315
# ALL EXISTING JULIA VERSIONS
1416
# Note that these must remain ordered, in order for the find_semver_match()
1517
# function to behave correctly.
16-
all_julias = [
17-
"0.7.0",
18-
"1.0.0",
19-
"1.0.1",
20-
"1.0.2",
21-
"1.0.3",
22-
"1.0.4",
23-
"1.0.5",
24-
"1.1.0",
25-
"1.1.1",
26-
"1.2.0",
27-
"1.3.0",
28-
"1.3.1",
29-
"1.4.0",
30-
"1.4.1",
31-
"1.4.2",
32-
"1.5.0",
33-
"1.5.1",
34-
"1.5.2",
35-
"1.5.3",
36-
]
18+
@property
19+
@functools.lru_cache(maxsize=1)
20+
def all_julias(self):
21+
try:
22+
json = requests.get(
23+
"https://julialang-s3.julialang.org/bin/versions.json"
24+
).json()
25+
except Exception as e:
26+
raise RuntimeError("Failed to fetch available Julia versions: {e}")
27+
vers = [semver.VersionInfo.parse(v) for v in json.keys()]
28+
# filter out pre-release versions not supported by find_semver_match()
29+
filtered_vers = [v for v in vers if v.prerelease is None]
30+
# properly sort list of VersionInfo
31+
sorted_vers = sorted(
32+
filtered_vers, key=functools.cmp_to_key(semver.VersionInfo.compare)
33+
)
34+
# return list of semver string
35+
return [str(v) for v in sorted_vers]
3736

3837
@property
3938
def julia_version(self):
40-
default_julia_version = self.all_julias[-1]
41-
4239
if os.path.exists(self.binder_path("JuliaProject.toml")):
4340
project_toml = toml.load(self.binder_path("JuliaProject.toml"))
4441
else:
4542
project_toml = toml.load(self.binder_path("Project.toml"))
4643

47-
if "compat" in project_toml:
48-
if "julia" in project_toml["compat"]:
49-
julia_version_str = project_toml["compat"]["julia"]
50-
51-
# For Project.toml files, install the latest julia version that
52-
# satisfies the given semver.
53-
_julia_version = find_semver_match(julia_version_str, self.all_julias)
54-
if _julia_version is not None:
55-
return _julia_version
56-
57-
return default_julia_version
44+
try:
45+
# For Project.toml files, install the latest julia version that
46+
# satisfies the given semver.
47+
compat = project_toml["compat"]["julia"]
48+
except:
49+
# Default version which needs to be manually updated with new major.minor releases
50+
compat = "1.5"
51+
52+
match = find_semver_match(compat, self.all_julias)
53+
if match is None:
54+
raise RuntimeError("Failed to find a matching Julia version: {compat}")
55+
return match
5856

5957
def get_build_env(self):
6058
"""Get additional environment settings for Julia and Jupyter

repo2docker/buildpacks/julia/semver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def match(self, v):
113113
while len(v) < 3:
114114
v = v + (0,)
115115
v_str = ".".join(map(str, v))
116-
return semver.match(v_str, self.constraint_str)
116+
v_ver = semver.VersionInfo.parse(v_str)
117+
return semver.VersionInfo.match(v_ver, self.constraint_str)
117118

118119
def __eq__(self, rhs):
119120
return self.constraint_str == rhs.constraint_str

0 commit comments

Comments
 (0)