-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
pants: disambiguate test file dependencies #5833
Conversation
We do large sets of files because maintaining manual per-file mapping of dependencies would be a lot of pointless work. Hopefully a future version of pants will have features that make disambiguation more precise, integrating better with dependency inferrence. When that happens we can revert this commit in favor of telling pants how to infer the ambiguous deps instead of hard-coding the deps for a large set of files that might not need the dep.
f5e1908
to
adf89a2
Compare
Note: This PR needs to be merged before I can add pylint. Otherwise, pants will run into these ambiguous deps whenever it runs pylint, and pylint will subsequently fail when pants doesn't add all of the required files/deps to the sandbox it runs pylint in. |
For reference, here are the warnings this resolves:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, sometimes that inference gets confused. For example, in several places our test files import tests.base, but we have multiple **/tests/base.py files, so pants doesn't know which one we're talking about, even though python itself understands exactly what we're talking about.
FYI this is because Pants lets you import from anywhere in your monorepo, which is a key benefit of monorepo. Whereas often when running Python directly, you only run in a subproject of your repo. So, Pants creates a global "module mapping" of e.g. the module to tests.base
to ("dir1/tests/base.py
, "dir2/tests/base.py")`
*In Pants 2.16, we added visibility support, where you can ban certain files from importing others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Background
This is another part of introducing pants, as discussed in various TSC meetings.
Related PRs can be found in:
Overview of this PR
Pants uses dependency inference, which the docs describe as:
However, sometimes that inference gets confused. For example, in several places our test files import
tests.base
, but we have multiple**/tests/base.py
files, so pants doesn't know which one we're talking about, even though python itself understands exactly what we're talking about.So, this PR resolves that ambiguity by explicitly defining dependencies in the BUILD files. In a few cases, we can add that dependency to the one file that needs it. But in other cases, lots of test files have the "ambiguous" import on
tests.base
ortests.unit.base
. Adding the dep to each of those files would be painful to maintain, so I added it to all of the test files in the affected directories.Aside: In each case, I left a comment about why the dep was "ambiguous". I hope that a future version of pants will give us some knobs to tell the inference system how to resolve dependencies it thinks are ambiguous instead of adding it explicitly to more files than necessary. Including "ambiguous" in the BUILD file comment will make it easier to grep and figure out where we can adjust things once pants includes a feature like that.
Relevant Pants documentation