Skip to content

Comments

fix: make -p flag in an alias for --python#11437

Closed
Aditya-PS-05 wants to merge 2 commits intoastral-sh:mainfrom
Aditya-PS-05:fix/pip-compile-python-flag
Closed

fix: make -p flag in an alias for --python#11437
Aditya-PS-05 wants to merge 2 commits intoastral-sh:mainfrom
Aditya-PS-05:fix/pip-compile-python-flag

Conversation

@Aditya-PS-05
Copy link
Contributor

closes #11285

Changes

  • Modified the argument parsing in PipCompileArgs to make -p alias to --python
  • Removed short form from --python-version option
  • Added explicit long and short form specifications to avoid ambiguity

@Aditya-PS-05 Aditya-PS-05 requested a review from j178 February 12, 2025 09:19
Comment on lines +1091 to +1092
long = "python",
short = 'p',
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need the verbose long and short options — we don't use that anywhere and coherence with the existing style is important.

This also seems to add support for the UV_PYTHON variable. It's fine to leave here, but please be careful with changes like that / note them in the summary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@zanieb
Copy link
Member

zanieb commented Feb 12, 2025

Unfortunately this is a breaking change and we'll need to do some tricks to make this roughly backwards compatible. I can own that.

@zanieb zanieb added this to the v0.6.0 milestone Feb 12, 2025
@zanieb zanieb added breaking A breaking change cli Related to the command line interface labels Feb 12, 2025
@zanieb
Copy link
Member

zanieb commented Feb 12, 2025

The failure mode can be seen in CI

    9       │-warning: The requested Python version 3.8 is not available; 3.12.[X] will be used to build dependencies instead.
   10       │-Resolved 1 package in [TIME]
          5 │+error: No interpreter found for Python 3.8 in virtual environments, managed installations, or search path

We could decide this is okay and just hint to use --python-version instead there? I worry we'll break a fair number of workflows though. Thoughts @charliermarsh ?

The alternative is --python falls back to the semantics of --python-version if it can't find the version — but then there's not a great way to say "Fail if this Python version cannot be found".

@zanieb
Copy link
Member

zanieb commented Feb 13, 2025

I tried a different approach in #11486

@zanieb zanieb closed this Feb 13, 2025
zanieb added a commit that referenced this pull request Feb 13, 2025
…#11486)

Closes #11285
Closes #11437

This changes `-p` from an alias of `--python-version` to `--python`
while retaining backwards compatibility for `--python-version`-like
fallback behavior when the requested version, e.g., `-p 3.12`, cannot be
found.

This was initially implemented with a hidden `--python-legacy` flag
which allows us to special case the short `-p` flag — unlike the
implementation in #11437. However, after further discussion, we decided
the behavior difference between `-p` and `--python` would be confusing
so now `-p` is an alias for `--python` and `--python` is special-cased
when a version is used.

Additionally, we now respect the `UV_PYTHON` environment variable, but
it is ignored when `--python-version` is set. If you want different
`--python-version` and `--python` values, you must do so explicitly. I
considered banning this, but it is valid for e.g. `--python pypy
--python-version 3.12`
zanieb added a commit that referenced this pull request Feb 13, 2025
…#11486)

Closes #11285
Closes #11437

This changes `-p` from an alias of `--python-version` to `--python`
while retaining backwards compatibility for `--python-version`-like
fallback behavior when the requested version, e.g., `-p 3.12`, cannot be
found.

This was initially implemented with a hidden `--python-legacy` flag
which allows us to special case the short `-p` flag — unlike the
implementation in #11437. However, after further discussion, we decided
the behavior difference between `-p` and `--python` would be confusing
so now `-p` is an alias for `--python` and `--python` is special-cased
when a version is used.

Additionally, we now respect the `UV_PYTHON` environment variable, but
it is ignored when `--python-version` is set. If you want different
`--python-version` and `--python` values, you must do so explicitly. I
considered banning this, but it is valid for e.g. `--python pypy
--python-version 3.12`
zanieb added a commit that referenced this pull request Feb 13, 2025
…#11486)

Closes #11285
Closes #11437

This changes `-p` from an alias of `--python-version` to `--python`
while retaining backwards compatibility for `--python-version`-like
fallback behavior when the requested version, e.g., `-p 3.12`, cannot be
found.

This was initially implemented with a hidden `--python-legacy` flag
which allows us to special case the short `-p` flag — unlike the
implementation in #11437. However, after further discussion, we decided
the behavior difference between `-p` and `--python` would be confusing
so now `-p` is an alias for `--python` and `--python` is special-cased
when a version is used.

Additionally, we now respect the `UV_PYTHON` environment variable, but
it is ignored when `--python-version` is set. If you want different
`--python-version` and `--python` values, you must do so explicitly. I
considered banning this, but it is valid for e.g. `--python pypy
--python-version 3.12`
loic-lescoat pushed a commit to loic-lescoat/uv that referenced this pull request Mar 2, 2025
…astral-sh#11486)

Closes astral-sh#11285
Closes astral-sh#11437

This changes `-p` from an alias of `--python-version` to `--python`
while retaining backwards compatibility for `--python-version`-like
fallback behavior when the requested version, e.g., `-p 3.12`, cannot be
found.

This was initially implemented with a hidden `--python-legacy` flag
which allows us to special case the short `-p` flag — unlike the
implementation in astral-sh#11437. However, after further discussion, we decided
the behavior difference between `-p` and `--python` would be confusing
so now `-p` is an alias for `--python` and `--python` is special-cased
when a version is used.

Additionally, we now respect the `UV_PYTHON` environment variable, but
it is ignored when `--python-version` is set. If you want different
`--python-version` and `--python` values, you must do so explicitly. I
considered banning this, but it is valid for e.g. `--python pypy
--python-version 3.12`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking A breaking change cli Related to the command line interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Treat -p in uv pip compile as --python and fallback to --python-version

3 participants