Skip to content

Commit ab75503

Browse files
authored
fix: make sure encoding is specified in more places (#861)
Fix #859 and make sure we specify this in more places. In Python 3.14, this will be the default, but before that it needs to be specified. --------- Signed-off-by: Henry Schreiner <[email protected]>
1 parent 4f06e8c commit ab75503

File tree

7 files changed

+24
-14
lines changed

7 files changed

+24
-14
lines changed

Diff for: src/scikit_build_core/build/_file_processor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def each_unignored_file(
4444
exclude_lines += f.readlines()
4545

4646
nested_excludes = {
47-
p.parent: pathspec.GitIgnoreSpec.from_lines(p.read_text().splitlines())
47+
p.parent: pathspec.GitIgnoreSpec.from_lines(
48+
p.read_text(encoding="utf-8").splitlines()
49+
)
4850
for p in Path().rglob("**/.gitignore")
4951
if p != Path(".gitignore")
5052
}

Diff for: src/scikit_build_core/file_api/_cattrs_converter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def load_reply_dir(reply_dir: Path) -> Index:
5757
msg = f"index file not found in {reply_dir}"
5858
raise IndexError(msg)
5959
index_file = indexes[-1]
60-
return converter.loads(index_file.read_text(), Index)
60+
return converter.loads(index_file.read_text("utf-8"), Index)
6161

6262

6363
if __name__ == "__main__":

Diff for: tests/packages/navigate_editable/python/shared_pkg/py_module.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def py_method():
1919
def read_py_data_txt():
2020
root = files("shared_pkg.data")
2121
py_data = root / "py_data.txt"
22-
print(py_data.read_text())
22+
print(py_data.read_text(encoding="utf-8"))
2323

2424

2525
def read_c_generated_txt():
2626
root = files("shared_pkg.data")
2727
c_generated_txt = root / "c_generated.txt"
28-
print(c_generated_txt.read_text())
28+
print(c_generated_txt.read_text(encoding="utf-8"))

Diff for: tests/test_cmake_ast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
@pytest.mark.parametrize("filename", FILENAMES, ids=IDS)
1919
def test_cmake_file_parse(filename: Path):
20-
for x in parse(tokenize(filename.read_text(encoding="utf-8-sig"))):
20+
for x in parse(tokenize(filename.read_text(encoding="utf-8"))):
2121
assert str(x).startswith(f"{x.name}({x.value})")
2222

2323

Diff for: tests/test_cmake_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_init_cache(
107107
cmake_init = config.build_dir / "CMakeInit.txt"
108108
source_dir_str = str(config.source_dir).replace("\\", "/")
109109
assert (
110-
cmake_init.read_text()
110+
cmake_init.read_text(encoding="utf-8")
111111
== f"""\
112112
set(SKBUILD ON CACHE BOOL "" FORCE)
113113
set(SKBUILD_VERSION [===[1.0.0]===] CACHE STRING "" FORCE)

Diff for: tests/test_custom_modules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_ep(isolated):
2020

2121
script = isolated.run("script1", capture=True).strip()
2222
pysys = isolated.execute("import sys; print(sys.executable)").strip()
23-
contents = Path(script).read_text()
23+
contents = Path(script).read_text(encoding="utf-8")
2424
assert contents.startswith(f"#!{pysys}")
2525

2626
if sys.version_info >= (3, 8):

Diff for: tests/test_process_scripts.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,26 @@ def test_script_dir(tmp_path: Path) -> None:
3333

3434
process_script_dir(script_dir)
3535

36-
assert script_1.read_text() == "#!python\n\nprint('hello world')"
36+
assert script_1.read_text(encoding="utf-8") == "#!python\n\nprint('hello world')"
3737
assert script_1.stat().st_mode == orig_mode_1
3838

39-
assert script_2.read_text() == "#!python\n\nprint('hello world')"
39+
assert script_2.read_text(encoding="utf-8") == "#!python\n\nprint('hello world')"
4040
assert script_2.stat().st_mode == orig_mode_2
4141

42-
assert script_3.read_text() == "#!python\n\nprint('hello world')"
42+
assert script_3.read_text(encoding="utf-8") == "#!python\n\nprint('hello world')"
4343

44-
assert script_4.read_text() == "#!python\n\nprint('hello world')"
44+
assert script_4.read_text(encoding="utf-8") == "#!python\n\nprint('hello world')"
4545

46-
assert script_5.read_text() == "#!/usr/bin/other\n\nprint('hello world')"
46+
assert (
47+
script_5.read_text(encoding="utf-8")
48+
== "#!/usr/bin/other\n\nprint('hello world')"
49+
)
4750

48-
assert script_6.read_text() == "#!python other\n\nprint('hello world')"
51+
assert (
52+
script_6.read_text(encoding="utf-8") == "#!python other\n\nprint('hello world')"
53+
)
4954

50-
assert script_7.read_text() == "#!/usr/bin/env other\n\nprint('hello world')"
55+
assert (
56+
script_7.read_text(encoding="utf-8")
57+
== "#!/usr/bin/env other\n\nprint('hello world')"
58+
)

0 commit comments

Comments
 (0)