Skip to content

(refactor): RequirementsResolver should have only one method resolve()#949

Open
rd4398 wants to merge 1 commit intopython-wheel-build:mainfrom
rd4398:single-resolve-mehtod
Open

(refactor): RequirementsResolver should have only one method resolve()#949
rd4398 wants to merge 1 commit intopython-wheel-build:mainfrom
rd4398:single-resolve-mehtod

Conversation

@rd4398
Copy link
Contributor

@rd4398 rd4398 commented Mar 5, 2026

This commits attempts to refactor the RequirementsResolver to have only one method resolve() instead of separate methods

It is consistent with existing code in resolver.py where there is only single method for resolution

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

This commits attempts to refactor the RequirementsResolver
to have only one method resolve() instead of separate
methods

It is consistent with existing code in resolver.py
where there is only single method for resolution

Signed-off-by: Rohan Devasthale <rdevasth@redhat.com>
@rd4398 rd4398 requested a review from a team as a code owner March 5, 2026 20:50
@rd4398 rd4398 requested a review from dhellmann March 5, 2026 20:51
@mergify mergify bot added the ci label Mar 5, 2026
# Delegate to RequirementResolver (handles caching internally)
# Delegate to RequirementResolver
parent_req = self.why[-1][1] if self.why else None
pbi = self.ctx.package_build_info(req)
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this step to get the pbi could move inside the resolver, too.

if cached_resolution and not req.url:
wheel_url, resolved_version = cached_resolution
url, resolved_version = cached_resolution
logger.debug(f"resolved from previous bootstrap to {resolved_version}")
Copy link
Member

Choose a reason for hiding this comment

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

I think the logic of this function would be clearer if you returned early in any cases where you have enough information. So for example here you could just return. Then the else on the next line is not needed and the rest of the code can be moved left 1 indentation level.

)
url, resolved_version = wheels.resolve_prebuilt_wheel(
ctx=self.ctx, req=req, wheel_server_urls=servers, req_type=req_type
)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, if we get here and have a result returning means you don't need the else on the next line.

# Cache the result
result = (wheel_url, resolved_version)
result = (url, resolved_version)
self.cache_resolution(req, result)
Copy link
Member

Choose a reason for hiding this comment

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

Making those other structural changes could mean modifying the cache in multiple places. To void that, you could have resolve() look in the cache, call another method if it doesn't find something, then save the results of the other method to the cache before returning. Then all of the more complex logic for dealing with the resolution is in that _resolve() (for example) method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants