Skip to content

Commit 2b82b1b

Browse files
committed
Keep order of packages to build in wheelbuilder so we can optimize build times
1 parent 18b3c80 commit 2b82b1b

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

scripts/wheelbuilder/build_wheels.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,28 @@ def create_venv():
113113

114114

115115
def build_wheels(pip):
116-
packages_selected = [s for s in os.environ.get("PACKAGES_TO_BUILD", "").split(",") if s]
117-
packages_to_build = set()
118116
with open(join(dirname(__file__), "packages.txt")) as f:
119-
for line in f.readlines():
120-
line = line.strip()
121-
name, version = line.split("==")
122-
if not packages_selected or name in packages_selected or line in packages_selected:
123-
packages_to_build.add(line)
117+
packages_from_txt = [tuple(l.strip().split("==")) for l in f]
118+
packages_to_build = []
119+
for s in os.environ.get("PACKAGES_TO_BUILD", "").split(","):
120+
s = s.strip()
121+
if not s:
122+
continue
123+
elif "==" in s:
124+
name, version = s.split("==")
125+
else:
126+
name, version = s, None
127+
for n, v in packages_from_txt:
128+
if n == name:
129+
version = v
130+
break
131+
if not version:
132+
print("ERROR: Asked to build", s, "but no version given")
133+
return False
134+
packages_to_build.append((name, version))
135+
if not packages_to_build:
136+
packages_to_build = packages_from_txt
137+
print("About to build", packages_to_build)
124138
scriptdir = abspath(join(dirname(__file__), sys.platform))
125139
if sys.platform == "win32":
126140
script_ext = "bat"
@@ -133,8 +147,7 @@ def build_wheels(pip):
133147
remaining_packages = 0
134148
while remaining_packages != len(packages_to_build):
135149
remaining_packages = len(packages_to_build)
136-
for spec in packages_to_build.copy():
137-
name, version = spec.split("==")
150+
for name, version in packages_to_build.copy():
138151
whl_count = len(glob("*.whl"))
139152
script = f"{name}.{version}.{script_ext}".lower()
140153
if script not in available_scripts:
@@ -153,13 +166,13 @@ def build_wheels(pip):
153166
if p.returncode != 0:
154167
continue
155168
if len(glob("*.whl")) > whl_count:
156-
packages_to_build.remove(spec)
169+
packages_to_build.remove((name, version))
157170
continue
158171
print(script, "did not build a wheel, we will do so now", flush=True)
159172
print("Building", name, version, flush=True)
160-
p = subprocess.run([pip, "wheel", spec])
173+
p = subprocess.run([pip, "wheel", f"{name}=={version}"])
161174
if p.returncode == 0:
162-
packages_to_build.remove(spec)
175+
packages_to_build.remove((name, version))
163176
if packages_to_build:
164177
print("Failed to build all packages, the following packages failed")
165178
print(packages_to_build)

0 commit comments

Comments
 (0)