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

Properly handle PEP 420 namespace packages #10183

Merged
merged 10 commits into from Jun 29, 2020

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Jun 27, 2020

Problem

When using PEP 420 namespace packages, you must leave off the __init__.py file. However, Pants was automatically injecting __init__.py files when missing, which would break PEP 420.

For example, Toolchain does not use __init__.py and has both src/python/toolchain/ and test/python/toolchain/, which both map to the module toolchain. So, v2 MyPy was failing because it detected an empty __init__.py file in both packages.

Solution

Stop ever generating __init__.py files, now that we automatically read them from the filesystem via #10166.

This means that Pants will much closer emulate real Python semantics. If a user is using PEP 420, we'll respect that. If they are missing __init__.py and it would cause normal Python to fail, we will also fail, rather than trying to magically fix the issue.

This PR also fixes our auto-discovery of PathGlobs when the input snapshot was stripped. The logic failed to account for how the input is stripped, yet PathGlobs is never stripped.

[ci skip-rust-tests]

# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
Copy link
Sponsor Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

Yay! Much better.

I can't figure out how to get PEP 420 working with MyPy

# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
Why is MyPy so much harder to get working?!

# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
…it__.py

# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
@Eric-Arellano
Copy link
Contributor Author

MyPy is still not working like I'd expect, but going to merge this because it makes substantial progress for multiple different Python tasks. Will fix MyPy in a dedicated PR.

@Eric-Arellano Eric-Arellano merged commit 791be48 into pantsbuild:master Jun 29, 2020
@Eric-Arellano Eric-Arellano deleted the stop-generating-inits branch June 29, 2020 22:07
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.

None yet

2 participants