Skip to content

Audit and update requirements for Python tools.#18431

Merged
benjyw merged 4 commits intopantsbuild:mainfrom
benjyw:audit_python_tools
Mar 9, 2023
Merged

Audit and update requirements for Python tools.#18431
benjyw merged 4 commits intopantsbuild:mainfrom
benjyw:audit_python_tools

Conversation

@benjyw
Copy link
Contributor

@benjyw benjyw commented Mar 7, 2023

#18418 added support for resolving tools from a user resolve.

Specifically, it added a requirements option for each tool that is expected to contain
very loose requirements that we expect Pants to support.

We initialized the default value for that option from the existing version and
extra_requirements fields. However those were often overly-constrained, sometimes
to a single version.

This PR audits all the tools' defaults and in various cases does one or both of:

  1. Update default_version to a newer version so we can regen more up-to-date lockfiles.
  2. Explicitly set default_requirements to something loose but likely compatible.

Of course it's hard to know which currently available tool versions Pants is compatible with,
unless we test against them. And it's impossible to know which future versions Pants will remain
compatible with.

So we assume that tools are semver-adherent, so that floating up in the same major version is safe.
Updating to newer versions lets us at least start to test against some newer versions, and is
also overdue, since many of our default tool versions are quite old. The proof that these upgrades
are compatible is in the passing tests.

At some point soon we will deprecate version and extra_requirements in favor of using
user lockfiles for custom tool versions.

Copy link
Contributor

@jsirois jsirois left a comment

Choose a reason for hiding this comment

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

I've started using the dedicated semver compatible syntax in my Pants using projects for this: https://peps.python.org/pep-0440/#compatible-release

@benjyw
Copy link
Contributor Author

benjyw commented Mar 7, 2023

I'm going to hold off on merging this until I've written docs for the new way of updating versions.

Upgrading some tools may break things for users! E.g., mypy will report things it did not previously report. I'm not sure how to resolve that short of providing a very easy escape hatch. The alternative is to only upgrade tools on a Pants major version bump, which seems extreme.

@benjyw
Copy link
Contributor Author

benjyw commented Mar 7, 2023

Although I guess 2.16 is just starting its stabilization so I have time to write docs...

@benjyw benjyw force-pushed the audit_python_tools branch from fd8dc6a to b3407b8 Compare March 8, 2023 01:57
@benjyw benjyw force-pushed the audit_python_tools branch from b3407b8 to 20e19a3 Compare March 8, 2023 02:04
@benjyw benjyw force-pushed the audit_python_tools branch from 1f3e513 to b88c8aa Compare March 8, 2023 05:06
@benjyw benjyw force-pushed the audit_python_tools branch from b88c8aa to bc3c062 Compare March 8, 2023 05:50
Copy link
Member

@kaos kaos left a comment

Choose a reason for hiding this comment

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

Sorry for the large number of comments. Took me half-way through before I had most of the details here figured out.

The main theme concludes to:

  • I think that we want to swap the order of declaring defaults so we can do
default_requirements = ["proj>=X.Y,<Z", "other", "stuff"]
default_version = default_requirements[0]
default_extra_requirements = default_requirements[1:]

Then we are in a good position to remove default_version and default_extra_requirements.

  • I take it we employ a "default policy" of floating versions on a single major. Makes sense to me. Exceptions are to be expected, but when we find them, I think we would do well to document them.

  • This is a large enough change already, so this may be for another PR. This line struck out at me:

 default_interpreter_constraints = ["CPython>=3.7,<4"]

At the very least we may want to move our "default default_interpreter_constraints" value to a CONST for re-use to DRY this up a bit.

@benjyw
Copy link
Contributor Author

benjyw commented Mar 8, 2023

Sorry for the large number of comments. Took me half-way through before I had most of the details here figured out.

The main theme concludes to:

  • I think that we want to swap the order of declaring defaults so we can do
default_requirements = ["proj>=X.Y,<Z", "other", "stuff"]
default_version = default_requirements[0]
default_extra_requirements = default_requirements[1:]

