@@ -28,19 +28,58 @@ def python_version(self):
2828 if hasattr (self , "_python_version" ):
2929 return self ._python_version
3030
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+
3152 pyproject_file = self .binder_path ("pyproject.toml" )
3253 with open (pyproject_file , "rb" ) as _pyproject_file :
3354 pyproject_toml = tomllib .load (_pyproject_file )
3455
3556 if "project" in pyproject_toml :
3657 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+ ]
3862
39- match = VERSION_PAT .match (raw_version )
63+ match = VERSION_PAT .match (raw_pyproject_minimum_version )
4064 if match :
41- return match .group ()
65+ pyproject_minimum_version = match .group ()
66+ pyproject_minimum_version_info = pyproject_minimum_version .split (
67+ "."
68+ )
4269
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
4483
4584 @lru_cache
4685 def get_preassemble_script_files (self ):
@@ -55,18 +94,6 @@ def get_preassemble_script_files(self):
5594 def get_preassemble_scripts (self ):
5695 """scripts to run prior to staging the repo contents"""
5796 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- )
7097 return scripts
7198
7299 @lru_cache
@@ -99,12 +126,9 @@ def get_assemble_scripts(self):
99126 assemble_scripts .append (
100127 (
101128 "${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+ """ ,
108132 )
109133 )
110134
0 commit comments