Skip to content

fix use of log context in bootstrapper #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/fromager/bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def __init__(
self._build_order_filename = self.ctx.work_dir / "build-order.json"

def bootstrap(self, req: Requirement, req_type: RequirementType) -> Version:
token = requirement_ctxvar.set(req)
try:
return self._bootstrap(req=req, req_type=req_type)
finally:
requirement_ctxvar.reset(token)

def _bootstrap(self, req: Requirement, req_type: RequirementType) -> Version:
constraint = self.ctx.constraints.get_constraint(req.name)
if constraint:
logger.info(
Expand Down Expand Up @@ -397,11 +404,9 @@ def _handle_build_requirements(
self.progressbar.update_total(len(build_dependencies))

for dep in self._sort_requirements(build_dependencies):
token = requirement_ctxvar.set(dep)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change build_environment.maybe_install() has no longer the correct context var. #598 should fix the bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to have a look at that. The bootstrap() function should be the top level function, so handling the context there should cover everything.

try:
resolved = self.bootstrap(req=dep, req_type=build_type)
except Exception as err:
requirement_ctxvar.reset(token)
raise ValueError(f"could not handle {self._explain}") from err
# We may need these dependencies installed in order to run build hooks
# Example: frozenlist build-system.requires includes expandvars because
Expand All @@ -414,7 +419,6 @@ def _handle_build_requirements(
dep_req_type=build_type,
)
self.progressbar.update()
requirement_ctxvar.reset(token)

def _download_prebuilt(
self,
Expand Down
2 changes: 0 additions & 2 deletions src/fromager/commands/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ def bootstrap(
)

for req in to_build:
token = requirement_ctxvar.set(req)
bt.bootstrap(req, requirements_file.RequirementType.TOP_LEVEL)
progressbar.update()
requirement_ctxvar.reset(token)

# If we put pre-built wheels in the downloads directory, we should
# remove them so we can treat that directory as a source of wheels
Expand Down
Loading