Skip to content

Commit

Permalink
Force encoding everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Nov 20, 2024
1 parent d2ead23 commit 0f6568a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
12 changes: 4 additions & 8 deletions meta_package_manager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
)
from click_extra.colorize import KO, OK, highlight
from click_extra.colorize import default_theme as theme
from extra_platforms import is_windows, reduce
from extra_platforms import reduce

from meta_package_manager.inventory import MAIN_PLATFORMS

Expand Down Expand Up @@ -96,10 +96,6 @@
"""


encoding_args = {"encoding": "utf-8"} if is_windows() else {}
"""Forcing encoding is required on Windows."""


def is_stdout(filepath: Path) -> bool:
"""Check if a file path is set to stdout.
Expand Down Expand Up @@ -1361,7 +1357,7 @@ def backup(ctx, overwrite, merge, update_version, toml_path):
"installed_version",
)
if merge or update_version:
installed_data = tomllib.loads(toml_path.read_text(**encoding_args))
installed_data = tomllib.loads(toml_path.read_text(encoding="utf-8"))

# Leave some metadata as comment.
content = (
Expand Down Expand Up @@ -1426,12 +1422,12 @@ def restore(ctx, toml_files):
for toml_input in toml_files:
is_stdin = isinstance(toml_input, TextIOWrapper)
if is_stdin:
toml_input.reconfigure(**encoding_args)
toml_input.reconfigure(encoding="utf-8")
toml_filepath = toml_input.name
toml_content = toml_input.read()
else:
toml_filepath = Path(toml_input.name).resolve()
toml_content = toml_filepath.read_text(**encoding_args)
toml_content = toml_filepath.read_text(encoding="utf-8")

logging.info(f"Load package list from {toml_filepath}")
doc = tomllib.loads(toml_content)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli_sbom.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_output_to_file(self, invoke, subcmd, export_format, standard_name):
result.stderr,
)
assert not result.stdout
content = Path(file_name).read_text()
content = Path(file_name).read_text(encoding="utf-8")

assert result.exit_code == 0
self.check_manager_selection(result)
Expand Down
11 changes: 5 additions & 6 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
else:
import tomli as tomllib # type: ignore[import-not-found]

from meta_package_manager.cli import encoding_args
from meta_package_manager.inventory import MAIN_PLATFORMS
from meta_package_manager.labels import LABELS, MANAGER_PREFIX, PLATFORM_PREFIX
from meta_package_manager.pool import pool
Expand Down Expand Up @@ -85,13 +84,13 @@ def test_all_platforms_covered_by_local_groups(manager):
def test_project_metadata():
# Fetch general information about the project from pyproject.toml.
toml_path = PROJECT_ROOT.joinpath("pyproject.toml").resolve()
toml_config = tomllib.loads(toml_path.read_text(**encoding_args))
toml_config = tomllib.loads(toml_path.read_text(encoding="utf-8"))
# Check all managers are referenced in Python package keywords.
assert set(pool.all_manager_ids).issubset(toml_config["project"]["keywords"])


def test_changelog():
content = PROJECT_ROOT.joinpath("changelog.md").read_text(**encoding_args)
content = PROJECT_ROOT.joinpath("changelog.md").read_text(encoding="utf-8")
assert content.startswith("# Changelog\n")

entry_pattern = re.compile(r"^- \[(?P<category>[a-z0-9,\-]+)\] (?P<entry>.+)")
Expand Down Expand Up @@ -128,7 +127,7 @@ def test_new_package_manager_issue_template():
"""Check all platforms groups are referenced in the issue template."""
content = PROJECT_ROOT.joinpath(
".github/ISSUE_TEMPLATE/new-package-manager.yaml",
).read_text(**encoding_args)
).read_text(encoding="utf-8")
assert content

template_platforms = load(content, Loader=Loader)["body"][3]["attributes"][
Expand All @@ -148,7 +147,7 @@ def test_new_package_manager_issue_template():
def test_labeller_rules():
# Extract list of extra labels.
content = PROJECT_ROOT.joinpath(".github/labels-extra.json").read_text(
**encoding_args,
encoding="utf-8"
)
assert content

Expand All @@ -175,7 +174,7 @@ def test_labeller_rules():
# Extract rules from json blurb serialized into YAML.
content = PROJECT_ROOT.joinpath(
".github/workflows/labeller-content-based.yaml",
).read_text(**encoding_args)
).read_text(encoding="utf-8")
assert "kdeldycke/workflows/.github/workflows/labeller-file-based.yaml" in content
extra_rules = load(content, Loader=Loader)["jobs"]["labeller"]["with"][
"extra-rules"
Expand Down

0 comments on commit 0f6568a

Please sign in to comment.