11"""Generates a Dockerfile based on an input matrix for Julia"""
2+ import functools
23import os
4+ import requests
35import toml
46from ..python import PythonBuildPack
5- from .semver import find_semver_match
7+ from .semver import find_semver_match , semver
68
79
810class 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
0 commit comments