Skip to content

Commit

Permalink
Always use UTF-8 for metadata files in setup.py
Browse files Browse the repository at this point in the history
This passes `encoding="utf-8"` to the `open` calls in setup.py, so
the readme, version, and requirements files are always read as
UTF-8, even on systems whose locale is not UTF-8, as is typically
the case on many Windows systems for non-European languages.

The specific problem was caused by the README.md file. The
requirements files are less likely to contain characters not in the
ASCII subset, though they could come to contain them, at least in
comments. The VERSION file is even less likely to ever contain
such characters. Nonetheless, for consistency, because it is a best
practice, and because it appears to be the intent of the existing
code, encoding="utf=8" is added for opening all of them.

This change is tested on a system whose locale uses Windows code
page 936. Editable installation, as well as the other affected ways
of installing (and building) described in #1747, are now working.
(Installing from a pre-built wheel was never affected.)
  • Loading branch information
EliahKagan committed Nov 28, 2023
1 parent 5c6a4f4 commit 5caf0d3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import os
import sys

with open(os.path.join(os.path.dirname(__file__), "VERSION")) as ver_file:
with open(os.path.join(os.path.dirname(__file__), "VERSION"), encoding="utf-8") as ver_file:
VERSION = ver_file.readline().strip()

with open("requirements.txt") as reqs_file:
with open("requirements.txt", encoding="utf-8") as reqs_file:
requirements = reqs_file.read().splitlines()

with open("test-requirements.txt") as reqs_file:
with open("test-requirements.txt", encoding="utf-8") as reqs_file:
test_requirements = reqs_file.read().splitlines()

with open("README.md") as rm_file:
with open("README.md", encoding="utf-8") as rm_file:
long_description = rm_file.read()


Expand Down

0 comments on commit 5caf0d3

Please sign in to comment.