Skip to content

Commit 974a559

Browse files
committed
Reduce code duplication in PyprojectBuildPack
1 parent 6f1f9a8 commit 974a559

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

repo2docker/buildpacks/pyproject/__init__.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,17 @@ 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]
31+
name, version, _ = self.runtime
32+
33+
if name == "python":
34+
runtime_python_version = version
3935
else:
40-
# not a Python runtime (e.g. R, which subclasses this)
41-
# use the default Python
4236
runtime_python_version = self.major_pythons["3"]
4337
self.log.warning(
4438
f"Python version unspecified in runtime.txt, using current default Python version {runtime_python_version}. This will change in the future."
4539
)
4640

4741
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(".")
5142

5243
pyproject_file = self.binder_path("pyproject.toml")
5344
with open(pyproject_file, "rb") as _pyproject_file:
@@ -135,12 +126,9 @@ def get_assemble_scripts(self):
135126
def detect(self):
136127
"""Check if current repo should be built with the pyproject.toml buildpack."""
137128
# first make sure python is not explicitly unwanted
138-
runtime_txt = self.binder_path("runtime.txt")
139-
if os.path.exists(runtime_txt):
140-
with open(runtime_txt) as f:
141-
runtime = f.read().strip()
142-
if not runtime.startswith("python-"):
143-
return False
129+
name, _, _ = self.runtime
130+
if name != "python":
131+
return False
144132

145133
pyproject_file = self.binder_path("pyproject.toml")
146134

0 commit comments

Comments
 (0)