Skip to content

Conversation

@ooooo-create
Copy link

Summary of changes

If the search failed to find any candidates (len(candidates) == 0) in a directory that had no subdirectories or multiple subdirectories (len(dirs) != 1), the condition evaluated to True. This triggered the assertion checks for candidates == 1, resulting in a confusing AssertionError: Multiple {suffix} directories found, even though zero candidates were actually found.

Closes

Pull Request Checklist

Copilot AI review requested due to automatic review settings January 23, 2026 10:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes _find_info_directory so that a “no candidates found” case no longer triggers the misleading Multiple {suffix} directories found assertion, and instead fails with the intended “No {suffix} directory found” error.

Changes:

  • Split the prior combined condition into: (1) return when a {suffix} directory is found, (2) abort the walk early when traversal becomes ambiguous (len(dirs) != 1).
  • Prevent the incorrect assertion path when candidates is empty.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@abravalheri
Copy link
Contributor

abravalheri commented Jan 23, 2026

Hi @ooooo-create, thank you very much for the contribution.

Could you please fill in an issue report containing the description of the problem you are trying to solve first, with a minimal reproducible example?

These checks are somewhat old in the codebase, despite being refactored a bunch of times, this check has always been present in one form or other since the introduction of PEP 517. So I would like to understand a bit better which kinds of problems you may have had.

In a different iteration, this piece of code had a different message: f"Exactly one {suffix} should have been produced". Would that be a better error message?

@abravalheri abravalheri added the Needs Repro Issues that need a reproducible example. label Jan 23, 2026
@ooooo-create
Copy link
Author

Could you please fill in an issue report containing the description of the problem you are trying to solve first, with a minimal reproducible example?

Thanks for your suggestion. Here is a bash script to reproduce it

mkdir /tmp/proj1
cd /tmp/proj1

touch setup.py

python -m venv .venv
.venv/bin/python -m pip install -U pip
.venv/bin/python -m pip install -e .

However, I ran into this issue because I had multiple setup() calls in my setup.py that were triggered by different conditions. I accidentally caused the execution flow to bypass all of them, and realized that the resulting error—AssertionError: Multiple .egg-info directories found—was actually misleading.

In a different iteration, this piece of code had a different message: f"Exactly one {suffix} should have been produced". Would that be a better error message?

yes~ it's better, i will take it.

@abravalheri
Copy link
Contributor

I see... Thank you very much.

Yeah, it is an assert statement, which probably means that the original author never expected this statement to be reached in a real scenario (and also they were more concerned with the case where multiple dirs are found) ... and I see why it is triggering in your build.

I think we should go with a better error message and avoid changing too much the code itself.

@ooooo-create ooooo-create changed the title Fix logic error in _find_info_directory causing misleading Multiple directories found assertion Fix misleading Multiple directories found assertion in _find_info_directory Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Repro Issues that need a reproducible example.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants