Skip to content

Commit ec2257d

Browse files
committed
concurrency updates for wheel output handling
Make the build output directory optionally thread-specific and move the handling for updating the simple server index into the build threads. That required moving similar code for build sequence for the pre-built downloaded wheel use case, which in turn required updating some expected output in test scripts. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
1 parent bfa2d1f commit ec2257d

4 files changed

Lines changed: 36 additions & 11 deletions

File tree

e2e/test_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fromager \
4646
build "${DIST}" "${VERSION}" "https://pypi.org/simple"
4747

4848
EXPECTED_FILES="
49-
wheels-repo/build/stevedore-5.2.0-0-py3-none-any.whl
49+
wheels-repo/downloads/stevedore-5.2.0-0-py3-none-any.whl
5050
sdists-repo/downloads/stevedore-5.2.0.tar.gz
5151
sdists-repo/builds/stevedore-5.2.0.tar.gz
5252
sdists-repo/builds/test-output-file.txt

e2e/test_build_settings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fromager \
3939
build "${DIST}" "${VERSION}" "unreachable_url"
4040

4141
EXPECTED_FILES="
42-
wheels-repo/build/stevedore-5.2.0-0-py3-none-any.whl
42+
wheels-repo/downloads/stevedore-5.2.0-0-py3-none-any.whl
4343
sdists-repo/downloads/stevedore-custom-5.2.0.tar.gz
4444
sdists-repo/builds/stevedore-5.2.0.tar.gz
4545
sdists-repo/builds/test-output-file.txt

src/fromager/commands/build.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ def build_sequence(
224224
dist_version=str(resolved_version),
225225
wheel_filename=wheel_filename,
226226
)
227+
server.update_wheel_mirror(wkctx)
228+
# After we update the wheel mirror, the built file has
229+
# moved to a new directory.
230+
wheel_filename = wkctx.wheels_downloads / wheel_filename.name
231+
227232
else:
228233
logger.info(
229234
"%s: building %s==%s", dist_name, dist_name, resolved_version
@@ -232,10 +237,6 @@ def build_sequence(
232237
wkctx, resolved_version, req, source_download_url
233238
)
234239

235-
server.update_wheel_mirror(wkctx)
236-
# After we update the wheel mirror, the built file has
237-
# moved to a new directory.
238-
wheel_filename = wkctx.wheels_downloads / wheel_filename.name
239240
entries.append(
240241
BuildSequenceEntry(
241242
dist_name,
@@ -422,6 +423,12 @@ def _build(
422423
wheel_filename=wheel_filename,
423424
)
424425

426+
server.update_wheel_mirror(wkctx)
427+
428+
# After we update the wheel mirror, the built file has
429+
# moved to a new directory.
430+
wheel_filename = wkctx.wheels_downloads / wheel_filename.name
431+
425432
return wheel_filename
426433

427434

@@ -518,6 +525,8 @@ def build_parallel(
518525
parallel. Use --jobs to limit the number of concurrent builds.
519526
520527
"""
528+
wkctx.enable_parallel_builds()
529+
521530
server.start_wheel_server(wkctx)
522531
wheel_server_urls = [wkctx.wheel_server_url]
523532
if cache_wheel_server_url:
@@ -604,10 +613,6 @@ def build_parallel(
604613
for node, future in zip(buildable_nodes, futures, strict=True):
605614
try:
606615
wheel_filename = future.result()
607-
server.update_wheel_mirror(wkctx)
608-
# After we update the wheel mirror, the built file has
609-
# moved to a new directory.
610-
wheel_filename = wkctx.wheels_downloads / wheel_filename.name
611616
entries.append(
612617
BuildSequenceEntry(
613618
node.canonicalized_name,

src/fromager/context.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import pathlib
5+
import threading
56
from urllib.parse import urlparse
67

78
from packaging.requirements import Requirement
@@ -52,7 +53,7 @@ def __init__(
5253
self.sdists_downloads = self.sdists_repo / "downloads"
5354
self.sdists_builds = self.sdists_repo / "builds"
5455
self.wheels_repo = pathlib.Path(wheels_repo).absolute()
55-
self.wheels_build = self.wheels_repo / "build"
56+
self.wheels_build_base = self.wheels_repo / "build"
5657
self.wheels_downloads = self.wheels_repo / "downloads"
5758
self.wheels_prebuilt = self.wheels_repo / "prebuilt"
5859
self.wheel_server_dir = self.wheels_repo / "simple"
@@ -74,6 +75,25 @@ def __init__(
7475
)
7576
self.time_description_store: dict[str, str] = {}
7677

78+
self._parallel_builds = False
79+
80+
def enable_parallel_builds(self) -> None:
81+
self._parallel_builds = True
82+
83+
def disable_parallel_builds(self) -> None:
84+
self._parallel_builds = False
85+
86+
@property
87+
def wheels_build(self) -> pathlib.Path:
88+
# when parallel builds are enabled, return a path that is unique for the
89+
# current thread to avoid collisions when creating output files
90+
if self._parallel_builds:
91+
thread_path = self.wheels_build_base / f"{threading.get_native_id()}"
92+
thread_path.mkdir(parents=True, exist_ok=True)
93+
return thread_path
94+
else:
95+
return self.wheels_build_base
96+
7797
@property
7898
def pip_wheel_server_args(self) -> list[str]:
7999
args = ["--index-url", self.wheel_server_url]

0 commit comments

Comments
 (0)