Skip to content

Commit

Permalink
fix: Always use encoding="utf8" when reading text files
Browse files Browse the repository at this point in the history
Issue #99: #99
PR #100: #100
  • Loading branch information
rudolfbyker authored Sep 10, 2022
1 parent 49b080f commit 3b279bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def check_types(ctx): # noqa: WPS231
# handle .pth files
for pth in pkgs_dir.glob("*.pth"):
with suppress(OSError):
for package in Path(pth.read_text().splitlines()[0]).glob("*"): # noqa: WPS440
for package in Path(pth.read_text(encoding="utf8").splitlines()[0]).glob("*"): # noqa: WPS440
if package.suffix != ".dist-info":
packages[package.name] = package

Expand All @@ -223,7 +223,7 @@ def check_types(ctx): # noqa: WPS231
Path(tmpdir, pkg_name).symlink_to(packages[pkg_name], target_is_directory=True)

# create temporary mypy config to ignore stubbed packages
newconfig = Path("config", "mypy.ini").read_text()
newconfig = Path("config", "mypy.ini").read_text(encoding="utf8")
newconfig += "\n" + "\n\n".join(f"[mypy-{pkg}.*]\nignore_errors=true" for pkg in ignore)
tmpconfig = Path(tmpdir, "mypy.ini")
tmpconfig.write_text(newconfig)
Expand Down
6 changes: 3 additions & 3 deletions src/griffe/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _top_module_name(self, path: Path) -> str:
# TODO: for better robustness, we should load and minify the AST
# to search for particular call statements
def _is_pkg_style_namespace(init_module: Path) -> bool:
code = init_module.read_text()
code = init_module.read_text(encoding="utf8")
return bool(_re_pkgresources.search(code) or _re_pkgutil.search(code))


Expand All @@ -304,7 +304,7 @@ def _handle_pth_file(path) -> list[Path]: # noqa: WPS231
# Blank lines and lines beginning with # are skipped.
# Lines starting with import (followed by space or tab) are executed.
directories = []
for line in path.read_text().strip().splitlines(keepends=False):
for line in path.read_text(encoding="utf8").strip().splitlines(keepends=False):
line = line.strip()
if line and not line.startswith("#") and not _re_import_line.search(line):
if os.path.exists(line):
Expand All @@ -314,7 +314,7 @@ def _handle_pth_file(path) -> list[Path]: # noqa: WPS231

def _handle_editables_module(path: Path):
try:
editables_lines = path.read_text().splitlines(keepends=False)
editables_lines = path.read_text(encoding="utf8").splitlines(keepends=False)
except FileNotFoundError:
raise UnhandledEditablesModuleError(path)
# example line: F.map_module('griffe', '/media/data/dev/griffe/src/griffe/__init__.py')
Expand Down
2 changes: 1 addition & 1 deletion src/griffe/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _get_async_reader():
logger.warning("aiofiles is not installed, fallback to blocking read")

async def _read_async(path): # noqa: WPS430
return path.read_text()
return path.read_text(encoding="utf8")

else:

Expand Down

0 comments on commit 3b279bf

Please sign in to comment.