Skip to content
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

Address circular imports complaints by Sphinx 7.2+ #4023

Merged
merged 5 commits into from
Aug 23, 2023

Conversation

abravalheri
Copy link
Contributor

Summary of changes

The latest version of sphinx started failing in #4020 (comment) due to circular imports.

Examples of the error messages are:

ImportError: cannot import name 'Distribution' from partially initialized module 'setuptools.dist'

AttributeError: partially initialized module 'setuptools' has no attribute 'version' (most likely due to a circular import)

Failed to import class 'Command' from module 'setuptools'

In this PR, I am attempting to address this problem.

The approach I used was:

  • Rewrite the imports in setuptools/__init__.py, setuptools/monkey.py and setuptools/dist.py to avoid circular imports.
    • I also took this chance to try to tide up a bit (e.g. sorting them, separating import ... and from ... import ... statements, etc)
  • I had to change slightly the way we are importing setuptools.extern.packaging and setuptools/depends.py and setuptools/tests/test_setuptools.py because for some reason the tests where complaining that the Version class was differing from itself (maybe the module is loaded twice?)

Closes

Pull Request Checklist

@abravalheri abravalheri marked this pull request as ready for review August 18, 2023 13:12
henryiii added a commit to scikit-build/scikit-build-core that referenced this pull request Aug 21, 2023
Temporary fix while waiting for
pypa/setuptools#4023.

Signed-off-by: Henry Schreiner <[email protected]>
henryiii pushed a commit to scikit-build/scikit-build-core that referenced this pull request Aug 21, 2023
pypa/setuptools#4023 Fixes the issue

Signed-off-by: Cristian Le <[email protected]>
Somehow before this change the tests were failing because the ``Version`` class
imported in the tests was different from the ``Version`` class produced
in the code under test.
@abravalheri
Copy link
Contributor Author

Since the problem with sphinx seems to be impacting other users, I will go ahead and merge this as soon as the CI is green (but I will not immediately publish a new release). Hopefully it is just some refactoring that does not impact negatively the project.

@abravalheri abravalheri merged commit 2733fc3 into pypa:main Aug 23, 2023
21 checks passed
@abravalheri abravalheri deleted the circular-imports branch August 23, 2023 11:08
abravalheri added a commit to abravalheri/setuptools that referenced this pull request Aug 29, 2023
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.

1 participant