Then we are in a good position to remove default_version and default_extra_requirements.

I had thought of that, but that seems pretty error prone, if someone changes default_extra_requirements in some way that would break those positional assumptions. Whereas this way it is at least straightforward to see what must happen to remove default_version and default_extra_requirements. In any case, this is all temporary, we'll end up in the same end state... :)

  • I take it we employ a "default policy" of floating versions on a single major. Makes sense to me. Exceptions are to be expected, but when we find them, I think we would do well to document them.

So that's not quite the policy. It's more that we've established a baseline, and we'll float above it as we upgrade versions in the future, until we make changes to how we use the tool that makes us incompatible with earlier versions, in which case we raise the floor.

Note that this is all educated guesswork. The only tool versions we're really confident about are the one's we've tested against. But we're roughly assuming minor version float is safe.

So what this is capturing, over time, is "in the past we tested against 1.2.3, so 1.x above that is compatible, and now we're testing against 2.3.4, so 2.x is also compatible, so the total compatible range so far is >=1.2.3,<3"). In the future that might extend up (<4) but we might have to raise the floor, if we start relying on a tool feature that wasn't available in 1.x.

  • This is a large enough change already, so this may be for another PR. This line struck out at me:
 default_interpreter_constraints = ["CPython>=3.7,<4"]

At the very least we may want to move our "default default_interpreter_constraints" value to a CONST for re-use to DRY this up a bit.

Agreed, but this is a separate audit and this change is already a giant PITA, so I'd prefer to do that in another PR. There is still some stuff to figure out about ICs. For example, which ones we use to generate the default lockfiles (these should be broad) vs which interpreter we use to run the tool (that's a bit chaotic today, I think, but in practice I believe can always be the one your code is compatible with, since that's how the python ecosystem seems to work).

@benjyw
Copy link
Contributor Author

benjyw commented Mar 8, 2023

To expand on my comment - default_version may ultimately turn into the version we generate default lockfiles for (except it'll live in a BUILD file), it is purposely different in many cases than the default_requirements, which are intended to be much looser - capturing the versions we expect to be compatible with. These are two different things. Hence in many cases they are not the same.

@kaos kaos closed this Mar 8, 2023
@kaos kaos reopened this Mar 8, 2023
@kaos
Copy link
Member

kaos commented Mar 8, 2023

Bah.. normally there is a cancel button next to the green one, but here it was a close button 🤢

@benjyw benjyw requested a review from kaos March 9, 2023 17:10
@benjyw
Copy link
Contributor Author

benjyw commented Mar 9, 2023

@kaos Can you re-review taking my clarifications into account? Your detailed comments are, afaict, all covered by those clarifications. Thanks!

Copy link
Member

@kaos kaos left a comment

Choose a reason for hiding this comment

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

lgtm. 👍🏽

@benjyw benjyw merged commit 8b669c8 into pantsbuild:main Mar 9, 2023
@benjyw benjyw deleted the audit_python_tools branch March 9, 2023 17:30
stuhood added a commit to stuhood/pants that referenced this pull request Mar 9, 2023
stuhood added a commit that referenced this pull request Mar 9, 2023
#17480 and #18431 collided, such that a new file was not re-formatted by
the new version of `black`.
benjyw added a commit to benjyw/pants that referenced this pull request Mar 9, 2023
Specifically, it added a `requirements` option for each tool that is
expected to contain very loose requirements that we expect
Pants to support.

We initialized the default value for that option from the existing
`version` and`extra_requirements` fields. However those were often
overly-constrained, sometimes to a single version.

This PR audits all the tools' defaults and in various cases does one or
both of:

1. Update `default_version` to a newer version so we can regen more
up-to-date lockfiles.
2. Explicitly set `default_requirements` to something loose but likely
compatible.

Of course it's hard to know which currently available tool versions
Pants is compatible with, unless we test against them. And it's impossible
to know which future versions Pants will remain compatible with.

So we assume that tools are semver-adherent, so that floating up in the
same major version is safe. Updating to newer versions lets us at least start
to test against some newer versions, and is also overdue, since many of
our default tool versions are quite old. The proof that these upgrades
are compatible is in the passing tests.

At some point soon we will `deprecate` `version` and `extra_requirements`
in favor of using user lockfiles for custom tool versions.
benjyw added a commit to benjyw/pants that referenced this pull request Mar 9, 2023
Specifically, it added a `requirements` option for each tool that is
expected to contain very loose requirements that we expect
Pants to support.

We initialized the default value for that option from the existing
`version` and`extra_requirements` fields. However those were often
overly-constrained, sometimes to a single version.

This PR audits all the tools' defaults and in various cases does one or
both of:

1. Update `default_version` to a newer version so we can regen more
up-to-date lockfiles.
2. Explicitly set `default_requirements` to something loose but likely
compatible.

Of course it's hard to know which currently available tool versions
Pants is compatible with, unless we test against them. And it's impossible
to know which future versions Pants will remain compatible with.

So we assume that tools are semver-adherent, so that floating up in the
same major version is safe. Updating to newer versions lets us at least start
to test against some newer versions, and is also overdue, since many of
our default tool versions are quite old. The proof that these upgrades
are compatible is in the passing tests.

At some point soon we will `deprecate` `version` and `extra_requirements`
in favor of using user lockfiles for custom tool versions.
benjyw added a commit that referenced this pull request Mar 10, 2023
…18460)

