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

Split Python targets into atom vs. generator and use source: str field #13231

Merged
merged 8 commits into from
Oct 13, 2021

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Oct 12, 2021

Now our Python code operates on python_source and python_test targets. This causes some changes.

Dependency inference

Dependency inference no longer runs on python_sources and python_tests, only python_source and python_test. That applies to import analysis, conftest.py, and __init__.py.

This actually speeds up dependency inference! We no longer run import_parser.py twice on the same files.

Before:

❯ hyperfine -r 10 './pants --no-process-execution-local-cache --no-pantsd dependencies src/python::'
Benchmark #1: ./pants --no-process-execution-local-cache --no-pantsd dependencies src/python::
  Time (mean ± σ):      7.650 s ±  0.741 s    [User: 5.794 s, System: 2.141 s]
  Range (min … max):    7.250 s …  9.673 s    10 runs

After:

❯ hyperfine -r 10 './pants --no-process-execution-local-cache --no-pantsd dependencies src/python::'
Benchmark #1: ./pants --no-process-execution-local-cache --no-pantsd dependencies src/python::
  Time (mean ± σ):      5.998 s ±  0.279 s    [User: 3.524 s, System: 0.903 s]
  Range (min … max):    5.708 s …  6.688 s    10 runs

It means that ./pants dependencies src/py:lib now only has explicitly declared dependencies. You have to use --transitive to get the results of dep inference.

Thanks to this change, we can simplify import_parser.py to assume there is only one file.

Lockfile generation

When determining the interpreter constraints to use, we now look at generated targets, not target generators. We only run over the python_source and python_test targets that actually will be used.

This makes us future-proof to an overrides field adding skip_tool to only some of the files. I think it also fixes our dependency resolution for Pylint looking at direct deps?

FieldSet.opt_out no longer worries about file targets

Pytest and MyPy used to skip running on non-file targets. That can be removed now. This unblocks allowing you to explicitly define a python_source/python_test target.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano changed the title WIP [internal] Split Python targets into atom vs. generator and use source: str field [internal] Split Python targets into atom vs. generator and use source: str field Oct 13, 2021
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano changed the title [internal] Split Python targets into atom vs. generator and use source: str field Split Python targets into atom vs. generator and use source: str field Oct 13, 2021
@Eric-Arellano Eric-Arellano marked this pull request as ready for review October 13, 2021 02:02
@Eric-Arellano
Copy link
Contributor Author

Each commit is distinct.

--

I'm still thinking of a good title to put in the changelog to capture the change to dependency inference. Maybe

python_sources and python_tests targets no longer use dependency inference, only python_source and python_test targets

Fixing https://docs.google.com/document/d/1WWQM-X6kHoSCKwItqf61NiKFWNSlpnTC5QNu3ul9RDk/edit# will be important I think, as ./pants dependencies :: no longer includes the generated targets given that we don't "expand" the input roots

@Eric-Arellano
Copy link
Contributor Author

Also, the dependency inference speedup is an excellent example of why I felt so compelled to prioritize this change. As the author of that dep inference implementation, I had no idea we were running the import parser twice! Probably I could have profiled better, but also it's hard to reason about python_library targets generating python_library targets. I think the modeling is much more intuitive now.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks!

This actually speeds up dependency inference! We no longer run import_parser.py twice on the same files.

Whoops.

Fixing https://docs.google.com/document/d/1WWQM-X6kHoSCKwItqf61NiKFWNSlpnTC5QNu3ul9RDk/edit# will be important I think, as ./pants dependencies :: no longer includes the generated targets given that we don't "expand" the input roots

Yea, fixing Specs matching is a blocker for 2.8.0.

@Eric-Arellano
Copy link
Contributor Author

Confirmed that depending on a python_sources target still results in it being an alias for all of its generated targets. Which means that we do not break Pylint, which solely looks at direct deps and not transitive. Great! I was afraid I broke that.

@Eric-Arellano Eric-Arellano merged commit e865418 into pantsbuild:main Oct 13, 2021
@Eric-Arellano Eric-Arellano deleted the python-tgt-split branch October 13, 2021 05:56
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.

2 participants