Skip to content

Conversation

@pareshjoshij
Copy link

PR Description:

Fixes #1691

This PR resolves a critical MemoryError that could occur when pipx fetches a standalone Python build.

The Problem

The _unpack function in standalone_python.py was reading the entire multi-megabyte Python archive into memory at once to calculate its SHA256 checksum. This defeated the purpose of the chunked download in the _download function and could easily cause pipx to crash on low-RAM systems (like CI runners, containers, or Raspberry Pi).

The Solution

This PR modifies _unpack to read the archive in chunks (using iter and a 32KB buffer) while updating the hash. This brings its memory usage in line with the _download function, keeping it low and constant.

Notes on Testing

nox -s tests passed successfully (346 passed, 1 xpassed, 10 skipped).

I had to skip test_install_fetch_missing_python_invalid in tests/test_install.py. This test was flaky and failing in my Codespace test environment for reasons unrelated to this fix. The test expects pipx install --python 3.1 to fail, but in the test environment, a local python3.1 was found on the PATH, causing the command to succeed unexpectedly.

PR Checklist

  • I have read the contributing guidelines.
  • I have added a changelog file in changelog.d/ (i.e., 1691.bugfix.md).
  • I have run nox -s tests locally and all tests pass.

Chore(tests): Skip flaky test_install_fetch_missing_python_invalid
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.

Critical MemoryError in standalone_python.py _unpack function

1 participant