adds encoding="utf-8" everywhere

This commit is contained in:
James Livulpi 2021-09-05 13:30:42 -04:00
parent ba3dbad41d
commit 0228426bcd
18 changed files with 24 additions and 25 deletions

View File

@ -31,7 +31,6 @@ disable=no-self-use,
import-outside-toplevel,
raise-missing-from,
arguments-renamed,
unspecified-encoding,
[BASIC]
function-rgx=[a-z_][a-z0-9_]{2,50}$

View File

@ -95,7 +95,7 @@ def main():
setup_path = os.path.join(dst, "setup.py")
# Insert the include statement to MANIFEST.in if not present
with open(manifest_path, "a+") as manifest:
with open(manifest_path, "a+", encoding="utf-8") as manifest:
manifest.seek(0)
manifest_content = manifest.read()
if "include fastentrypoints.py" not in manifest_content:
@ -104,7 +104,7 @@ def main():
)
# Insert the import statement to setup.py if not present
with open(setup_path, "a+") as setup:
with open(setup_path, "a+", encoding="utf-8") as setup:
setup.seek(0)
setup_content = setup.read()
if "import fastentrypoints" not in setup_content:

View File

@ -11,7 +11,7 @@ class RSTFile:
"""Context manager wrapping a file and adding rst utility methods."""
def __init__(self, filename):
self._file = open(filename, "w")
self._file = open(filename, "w", encoding="utf-8")
self._write_header()
def __enter__(self):

View File

@ -97,7 +97,7 @@ def generate_commandline_options():
groups, titles = _get_options(argparser)
# Synopsis
filename_synopsis = "docs/manpage/synopsis.rstsrc"
with open(filename_synopsis, "w") as f:
with open(filename_synopsis, "w", encoding="utf-8") as f:
synopsis_options = ["[%s]" % (title) for title in titles]
synopsis = "**vimiv** %s" % (" ".join(synopsis_options))
f.write(synopsis)

View File

@ -49,7 +49,7 @@ def get_parser() -> argparse.ArgumentParser:
def read_history(*, mode: str, filename: str) -> List[str]:
with open(filename, "r") as f:
with open(filename, "r", encoding="utf-8") as f:
content = json.load(f)
return content[mode]

View File

@ -25,7 +25,7 @@ except NameError:
def read_file(filename):
"""Read content of filename into string and return it."""
with open(filename) as f:
with open(filename, encoding="utf-8") as f:
return f.read()

View File

@ -30,7 +30,7 @@ def custom_configfile(tmp_path, custom_configparser):
def create_custom_configfile(basename, read, default_parser, **sections):
parser = custom_configparser(default_parser, **sections)
path = tmp_path / basename
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
parser.write(f)
read(str(path))

View File

@ -101,7 +101,7 @@ def test_tag_write(tagwrite):
def test_tag_write_header(tagwrite):
with open(tagwrite.path, "r") as f:
with open(tagwrite.path, "r", encoding="utf-8") as f:
comment_lines = [line for line in f if line.startswith(Tag.COMMENTCHAR)]
assert "vimiv tag file" in comment_lines[0]
date_re = re.compile(r"# created: \d\d\d\d-\d\d-\d\d \d\d:\d\d")
@ -111,7 +111,7 @@ def test_tag_write_header(tagwrite):
def test_tag_write_paths(tagwrite):
with open(tagwrite.path, "r") as f:
with open(tagwrite.path, "r", encoding="utf-8") as f:
path_lines = [
line.strip() for line in f if not line.startswith(Tag.COMMENTCHAR)
]
@ -142,7 +142,7 @@ def test_tag_delete(mark, parts):
name = os.path.join(*parts)
tagpath = Tag.path(name)
os.makedirs(os.path.dirname(tagpath), exist_ok=True, mode=0o700)
with open(Tag.path(name), "w") as f:
with open(Tag.path(name), "w", encoding="utf-8") as f:
f.write("My tag content")
mark.tag_delete(basename)
assert not os.path.exists(Tag.path(basename))

View File

