Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Raise the original error when a launcher can't be written - #269

Merged
vsajip merged 1 commit into
pypa:masterfrom
candygoogy:fix-launcher-write-error
Oct 15, 2026
Merged

vsajip merged 1 commit into
pypa:masterfrom
candygoogy:fix-launcher-write-error

Conversation

@candygoogy

Copy link
Copy Markdown
Contributor

Summary

On Windows, if ScriptMaker can't write an .exe launcher and there is no existing file at that path, the original error is lost: the .deleteme logic tries to rename a file that doesn't exist, and that FileNotFoundError is raised instead.

This is what pip users get when the scripts directory isn't writable (e.g. a Python installed for all users, used without admin rights). See pypa/pip#9023:

WARNING: Failed to write executable - trying to use .deleteme logic
ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: '...\Scripts\cowsay.exe' -> '...\Scripts\cowsay.exe.deleteme'

pip only shows its permission hint when the error is EACCES, so the real cause is hidden.

Change

If writing the launcher fails and the file doesn't exist, there's nothing to move aside, so the original exception is re-raised. When the file does exist (e.g. because it's running), the .deleteme logic works as before.

Testing

  • Two new Windows-only tests in tests/test_scripts.py: a failing write with no existing file raises the original error and leaves nothing behind (fails before this change with FileNotFoundError), and an existing launcher whose first write fails is still replaced.
  • tests/test_all.py on Windows 11 with Python 3.14: the same results as on master plus the two new tests (6 tests fail or error both before and after, all unrelated to scripts).
  • Manually, with pip 26.1.1 in a venv whose Scripts folder denies creating files, installing cowsay:
    • pip's vendored distlib: the [WinError 2] ... cowsay.exe.deleteme error above
    • with this change applied to it: [Errno 13] Permission denied: '...\Scripts\cowsay.exe' followed by pip's Check the permissions. hint

If writing an .exe launcher fails and there is no existing file, the
.deleteme logic tried to rename the missing file, and the resulting
FileNotFoundError replaced the original error (e.g. no write permission
for the scripts directory). Re-raise the original error in that case.
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.04%. Comparing base (674a491) to head (472274b).
⚠️ Report is 68 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #269      +/-   ##
==========================================
- Coverage   81.49%   81.04%   -0.45%     
==========================================
  Files          24       24              
  Lines        8885     9144     +259     
  Branches     1747     1564     -183     
==========================================
+ Hits         7241     7411     +170     
- Misses       1300     1386      +86     
- Partials      344      347       +3     
Flag Coverage Δ
unittests 80.20% <100.00%> (-0.42%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vsajip
vsajip merged commit e54dd8c into pypa:master Oct 15, 2026
40 of 41 checks passed
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