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

Add experimental lockfile support to IPython, Pytest, and Pylint #12491

Merged
merged 6 commits into from
Aug 6, 2021

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Aug 3, 2021

Shading

These tools all run with user requirements. As before, we combine the "tool pex" with the user requirements pex via --pex-path.

I thought that tool lockfiles would cause issues that it's likely for the tool requirements to conflict with the user requirements. But turns out, this has always been the case in Python land. Before, the tool would still have pinned deps in its PEX file, only, those pins might float over time without a lockfile. This PR changes nothing in terms of the need for shading (#9206).

Performance concerns

As with Flake8, Bandit, and Setuptools, we must consult the codebase to determine which interpreter constraints the tool will be run with. This does have a performance hit, especially for generating Pytest's lockfile because we must consider the transitive deps of each python_tests target.

There are four proposals floating to improve the performance. All are compatible with the others:

  1. When generating the lockfile via ./pants tool-lock, continue to inspect the whole repo. But when checking at call sites if the lockfile is stale, only inspect the code in question: create what the PythonToolLockfile would be if it were just for that code, and ensure the ICs are compatible w/ the checked-in file.
  2. Stop treating the IC field as the constraints for the source itself, and start treating it as constraints for the whole transitive closure. This would allow us to look only at the target roots, w/o needing to resolve transitive dependencies.
  3. Allow repos to opt-out of mixed interpreter constraints and only set ICs via [python-setup].interpreter_constraints (Add [python-setup].disable_mixed_interpreter_constraints for repositories not using the interpreter_constraints field #12495). This has no impact if you are using mixed ICs, but greatly speeds things up for other repos not using the mechanism.
  4. Add an ignore option to our check for stale lockfiles. Users could risk ignoring for desktop builds, and then error in CI.

For now, this PR provides a common denominator.

# 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] Add experimental lockfile support to IPython, Pytest, and Pylint Add experimental lockfile support to IPython, Pytest, and Pylint Aug 6, 2021
@Eric-Arellano Eric-Arellano marked this pull request as ready for review August 6, 2021 01:07
# 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]
Comment on lines +143 to +148
# While Flake8 will run in partitions, we need a single lockfile that works with every
# partition.
#
# This ORs all unique interpreter constraints. When paired with
# `InterpreterConstraints.partition_by_major_minor_versions`, the net effect is that every
# possible Python interpreter used will be covered.
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Is it worth deduping these IC calculations now across Bandit/Flake8/etc, or are you expecting more change soon that might cause them to need to be separate rules like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to dedupe, but we can't because of the skip_field options. I think the correctness could be important here. Let's say you don't run Pylint on your Py2 only code: we need to ignore those targets when determining the ICs for the lockfile.

Maybee we decide to give up on that correctness, but I want to start with a baseline of what is fully correct.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Sure... but that filtering feels like it could be generalized?

@Eric-Arellano Eric-Arellano merged commit 8cae241 into pantsbuild:main Aug 6, 2021
@Eric-Arellano Eric-Arellano deleted the pytest-lockfile branch August 6, 2021 21:12
@stuhood stuhood mentioned this pull request Aug 6, 2021
Eric-Arellano added a commit that referenced this pull request Aug 18, 2021
#12491 did not properly add lockfiles to Pylint. The option was registered, but not being consumed.

This was trickier to implement than other tool lockfiles because we must consider `[pylint].source_plugins`, whose requirement strings and interpreter constraints must be considered. 

[ci skip-rust]
[ci skip-build-wheels]
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