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

Test for circular imports in project #779

Merged
merged 8 commits into from
Jan 20, 2022
Merged

Conversation

cidrblock
Copy link
Collaborator

@cidrblock cidrblock commented Jan 20, 2022

Resolves: #778

Test for circular imports in all local packages and modules.

This ensures all internal packages can be imported right away without any need to import some other module before doing so.

Related: #777

@cidrblock cidrblock added bot:chronographer:skip tests Related to testing and CI labels Jan 20, 2022
@cidrblock cidrblock self-assigned this Jan 20, 2022
@cidrblock cidrblock requested review from a team, ssbarnea, ganeshrn and priyamsahoo January 20, 2022 16:02
@webknjaz webknjaz added the gate label Jan 20, 2022
Copy link
Contributor

@ansible-zuul ansible-zuul bot left a comment

Choose a reason for hiding this comment

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

LGTM!

@ansible-zuul ansible-zuul bot removed the gate label Jan 20, 2022
@cidrblock cidrblock added the gate label Jan 20, 2022
Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

(now I need to go and fix it too in one of the projects using this module)

tests/unit/test_circular_imports.py Outdated Show resolved Hide resolved
tests/unit/test_circular_imports.py Outdated Show resolved Hide resolved
tests/unit/test_circular_imports.py Outdated Show resolved Hide resolved
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
@ansible-zuul ansible-zuul bot removed the gate label Jan 20, 2022
cidrblock and others added 2 commits January 20, 2022 09:19
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
@cidrblock
Copy link
Collaborator Author

Related: ansible/ansible-runner#969

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
set(
chain.from_iterable(
_discover_path_importables(Path(p), pkg.__name__)
for p in pkg.__path__ # type: ignore[attr-defined]
Copy link
Member

Choose a reason for hiding this comment

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

Check if this is still necessary:

Suggested change
for p in pkg.__path__ # type: ignore[attr-defined]
for p in pkg.__path__

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tests/unit/test_circular_imports.py:36:26: error: Module has no attribute
"__path__"  [attr-defined]
                    for p in pkg.__path__
                             ^
Found 1 error in 1 file (checked 220 source files)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

seems so

Copy link
Member

Choose a reason for hiding this comment

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

@cidrblock
Copy link
Collaborator Author

related: #758

@cidrblock
Copy link
Collaborator Author

recheck

@cidrblock cidrblock added the gate label Jan 20, 2022
@ansible-zuul ansible-zuul bot merged commit cd27e3c into ansible:main Jan 20, 2022
ansible-zuul bot pushed a commit that referenced this pull request Jan 24, 2022
Change the order of relative imports

This modifies the order of relative import statements.
Fixes: #780
Prior to this change the order was
import .sibling
import ..parent
import ...grandparent

after this change
import ...grandparent
import ..parent
import .sibling

The resulting order is the default for isort which decreases the amount of custom configuration within the repo and results in a sorting order starting with "least local" to "most local".
This follow on work after #777, which was intended to minimize the changes in the repo related to the cleanup. #779 was also implemented to help detect any issues arising from a change in order.
Some conversation and history about the ordering can be found here: PyCQA/isort#417

Reviewed-by: Sviatoslav Sydorenko <webknjaz+github/profile@redhat.com>
Reviewed-by: None <None>
cidrblock added a commit to cidrblock/ansible-navigator that referenced this pull request Jan 24, 2022
Change the order of relative imports

This modifies the order of relative import statements.
Fixes: ansible#780
Prior to this change the order was
import .sibling
import ..parent
import ...grandparent

after this change
import ...grandparent
import ..parent
import .sibling

The resulting order is the default for isort which decreases the amount of custom configuration within the repo and results in a sorting order starting with "least local" to "most local".
This follow on work after ansible#777, which was intended to minimize the changes in the repo related to the cleanup. ansible#779 was also implemented to help detect any issues arising from a change in order.
Some conversation and history about the ordering can be found here: PyCQA/isort#417

Reviewed-by: Sviatoslav Sydorenko <webknjaz+github/profile@redhat.com>
Reviewed-by: None <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Related to testing and CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TODO] Implement smoke/sanity testing of circular imports
3 participants