Skip to content

Fix RecursionError in get_all_imports for packages with relative imports - #282

Open
cpruijsen wants to merge 1 commit into
adafruit:mainfrom
cpruijsen:fix/issue-275
Open

cpruijsen wants to merge 1 commit into
adafruit:mainfrom
cpruijsen:fix/issue-275

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

circup install --auto crashes with RecursionError on packages whose __init__.py re-exports from
submodules. get_all_imports in circup/command_utils.py resolves each import to a module name and
recurses, and a bare . or .. carries no module name: the resolution appends nothing, producing a
name ending in a dot that resolves back to the same place, so the recursion has no base case.

Two changes. A bare relative entry, one that is nothing but dots, is skipped, since there is no module
named for it to resolve to. And relative paths are resolved explicitly against the current module,
dropping one package level for a leading dot and two for a double dot, rather than being handled by
the same branch as absolute imports.

The continue after requested_installs.append is the third: an import already matched as a
requested install was falling through into the resolution below and being processed twice.

Tests cover a package with a re-exporting __init__.py, which recursed without bound before.

Fixes #275

Skip bare "."/".." entries emitted by imports_from_code for `from .. import x` partials: resolving them produced module names with a trailing dot that recursed without bound. Also deduplicate on the resolved module name and record it in visited before recursing, so a submodule is no longer re-walked through every relative-import entry in its parent's __init__.py.

Fixes adafruit#275
@tannewt
tannewt requested a review from FoamyGuy September 14, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

circup install --auto hits RecursionError on packages with re-exporting __init__.py

1 participant