@@ -28,19 +28,58 @@ def python_version(self):
28
28
if hasattr (self , "_python_version" ):
29
29
return self ._python_version
30
30
31
+ try :
32
+ with open (self .binder_path ("runtime.txt" )) as f :
33
+ runtime = f .read ().strip ()
34
+ except FileNotFoundError :
35
+ runtime = ""
36
+
37
+ if runtime .startswith ("python-" ):
38
+ runtime_python_version = runtime .split ("-" , 1 )[1 ]
39
+ else :
40
+ # not a Python runtime (e.g. R, which subclasses this)
41
+ # use the default Python
42
+ runtime_python_version = self .major_pythons ["3" ]
43
+ self .log .warning (
44
+ f"Python version unspecified in runtime.txt, using current default Python version { runtime_python_version } . This will change in the future."
45
+ )
46
+
47
+ runtime_python_version_info = runtime_python_version .split ("." )
48
+ if len (runtime_python_version_info ) == 1 :
49
+ runtime_python_version = self .major_pythons [runtime_python_version_info [0 ]]
50
+ runtime_python_version_info = runtime_python_version .split ("." )
51
+
31
52
pyproject_file = self .binder_path ("pyproject.toml" )
32
53
with open (pyproject_file , "rb" ) as _pyproject_file :
33
54
pyproject_toml = tomllib .load (_pyproject_file )
34
55
35
56
if "project" in pyproject_toml :
36
57
if "requires-python" in pyproject_toml ["project" ]:
37
- raw_version = pyproject_toml ["project" ]["requires-python" ]
58
+ # This is the minumum version!
59
+ raw_pyproject_minimum_version = pyproject_toml ["project" ][
60
+ "requires-python"
61
+ ]
38
62
39
- match = VERSION_PAT .match (raw_version )
63
+ match = VERSION_PAT .match (raw_pyproject_minimum_version )
40
64
if match :
41
- return match .group ()
65
+ pyproject_minimum_version = match .group ()
66
+ pyproject_minimum_version_info = pyproject_minimum_version .split (
67
+ "."
68
+ )
42
69
43
- return ""
70
+ if (
71
+ runtime_python_version_info [0 ]
72
+ < pyproject_minimum_version_info [0 ]
73
+ ) or (
74
+ runtime_python_version_info [1 ]
75
+ < pyproject_minimum_version_info [1 ]
76
+ ):
77
+ raise RuntimeError (
78
+ "runtime.txt version not supported by pyproject.toml."
79
+ )
80
+
81
+ self ._python_version = runtime_python_version
82
+ return self ._python_version
44
83
45
84
@lru_cache
46
85
def get_preassemble_script_files (self ):
@@ -55,18 +94,6 @@ def get_preassemble_script_files(self):
55
94
def get_preassemble_scripts (self ):
56
95
"""scripts to run prior to staging the repo contents"""
57
96
scripts = super ().get_preassemble_scripts ()
58
- # install pipenv to install dependencies within Pipfile.lock or Pipfile
59
- if V (self .python_version ) < V ("3.6" ):
60
- # last pipenv version to support 2.7, 3.5
61
- pipenv_version = "2021.5.29"
62
- else :
63
- pipenv_version = "2022.1.8"
64
- scripts .append (
65
- (
66
- "${NB_USER}" ,
67
- f"${{KERNEL_PYTHON_PREFIX}}/bin/pip install --no-cache-dir pipenv=={ pipenv_version } " ,
68
- )
69
- )
70
97
return scripts
71
98
72
99
@lru_cache
@@ -99,12 +126,9 @@ def get_assemble_scripts(self):
99
126
assemble_scripts .append (
100
127
(
101
128
"${NB_USER}" ,
102
- """(cd && \\
103
- PATH="${{KERNEL_PYTHON_PREFIX}}/bin:$PATH" \\
104
- pip install --no-cache-dir --editable {working_directory}
105
- )""" .format (
106
- working_directory = working_directory ,
107
- ),
129
+ """PATH="${KERNEL_PYTHON_PREFIX}/bin:$PATH" \\
130
+ pip install --no-cache-dir --editable .
131
+ """ ,
108
132
)
109
133
)
110
134
0 commit comments