Skip to content

Commit

Permalink
Fix encoding warnings with PEP 597 enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
danyeaw committed Jan 21, 2024
1 parent 9cb1cd6 commit c64538a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
push:
branches: [main]

env:
PYTHONWARNDEFAULTENCODING: 'true'

jobs:
tests:
name: ${{ matrix.os }} / ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def _get_sys_tags(self) -> list[str]:
],
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
)
except subprocess.CalledProcessError as e:
raise RuntimeError(
Expand Down
1 change: 1 addition & 0 deletions src/poetry/core/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_vcs(directory: Path) -> Git | None:
[executable(), "rev-parse", "--show-toplevel"],
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
).strip()

vcs = Git(Path(git_dir))
Expand Down
4 changes: 3 additions & 1 deletion tests/masonry/builders/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ def test_metadata_with_readme_files() -> None:

readme1 = test_path / "README-1.rst"
readme2 = test_path / "README-2.rst"
description = "\n".join([readme1.read_text(), readme2.read_text(), ""])
description = "\n".join(
[readme1.read_text(encoding="utf-8"), readme2.read_text(encoding="utf-8"), ""]
)

assert metadata.get_payload() == description

Expand Down
6 changes: 3 additions & 3 deletions tests/pyproject/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@pytest.fixture
def pyproject_toml(tmp_path: Path) -> Path:
path = tmp_path / "pyproject.toml"
with path.open(mode="w"):
with path.open(mode="w", encoding="utf-8"):
pass
return path

Expand All @@ -24,7 +24,7 @@ def build_system_section(pyproject_toml: Path) -> str:
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
"""
with pyproject_toml.open(mode="a") as f:
with pyproject_toml.open(mode="a", encoding="utf-8") as f:
f.write(content)
return content

Expand All @@ -38,6 +38,6 @@ def poetry_section(pyproject_toml: Path) -> str:
[tool.poetry.dependencies]
python = "^3.5"
"""
with pyproject_toml.open(mode="a") as f:
with pyproject_toml.open(mode="a", encoding="utf-8") as f:
f.write(content)
return content
2 changes: 1 addition & 1 deletion tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_utils_helpers_combine_unicode() -> None:
def test_utils_helpers_temporary_directory_readonly_file() -> None:
with temporary_directory() as temp_dir:
readonly_filename = os.path.join(temp_dir, "file.txt")
with open(readonly_filename, "w+") as readonly_file:
with open(readonly_filename, "w+", encoding="utf-8") as readonly_file:
readonly_file.write("Poetry rocks!")
os.chmod(str(readonly_filename), S_IREAD)

Expand Down

0 comments on commit c64538a

Please sign in to comment.