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 tool lockfiles for Black, Isort, Yapf, Coverage.py, Lambdex, and Protobuf MyPy #12357

Merged
merged 11 commits into from
Jul 16, 2021

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Jul 15, 2021

These tools are simple to support: they run entirely independently of user code, and they get their interpreter constraints from a subsystem rather than from user code.

*Black is temporarily not used because it does not play nicely with interpreter constraints: #12200.

Tools that still need lockfiles

Need to consider user interpreter constraints:

  • Bandit
  • Flake8
  • setuptools
  • pip-tools

Need to be mixed into user lockfiles (or have shading):

  • MyPy
  • Pylint
  • Pytest
  • IPython(?)

…x, and Protobuf MyPy

# 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
Copy link
Contributor Author

Blocked by #12200. The Black lockfile generated w/ Py36 does not work with 3.9, and vice versa. It can be fixed by manually adding environment markers.

# 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 tool lockfiles for Black, Isort, Coverage.py, Lambdex, and Protobuf MyPy Add experimental tool lockfiles for Black, Isort, Coverage.py, Lambdex, and Protobuf MyPy Jul 15, 2021
@Eric-Arellano Eric-Arellano marked this pull request as ready for review July 15, 2021 18:53
# 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]
Copy link
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! One thing that would be fine in a followup.

Also, the title needs an update to remove black, maybe? Or have we still added the support, but not enabled it yet?

# Register the UnionRule.
register_lockfile: ClassVar[bool] = False
default_lockfile_resource: ClassVar[tuple[str, str] | None] = None
default_lockfile_file_path: ClassVar[str | None] = None
Copy link
Member

Choose a reason for hiding this comment

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

Missed this the first time around, but: the fact that this gets baked into a Github URL will result in an incorrect URL if someone outside of the pantsbuild/pants repo declares a PythonToolRequirementsBase instance in a plugin.

Maybe make the field optional (even when default_lockfile_resource is set), and then declare it as:

    default_lockfile_file_url: ClassVar[str | None] = None

...and have instances in pantsbuild/pants call git_url(cls.default_lockfile_file_path) explicitly? Callers outside the repo could construct a URL or not if they didn't want to bother.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, good point. Will fix here.

@Eric-Arellano
Copy link
Contributor Author

Also, the title needs an update to remove black, maybe? Or have we still added the support, but not enabled it yet?

Yeah, Black support is technically added. Just the default file is not going to work if you don't use Python 3.6. But you can still generate your own lockfile.

@Eric-Arellano Eric-Arellano changed the title Add experimental tool lockfiles for Black, Isort, Coverage.py, Lambdex, and Protobuf MyPy Add experimental tool lockfiles for Black, Isort, Yapf, Coverage.py, Lambdex, and Protobuf MyPy Jul 16, 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]
…more-lockfiles

[ci skip-rust]

[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano merged commit 5df98d7 into pantsbuild:main Jul 16, 2021
@Eric-Arellano Eric-Arellano deleted the more-lockfiles branch July 16, 2021 02:15
Eric-Arellano added a commit that referenced this pull request Jul 26, 2021
These tool lockfiles are trickier than #12357 because they get their interpreter constraints from the users' code, rather than subsystems. So, when generating a lockfile, we query all their code to calculate the constraint.

It's even trickier that Bandit and Flake8 partition by interpreter constraints, e.g. Py27 code running separately than Py37. Ideally, the single lockfile will be compatible with all partitions. To do this, we OR each distinct IC encountered. Using the technique from #12389, we'll try to generate a lockfile for each possible interpreter and then will merge into a single lockfile.

Finally, this updates Black's generation to mirror our actual logic: if the user's code is Py38+ only, we automatically default to the ICs being Py38+ instead of Py36+.

--

With this PR, we have now implemented lockfiles for:

- Bandit
- Black
- Docformatter
- Flake8
- isort
- Yapf
- Coverage.py
- Lambdex
- Protobuf MyPy plugin
- setuptools

These remain:
- MyPy
- Pylint
- Pytest
- IPython
 - pip-tools

[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