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

pex-cli: Change version format #22090

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

grihabor
Copy link
Contributor

@grihabor grihabor commented Mar 13, 2025

New tool upgrade script expects unified version format for tools, in this pr I change the format for pex-cli subsystem

@grihabor grihabor marked this pull request as ready for review March 17, 2025 15:17
@grihabor
Copy link
Contributor Author

@huonw Here is a separate pr for pex-cli version format deprecation

@grihabor grihabor force-pushed the pex-cli-change-version-format branch from 36d3154 to 3074750 Compare March 19, 2025 22:13
@grihabor grihabor force-pushed the pex-cli-change-version-format branch from 3074750 to 85332a9 Compare March 19, 2025 22:16
Copy link
Contributor

@huonw huonw left a comment

Choose a reason for hiding this comment

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

This looks good in principle (thank you for the efforts to ensure we're not breaking existing users), but it'd be good to make the deprecation more vocal.

@classmethod
def decode_known_version(cls, known_version: str) -> ExternalToolVersion:
# for backward compatibility with version format like "v2.33.4"
return super().decode_known_version(known_version.lstrip("v"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will break anyone who's got an existing specification like:

[pex-cli]
version = "v2.33.4"
known_versions = ["v2.33.4|..."]

Because it'll decode to ExternalToolVersion(version="2.33.4", ...), but compare that "2.33.4" to version = "v2.33.4", in known_version, and thus not be found:

def known_version(self, plat: Platform) -> ExternalToolVersion | None:
for known_version in self.known_versions:
tool_version = self.decode_known_version(known_version)
if plat.value == tool_version.platform and tool_version.version == self.version:
return tool_version
return None

We can likely handle this by overriding known_version too.

@classmethod
def decode_known_version(cls, known_version: str) -> ExternalToolVersion:
# for backward compatibility with version format like "v2.33.4"
return super().decode_known_version(known_version.lstrip("v"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could centralise the logic for stripping v. This'd also let us have a single sensible place for emitting a vocal deprecation warning, so that the deprecation is emphasised to users rather than just relying on release notes.

Maybe something like

from pants.base.deprecated import warn_or_error

...

def _strip_deprecated_version_prefix(version: str, option_name: str) -> str:
    if not version.startswith("v"):
        return version

    warn_or_error(
        "2.30.0.dev0",
        f"use of `v` prefix in [pex-cli].{option_name} value {version}",
        "The [pex-cli] subsystem now uses plain versions, like `2.33.4`, instead of `v2.33.4`. Remove the `v` prefix",
    )
    return version.lstrip("v")

And then call that like

self.url_template.format(version= _strip_deprecated_version_prefix (self.version, "version"), platform=platform)
...
super().decode_known_version(_strip_deprecated_version_prefix(known_version, "known_version"))

@@ -20,6 +20,9 @@ New kubernetes backend! See [docs](https://www.pantsbuild.org/stable/docs/kubern

### Deprecations

`[pex-cli].version` format `"v2.33.4"` is deprecated in favor of `"2.33.4"`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, we often call out this sort of thing in the Python section specifically too.

So maybe this could be a really short bullet point here (e.g. "[pex-cli].version and known_versions should no longer include a v prefix") to make it easier to skim (if/when we have more), and then have this longer content in the Python section.

@huonw
Copy link
Contributor

huonw commented Mar 25, 2025

Thanks for the contribution. We've just branched for 2.26, so merging this pull request now will come out in 2.27, please move the release notes updates to docs/notes/2.27.x.md.

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