Skip to content

Commit 577cb1b

Browse files
committed
Add builldpack for pyproject to list of buildpack
Related to #1427
1 parent c256c67 commit 577cb1b

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed

repo2docker/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
LegacyBinderDockerBuildPack,
3434
NixBuildPack,
3535
PipfileBuildPack,
36+
PyprojectBuildPack,
3637
PythonBuildPack,
3738
RBuildPack,
3839
)
@@ -100,6 +101,7 @@ def _default_log_level(self):
100101
RBuildPack,
101102
CondaBuildPack,
102103
PipfileBuildPack,
104+
PyprojectBuildPack,
103105
PythonBuildPack,
104106
],
105107
config=True,

repo2docker/buildpacks/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
from .legacy import LegacyBinderDockerBuildPack
66
from .nix import NixBuildPack
77
from .pipfile import PipfileBuildPack
8+
from .pyproject import PyprojectBuildPack
89
from .python import PythonBuildPack
910
from .r import RBuildPack

repo2docker/buildpacks/pyproject/__init__.py

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)