Skip to content

Commit 863898e

Browse files
committed
Remove non-used code and updated hardcoded code #339
Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent c92f830 commit 863898e

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

etc/scripts/build_nix_docker.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,6 @@ def read_pyproject_toml():
9292

9393
return pyproject_data
9494

95-
96-
def extract_python_version_from_pyproject():
97-
"""Extract Python version from pyproject.toml and return major.minor"""
98-
pyproject_data = read_pyproject_toml()
99-
requires_python = pyproject_data["project"].get("requires-python", "")
100-
101-
if requires_python:
102-
import re
103-
104-
# Match any version pattern: 2.7, 3.8, 3.13, 4.0, etc.
105-
version_match = re.search(r"(\d+)\.(\d+)", requires_python)
106-
if version_match:
107-
major = version_match.group(1)
108-
minor = version_match.group(2)
109-
return f"{major}.{minor}"
110-
111-
# Default to current Python version if not specified
112-
return f"{sys.version_info.major}.{sys.version_info.minor}"
113-
114-
11595
def extract_project_meta(pyproject_data):
11696
# Extract project metadata from pyproject.toml data.
11797
project_data = pyproject_data["project"]
@@ -191,9 +171,8 @@ def extract_tags_from_url(url, major, minor):
191171
return tags
192172

193173

194-
def is_compatible_wheel(url, python_version):
174+
def is_compatible_wheel(url, major, minor):
195175
"""Check if wheel is compatible using tag matching"""
196-
major, minor = python_version.split(".")
197176
wheel_tags = extract_tags_from_url(url, major, minor)
198177

199178
# Check Python compatibility
@@ -208,14 +187,20 @@ def is_compatible_wheel(url, python_version):
208187

209188

210189
def create_defualt_nix(dependencies_list, meta_dict):
190+
python_version = meta_dict["requires_python"]
191+
py_version_major, py_version_minor = python_version.split(".")
192+
if py_version_minor == "0":
193+
python_use = f"python{py_version_major}"
194+
else:
195+
python_use = f"python{py_version_major}{py_version_minor}"
211196
# Create a default.nix
212197
nix_content = """
213198
{
214199
pkgs ? import <nixpkgs> { },
215200
}:
216201
217202
let
218-
python = pkgs.python313;
203+
python = pkgs.""" + python_use + """;
219204
220205
# Helper function to create packages with specific versions and disabled tests
221206
buildCustomPackage = { pname, version, format ? "wheel", src, ... }@attrs:
@@ -247,7 +232,6 @@ def create_defualt_nix(dependencies_list, meta_dict):
247232
"""
248233
need_review_packages_list = []
249234
deps_size = len(dependencies_list)
250-
python_version = meta_dict["requires_python"]
251235
for idx, dep in enumerate(dependencies_list):
252236
print("Processing {}/{}: {}".format(idx + 1, deps_size, dep["name"]))
253237
name = dep["name"]
@@ -299,7 +283,7 @@ def create_defualt_nix(dependencies_list, meta_dict):
299283
for component in url_section:
300284
if component.get("packagetype") == "bdist_wheel":
301285
whl_url = component.get("url")
302-
if not is_compatible_wheel(whl_url, python_version):
286+
if not is_compatible_wheel(whl_url, py_version_major, py_version_minor):
303287
continue
304288
whl_sha256 = get_sha256_hash(whl_url)
305289
nix_content += " " + name + " = buildCustomPackage {\n"

0 commit comments

Comments
 (0)