-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Bugfix: Make sure ensure_python() installs Python when conditions are met #6425
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
Conversation
… met Previously, even when PIPENV_YES was set or the user confirmed the installation, the presence of an unnecessary else statement caused ensure_python() to exit early without attempting the Python installation.
@EpiX-1 could you install pre-commit and run |
Actually the ruff issues aren't related to your change -- I am investigating them. |
@EpiX-1 would you be able to add a news fragment though? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that when PIPENV_YES
is set (or the user confirms), the Python installer logic always runs by removing an unnecessary else
that caused an early exit.
- Removed a redundant
else
to prevent premature abort - Dedented and cleaned up the installation spinner block
- Adjusted formatting of status and print statements
Comments suppressed due to low confidence (1)
pipenv/utils/virtualenv.py:331
- Consider adding a test to verify that the installation path is triggered when
PIPENV_YES
is set and the specified Python version is not already installed.
console.print(
Sure, I'll do it tomorrow. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Bumps [pipenv](https://github.com/pypa/pipenv) from 2024.4.1 to 2025.0.4. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/pypa/pipenv/releases">pipenv's releases</a>.</em></p> <blockquote> <h2>Release v2025.0.4</h2> <h2>What's Changed</h2> <ul> <li>Fix editable installation from relative paths on Windows by <a href="https://github.com/stewartmiles"><code>@stewartmiles</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6416">pypa/pipenv#6416</a></li> <li>chore: remove tomli from vendor by <a href="https://github.com/oz123"><code>@oz123</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6417">pypa/pipenv#6417</a></li> <li>Bump urllib3 from 2.4.0 to 2.5.0 in /examples by <a href="https://github.com/dependabot"><code>@dependabot</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6424">pypa/pipenv#6424</a></li> <li>Bump requests from 2.32.3 to 2.32.4 in /examples by <a href="https://github.com/dependabot"><code>@dependabot</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6427">pypa/pipenv#6427</a></li> <li>Add back ignore_compatibility option to pip package finder for comprehensive lock file generation by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6426">pypa/pipenv#6426</a></li> <li>Bugfix: Make sure ensure_python() installs Python when conditions are met by <a href="https://github.com/EpiX-1"><code>@EpiX-1</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6425">pypa/pipenv#6425</a></li> <li>Performance Optimization: Resolver, Benchmarking & Batch Operations by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6419">pypa/pipenv#6419</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/EpiX-1"><code>@EpiX-1</code></a> made their first contribution in <a href="https://redirect.github.com/pypa/pipenv/pull/6425">pypa/pipenv#6425</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/pypa/pipenv/compare/v2025.0.3...v2025.0.4">https://github.com/pypa/pipenv/compare/v2025.0.3...v2025.0.4</a></p> <h2>Release v2025.0.3</h2> <h2>What's Changed</h2> <ul> <li>Fix release notes generation by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6399">pypa/pipenv#6399</a></li> <li>Vendor in pip 25.1.1 by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6400">pypa/pipenv#6400</a></li> <li>vendor: remove dparse and ruamel by <a href="https://github.com/oz123"><code>@oz123</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6407">pypa/pipenv#6407</a></li> <li>Fix pypi-server startup (it now requires <code>--welcome</code>). by <a href="https://github.com/stewartmiles"><code>@stewartmiles</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6410">pypa/pipenv#6410</a></li> <li>Rewrite docs Claude AI prompt for more cohesive technical voice and expanded examples by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6379">pypa/pipenv#6379</a></li> <li>Apply variant of fix for wrong cononical name in Pipfile. by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6413">pypa/pipenv#6413</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/stewartmiles"><code>@stewartmiles</code></a> made their first contribution in <a href="https://redirect.github.com/pypa/pipenv/pull/6410">pypa/pipenv#6410</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/pypa/pipenv/compare/v2025.0.2...v2025.0.3">https://github.com/pypa/pipenv/compare/v2025.0.2...v2025.0.3</a></p> <h2>Release v2025.0.2</h2> <h2>What's Changed</h2> <ul> <li>Cleanup unused dependencies by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6386">pypa/pipenv#6386</a></li> <li>Fix for UnboundLocalError in ensure_python SESSION_IS_INTERACTIVE=False by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6389">pypa/pipenv#6389</a></li> <li>Fix changelog generation during release. by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6394">pypa/pipenv#6394</a></li> <li>Correct check/scan command documentation by <a href="https://github.com/kerhac"><code>@kerhac</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6398">pypa/pipenv#6398</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/kerhac"><code>@kerhac</code></a> made their first contribution in <a href="https://redirect.github.com/pypa/pipenv/pull/6398">pypa/pipenv#6398</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/pypa/pipenv/compare/v2025.0.1...v2025.0.2">https://github.com/pypa/pipenv/compare/v2025.0.1...v2025.0.2</a></p> <h2>Release v2025.0.1</h2> <h2>What's Changed</h2> <ul> <li>HOTFIX import requirements by <a href="https://github.com/matteius"><code>@matteius</code></a> in <a href="https://redirect.github.com/pypa/pipenv/pull/6385">pypa/pipenv#6385</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/pypa/pipenv/compare/v2025.0.0...v2025.0.1">https://github.com/pypa/pipenv/compare/v2025.0.0...v2025.0.1</a></p> <h2>Release v2025.0.0</h2> <h2>What's Changed</h2> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/pypa/pipenv/blob/main/CHANGELOG.md">pipenv's changelog</a>.</em></p> <blockquote> <h1>2025.0.4 (2025-07-07)</h1> <h1>Pipenv 2025.0.4 (2025-07-07)</h1> <h2>Bug Fixes</h2> <ul> <li>Significantly improved dependency resolution performance with ResolveLib 1.2.0 optimistic backjumping, intelligent caching system, and batch Pipfile operations. Added comprehensive benchmarking infrastructure to prevent performance regressions. Requirements imports are 60-80% faster for large files, complex resolutions are 10-30% faster, and repeated operations benefit from smart caching. <code>[#6419](pypa/pipenv#6419) <https://github.com/pypa/pipenv/issues/6419></code>_</li> <li>Ensure the requested Python version is installed when it differs from the one used with Pipenv. <code>[#6425](pypa/pipenv#6425) <https://github.com/pypa/pipenv/issues/6425></code>_</li> <li>Restored ignore compatibility finder patch to enable comprehensive cross-platform hash collection in lock files. <code>[#6426](pypa/pipenv#6426) <https://github.com/pypa/pipenv/issues/6426></code>_ 2025.0.3 (2025-05-29) ===================== Pipenv 2025.0.3 (2025-05-29) ============================</li> </ul> <h2>Vendored Libraries</h2> <ul> <li>Vendor in <code>pip==25.1.1</code> latest. <code>[#6400](pypa/pipenv#6400) <https://github.com/pypa/pipenv/issues/6400></code>_ 2025.0.1 (2025-05-02) ===================== 2025.0.2 2025.0.1 (2025-05-02) ==============================</li> </ul> <h2>Bug Fixes</h2> <ul> <li>Cleanup unused dependencies when upgrading packages. <code>[#6386](pypa/pipenv#6386) <https://github.com/pypa/pipenv/issues/6386></code>_</li> <li>Fix for <code>UnboundLocalError</code> in <code>ensure_python</code> when <code>SESSION_IS_INTERACTIVE=False</code>, using pyenv, and python version in Pipfile not available. <code>[#6389](pypa/pipenv#6389) <https://github.com/pypa/pipenv/issues/6389></code>_</li> </ul> <h1>2025.0.1 (2025-04-24)</h1> <h1>Pipenv 2025.0.1 (2025-04-24)</h1> <h2>Bug Fixes</h2> <ul> <li>Fix for broken import requirements in <code>2025.0.0</code> <code>[#6385](pypa/pipenv#6385) <https://github.com/pypa/pipenv/issues/6385></code>_</li> </ul> <h1>2025.0.0 (2025-04-24)</h1> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/pypa/pipenv/commit/4e5f9a79839f0e6701422341dcdf8edebb5063eb"><code>4e5f9a7</code></a> Release v2025.0.4</li> <li><a href="https://github.com/pypa/pipenv/commit/1b2eca3406a5163df49f486bddc1556b916024ee"><code>1b2eca3</code></a> Bumped version to 2025.0.4.</li> <li><a href="https://github.com/pypa/pipenv/commit/25d3d98079da966e987dbe97828bab43ed3ea4d0"><code>25d3d98</code></a> Merge pull request <a href="https://redirect.github.com/pypa/pipenv/issues/6419">#6419</a> from pypa/increase-resolution-depth</li> <li><a href="https://github.com/pypa/pipenv/commit/959ab65655876e82f5fc7a498aa19d00c83209c4"><code>959ab65</code></a> rework test to be less problematic</li> <li><a href="https://github.com/pypa/pipenv/commit/e2aaef6318376f0564b19188a962a9e82efb5477"><code>e2aaef6</code></a> rework test to be less problematic</li> <li><a href="https://github.com/pypa/pipenv/commit/2a8dc20c31c0c9852b5d624a4e8bfaf0a3a2e064"><code>2a8dc20</code></a> fix ruff error</li> <li><a href="https://github.com/pypa/pipenv/commit/65a1089f829deea12efd46a57c69999ac03d5cd5"><code>65a1089</code></a> try fixing flaky test</li> <li><a href="https://github.com/pypa/pipenv/commit/621fafa2e3546421cfbe3e3dc175c0d0b4381dcb"><code>621fafa</code></a> Update 6425.bugfix.rst</li> <li><a href="https://github.com/pypa/pipenv/commit/c76efdfa724db00750ab2380a3a46480d500e741"><code>c76efdf</code></a> Update pipenv/utils/virtualenv.py</li> <li><a href="https://github.com/pypa/pipenv/commit/766c1670d83088645d6b07e05b8d7631c0da7457"><code>766c167</code></a> Add a news fragment</li> <li>Additional commits viewable in <a href="https://github.com/pypa/pipenv/compare/v2024.4.1...v2025.0.4">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
The issue
The issue arises when a user tries to create a new venv with a version of Python that hasn't been installed PREVIOUSLY with pyenv. Normally, pipenv should handle the installation of the desired Python version thanks to an installer (pyenv) before creating the new venv. However, this is not the case, and pipenv creates a new venv with the same Python version as the system one.
This behavior happens whether or not the conditions for the installation are met:
PIPENV_YES
is sety
when prompted:"Would you like us to install {version} with {installer}?"
Expected behavior
The Python version of the .venv should match the version specified in the Pipfile.
Actual behavior
The Python version of the .venv is the same as the one from the system.
Reproduce the issue
pip install pipenv
. For the rest of the steps, it is assumed that the system Python version is 3.13.pipenv install
The fix
Remove a useless else statement that would cause the program to exit abruptly.