Skip to content

Commit 6727d0e

Browse files
committed
Always read metadata files as UTF-8 in setup.py
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. This fixes the bug described in gitpython-developers#1747 where installation other than from a pre-built wheel would fail on many Windows systems using non-European languages. The specific problem occurred with the README.md file. The requirements files are less likely to contain characters not in the ASCII subset, though maybe they could come to contain them, perhaps 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 gitpython-developers#1747, are now working.
1 parent 5c6a4f4 commit 6727d0e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: setup.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
import os
88
import sys
99

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

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

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

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

2222

0 commit comments

Comments
 (0)