Skip to content

Commit 037e34c

Browse files
authored
Python: fix issue with installing package on windows. (#432)
The problem was that we weren't explicitly setting the charset/encoding when loading the README and it's different on every platform. While the default is utf-8 (I think) on Linux and macOS, it's cp1252 on Windows. The latter wasn't able to load the README which contains emoji and other fancy stuff. This fixes it to use utf-8 explicitly on every platform (like we already did for another file we load here). This was reported by a customer on Slack.
2 parents 6a59921 + c77c040 commit 037e34c

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

python/setup.py

+23-22
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,62 @@
1919
# prerequisite: setuptools
2020
# http://pypi.python.org/pypi/setuptools
2121

22+
2223
def read_file(filepath):
2324
"""Read content from a UTF-8 encoded text file."""
24-
with codecs.open(filepath, 'rb', 'utf-8') as file_handle:
25+
with codecs.open(filepath, "rb", "utf-8") as file_handle:
2526
return file_handle.read()
2627

27-
PKG_NAME = 'svix'
28+
29+
PKG_NAME = "svix"
2830
PKG_DIR = os.path.abspath(os.path.dirname(__file__))
29-
META_PATH = os.path.join(PKG_DIR, PKG_NAME, '__init__.py')
31+
META_PATH = os.path.join(PKG_DIR, PKG_NAME, "__init__.py")
3032
META_CONTENTS = read_file(META_PATH)
3133
PKG_REQUIRES = [
3234
"httpx >=0.15.4,<0.23.0",
3335
"attrs >=21.3.0",
3436
"python-dateutil",
3537
"Deprecated",
3638
"types-python-dateutil",
37-
"types-Deprecated"
39+
"types-Deprecated",
3840
]
3941

42+
4043
def find_meta(meta):
4144
"""Extract __*meta*__ from META_CONTENTS."""
42-
meta_match = re.search(
43-
r"^__{meta}__\s+=\s+['\"]([^'\"]*)['\"]".format(meta=meta),
44-
META_CONTENTS,
45-
re.M
46-
)
45+
meta_match = re.search(r"^__{meta}__\s+=\s+['\"]([^'\"]*)['\"]".format(meta=meta), META_CONTENTS, re.M)
4746

4847
if meta_match:
4948
return meta_match.group(1)
50-
raise RuntimeError(
51-
f'Unable to find __{meta}__ string in package meta file'
52-
)
49+
raise RuntimeError(f"Unable to find __{meta}__ string in package meta file")
50+
5351

5452
def is_canonical_version(version):
5553
"""Check if a version string is in the canonical format of PEP 440."""
5654
pattern = (
57-
r'^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))'
58-
r'*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))'
59-
r'?(\.dev(0|[1-9][0-9]*))?$')
55+
r"^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))"
56+
r"*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))"
57+
r"?(\.dev(0|[1-9][0-9]*))?$"
58+
)
6059
return re.match(pattern, version) is not None
6160

61+
6262
def get_version_string():
6363
"""Return package version as listed in `__version__` in meta file."""
6464
# Parse version string
65-
version_string = find_meta('version')
65+
version_string = find_meta("version")
6666

6767
# Check validity
6868
if not is_canonical_version(version_string):
69-
message = (
70-
'The detected version string "{}" is not in canonical '
71-
'format as defined in PEP 440.'.format(version_string))
69+
message = 'The detected version string "{}" is not in canonical ' "format as defined in PEP 440.".format(
70+
version_string
71+
)
7272
raise ValueError(message)
7373

7474
return version_string
7575

76-
with open(os.path.join(os.path.dirname(__file__), "README.md")) as readme:
77-
PKG_README = readme.read()
76+
77+
PKG_README = read_file(os.path.join(os.path.dirname(__file__), "README.md"))
7878

7979
# allow setup.py to be run from any path
8080
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
@@ -118,4 +118,5 @@ def get_version_string():
118118
},
119119
long_description=PKG_README,
120120
long_description_content_type="text/markdown",
121-
)
121+
)
122+

0 commit comments

Comments
 (0)