Specifically, it added a `requirements` option for each tool that is
expected to contain very loose requirements that we expect
Pants to support.

We initialized the default value for that option from the existing
`version` and`extra_requirements` fields. However those were often
overly-constrained, sometimes to a single version.

This PR audits all the tools' defaults and in various cases does one or
both of:
    
1. Update `default_version` to a newer version so we can regen more
up-to-date lockfiles.
2. Explicitly set `default_requirements` to something loose but likely
 compatible.
    
Of course it's hard to know which currently available tool versions
Pants is compatible with, unless we test against them. And it's
impossible to know which future versions Pants will remain compatible with.

So we assume that tools are semver-adherent, so that floating up in the
same major version is safe. Updating to newer versions lets us at least
start to test against some newer versions, and is also overdue, since many of
our default tool versions are quite old. The proof that these upgrades
are compatible is in the passing tests.

At some point soon we will `deprecate` `version` and `extra_requirements`
in favor of using user lockfiles for custom tool versions.
cognifloyd added a commit to StackStorm/st2 that referenced this pull request Mar 6, 2025
This is based on changes in pants:
- pantsbuild/pants#18431
- pantsbuild/pants#21894

Lockfile diff: lockfiles/twine.lock [twine]

==                    Upgraded dependencies                     ==

  jeepney                        0.8.0        -->   0.9.0
  nh3                            0.2.20       -->   0.2.21
  pkginfo                        1.12.0       -->   1.12.1.2
  twine                          3.7.1        -->   4.0.2

==                !! Downgraded dependencies !!                 ==

  importlib-metadata             8.5.0        -->   7.2.1

==                      Added dependencies                      ==

  markdown-it-py                 3.0.0
  mdurl                          0.1.2
  rich                           13.9.4
  typing-extensions              4.12.2

==                     Removed dependencies                     ==

  tqdm                           4.67.1
cognifloyd added a commit to StackStorm/st2 that referenced this pull request Mar 19, 2025
This is based on changes in pants:
- pantsbuild/pants#18431
- pantsbuild/pants#21894

Lockfile diff: lockfiles/twine.lock [twine]

==                    Upgraded dependencies                     ==

  jeepney                        0.8.0        -->   0.9.0
  nh3                            0.2.20       -->   0.2.21
  pkginfo                        1.12.0       -->   1.12.1.2
  twine                          3.7.1        -->   4.0.2

==                !! Downgraded dependencies !!                 ==

  importlib-metadata             8.5.0        -->   7.2.1

==                      Added dependencies                      ==

  markdown-it-py                 3.0.0
  mdurl                          0.1.2
  rich                           13.9.4
  typing-extensions              4.12.2

==                     Removed dependencies                     ==

  tqdm                           4.67.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants