From e9ef3e975082f6f57e64eebd798219c5a7bcf3fd Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Thu, 30 Dec 2021 04:14:16 -0500 Subject: [PATCH] fix: open setup.py as utf-8 in get_requires_python_str (#977) * open setup.py as utf-8 in get_requires_python_str fix #976 * update test for UTF-8 setup.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: mayeut --- cibuildwheel/projectfiles.py | 2 +- unit_test/projectfiles_test.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cibuildwheel/projectfiles.py b/cibuildwheel/projectfiles.py index c4f63c17..fece392f 100644 --- a/cibuildwheel/projectfiles.py +++ b/cibuildwheel/projectfiles.py @@ -70,7 +70,7 @@ def get_requires_python_str(package_dir: Path) -> Optional[str]: pass try: - with (package_dir / "setup.py").open() as f2: + with (package_dir / "setup.py").open(encoding="utf8") as f2: return setup_py_python_requires(f2.read()) except FileNotFoundError: pass diff --git a/unit_test/projectfiles_test.py b/unit_test/projectfiles_test.py index c62df6a9..6c55d46a 100644 --- a/unit_test/projectfiles_test.py +++ b/unit_test/projectfiles_test.py @@ -25,7 +25,7 @@ def test_read_setup_py_simple(tmp_path): def test_read_setup_py_full(tmp_path): - with open(tmp_path / "setup.py", "w") as f: + with open(tmp_path / "setup.py", "w", encoding="utf8") as f: f.write( dedent( """ @@ -35,6 +35,7 @@ def test_read_setup_py_full(tmp_path): setuptools.setup( name = "hello", + description = "≥“”ü", other = 23, example = ["item", "other"], python_requires = "1.24", @@ -43,7 +44,9 @@ def test_read_setup_py_full(tmp_path): ) ) - assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) == "1.24" + assert ( + setup_py_python_requires(tmp_path.joinpath("setup.py").read_text(encoding="utf8")) == "1.24" + ) assert get_requires_python_str(tmp_path) == "1.24"