Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce UTF-8 encoding for linter subprocess on Windows #69

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Fixed
- Version tag in pre-commit instructions.
- Avoid a buggy ``flake8-bugbear`` version in the CI build.
- Automation for updating version strings in README using ``darkgray_bump_version``.
- Enforce UTF-8 encoding when calling linter subprocesses on Windows.


2.0.0_ - 2024-07-31
Expand Down
5 changes: 4 additions & 1 deletion src/graylint/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,15 @@ def _check_linter_output(
existing_path_strs = sorted(str(path) for path in paths if (root / path).exists())
cmdline_and_paths = cmdline_parts + existing_path_strs
logger.debug("[%s]$ %s", root, shlex.join(cmdline_and_paths))
effective_env = env.copy()
if WINDOWS:
effective_env["PYTHONIOENCODING"] = "utf-8"
with Popen( # nosec
cmdline_and_paths,
stdout=PIPE,
encoding="utf-8",
cwd=root,
env=env,
env=effective_env,
) as linter_process:
# condition needed for MyPy (see https://stackoverflow.com/q/57350490/15770)
if linter_process.stdout is None:
Expand Down
Loading