Repository navigation
Read and write the Pipfile as UTF-8 everywhere - #6756
Merged
Merged
Conversation
Pipfile.read() decodes the Pipfile as utf-8-sig, but a few other places still opened it with the locale encoding: the Pipfile hash, the lock data derived from the Pipfile when there is no usable Pipfile.lock, and write_toml(). On Windows the locale encoding is a legacy code page, so a Pipfile with non-ASCII text (a comment, a local path) made pipenv lock fail with UnicodeDecodeError, and pipenv install rewrote the Pipfile in that code page (e.g. cp932), after which it no longer read as UTF-8. Read the Pipfile as utf-8-sig and write it as UTF-8 in those places, and read Pipfile.lock as utf-8-sig in locking.Lockfile.load(), which treated a lockfile with a BOM as corrupt and moved it to Pipfile.lock.bak. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
matteius
approved these changes
Oct 26, 2026
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The issue
No issue filed; this is a follow-up to #6750.
Pipfile.read()decodes the Pipfile asutf-8-sig, but a few other places still open it with the locale encoding: the Pipfile hash (Pipfile.calculate_hash()), the lock data built from the Pipfile when there is no usablePipfile.lock(Lockfile.as_dict()andLockfile.load()when_metais missing), andPipfile.write_toml(). On Windows the locale encoding is a legacy code page, so a Pipfile with any non-ASCII text, even just a comment, breaks:pipenv lockon Japanese Windows (cp932) with# 開発用の依存関係at the top of the Pipfile:pipenv install coloramawith the same Pipfile rewrites it in cp932 (the comment becomes\x8aJ\x94\xad...) and then fails withUnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a, because the next read is UTF-8. The Pipfile stays broken for every later command and on every other machine.Separately,
pipenv.utils.locking.Lockfile.load()still readsPipfile.lockwith the locale encoding. With a BOM,jsonraisesJSONDecodeError, so the lockfile is reported as corrupt and moved toPipfile.lock.bak(on Linux too).The fix
Read the Pipfile as
utf-8-sigand write it as UTF-8 in those places, and readPipfile.lockasutf-8-siginlocking.Lockfile.load(), matching what #6750 did for the other readers. A Pipfile that pipenv rewrites still loses its BOM, as before.tests/unit/test_pipfile_encoding.pyadds 9 cases (Pipfile with non-ASCII text, saved with and without a BOM, through the hash,write_toml(), both Pipfile-derived lock paths, plus aPipfile.lockwith a BOM throughlocking.Lockfile.load()). On Windows with cp932 all 9 fail without the change; under UTF-8 (-X utf8, like Linux) the 4 BOM cases fail. All pass with it.tests/unitotherwise gives the same results as onmainhere (test_helpand thetest_release_tasks.py/test_vendor.pyimports already fail locally).The checklist
news/directory to describe this fix with the extension.bugfix.rst,.feature.rst,.behavior.rst,.doc.rst..vendor.rst. or.trivial.rst(this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.I used Claude Code to write this change.