@ -28,7 +28,7 @@ def mode_based_history_file(tmp_path, mocker):
"""Fixture to create mode-based history file to initialize History."""
path = tmp_path / "history.json"
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
json.dump(MODE_HISTORY, f)
mocker.patch.object(History, "filename", return_value=str(path))
@ -58,7 +58,7 @@ def test_write_history(mode_based_history_file, history):
history_deque.extend(MODE_HISTORY[mode.name])
history.write()
with open(history.filename(), "r") as f:
with open(history.filename(), "r", encoding="utf-8") as f:
written_history = json.load(f)
assert written_history == MODE_HISTORY

View File

@ -32,7 +32,7 @@ def config(tmp_path):
parser = configparser.ConfigParser()
parser[SECTION_NAME][OPTION_NAME] = "${env:" + ENV_VARIABLE.name + "}"
path = tmp_path / "config.ini"
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
parser.write(f)
yield str(path)

View File

@ -44,7 +44,7 @@ def style_file(tmp_path):
parser["STYLE"]["font"] = font
for key, value in options.items():
parser["STYLE"][key] = value
with open(filename, "w") as f:
with open(filename, "w", encoding="utf-8") as f:
parser.write(f)
return filename

View File

@ -34,13 +34,13 @@ def mock_gtk_version(tmp_path, monkeypatch):
for basename in ("vimivrc", "keys.conf"):
abspath = xdg.vimiv_config_dir(basename)
with open(abspath, "w") as f:
with open(abspath, "w", encoding="utf-8") as f:
f.write("option: value\n")
tag_dir = xdg.vimiv_data_dir("Tags")
os.mkdir(tag_dir)
tag_file = os.path.join(tag_dir, TAGFILE_NAME)
with open(tag_file, "w") as f:
with open(tag_file, "w", encoding="utf-8") as f:
for i in range(10):
f.write(f"test_{i:02d}.jpg\n")

View File

@ -55,7 +55,7 @@ def test_undelete_file(deleted_file):
def test_create_trashinfo(deleted_file):
with open(deleted_file.info, "r") as f:
with open(deleted_file.info, "r", encoding="utf-8") as f:
content = f.read()
assert content.startswith("[Trash Info]"), "Trash info header not created"

View File

@ -338,7 +338,7 @@ class Tag:
try:
# We are writing our own context-manager here
# pylint: disable=consider-using-with
self._file = open(abspath, self._mode)
self._file = open(abspath, self._mode, encoding="utf-8")
except FileNotFoundError: # For read-only if the file does not exist
raise commands.CommandError(f"No tag called '{name}'")
except OSError as e:

View File

@ -51,7 +51,7 @@ class History(dict):
def write(self):
"""Write history of each mode to the json file."""
with open(self.filename(), "w") as f:
with open(self.filename(), "w", encoding="utf-8") as f:
json.dump(
{mode.name: list(value) for mode, value in self.items()}, f, indent=4
)
@ -60,7 +60,7 @@ class History(dict):
"""Backup and read history from the old text-file history."""
old_path = self.filename().replace(".json", "")
if os.path.isfile(old_path):
with open(old_path, "r") as f:
with open(old_path, "r", encoding="utf-8") as f:
old_commands = [line.strip() for line in f]
backup_name = old_path + ".bak"
_logger.info(
@ -83,7 +83,7 @@ class History(dict):
history: DefaultDict[str, list] = collections.defaultdict(list)
try:
with open(path, "r") as f:
with open(path, "r", encoding="utf-8") as f:
history.update(json.load(f))
_logger.debug("Loaded history from '%s'", path)
except FileNotFoundError:

View File

@ -25,7 +25,7 @@ def parse(cli_path: str) -> None:
def dump(path: str) -> None:
"""Write default configurations to config file at path."""
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
get_default_parser().write(f)
_logger.debug("Created default configuration file '%s'", path)

View File

@ -26,7 +26,7 @@ def parse(cli_path: str):
def dump(path: str):
"""Write default keybindings to keys file at path."""
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
get_default_parser().write(f)
_logger.debug("Created default keys file '%s'", path)

View File

@ -264,7 +264,7 @@ def dump(name: str, style: Style):
for option, value in style.items():
option = option.strip("{}")
parser["STYLE"][option] = value
with open(filename, "w") as f:
with open(filename, "w", encoding="utf-8") as f:
f.write(
"; This file is a reference for creating own styles."
" It will never be read.\n"