diff --git a/komodo/extract_dep_graph.py b/komodo/extract_dep_graph.py index ad1ff8a36..3e620fd91 100644 --- a/komodo/extract_dep_graph.py +++ b/komodo/extract_dep_graph.py @@ -7,7 +7,9 @@ def run(pkgfile, base_pkgfile, repofile, outfile=None): - with open(pkgfile) as p, open(base_pkgfile) as bp, open(repofile) as r: + with open(pkgfile, encoding="utf-8") as p, open( + base_pkgfile, encoding="utf-8" + ) as bp, open(repofile, encoding="utf-8") as r: yaml = YAML() pkgs, base_pkgs, repo = ( yaml.load(p), diff --git a/komodo/lint_maturity.py b/komodo/lint_maturity.py index 16fddd725..a29b6037a 100644 --- a/komodo/lint_maturity.py +++ b/komodo/lint_maturity.py @@ -100,7 +100,7 @@ def get_packages_info(release_file: ReleaseFile, tag_exceptions_package): def read_yaml_file(file_path): - with open(file_path) as yml_file: + with open(file_path, encoding="utf-8") as yml_file: return yaml.safe_load(yml_file) diff --git a/komodo/maintainer.py b/komodo/maintainer.py index 215bd680e..d8d62fdb8 100755 --- a/komodo/maintainer.py +++ b/komodo/maintainer.py @@ -6,7 +6,7 @@ def maintainers(pkgfile, repofile): - with open(pkgfile) as p, open(repofile) as r: + with open(pkgfile, encoding="utf-8") as p, open(repofile, encoding="utf-8") as r: yml = YAML() pkgs, repo = yml.load(p), yml.load(r) diff --git a/komodo/post_messages.py b/komodo/post_messages.py index c131b5661..f34765160 100644 --- a/komodo/post_messages.py +++ b/komodo/post_messages.py @@ -27,7 +27,7 @@ def create_inline_messages(messages, dst_path): for msg in messages: filename = hashlib.md5(msg.encode()).hexdigest() filename = "0Z" + filename # for orderings sake - with open(os.path.join(dst_path, filename), "w") as new_file: + with open(os.path.join(dst_path, filename), "w", encoding="utf-8") as new_file: new_file.write(msg) @@ -80,7 +80,7 @@ def main(args=None): if not os.path.isfile(args.motd_db): msg = f"ERROR: The message-database {args.motd_db} was not found" raise SystemExit(msg) - with open(args.motd_db) as motd_db_file: + with open(args.motd_db, encoding="utf-8") as motd_db_file: yml = YAML() motd_db = yml.load(motd_db_file) motd_path = os.path.dirname(args.motd_db) diff --git a/komodo/prettier.py b/komodo/prettier.py index 91fc529a9..7f9c68d2e 100644 --- a/komodo/prettier.py +++ b/komodo/prettier.py @@ -80,7 +80,7 @@ def prettified_yaml(filepath, check_only=True): If `check_only` is False, the input file will be "prettified" in place if necessary. """ print(f"Checking {filepath}... ", end="") - with open(file=filepath) as input_file: + with open(file=filepath, encoding="utf-8") as input_file: yaml_original = input_file.read() yaml_input = load_yaml(filepath) @@ -90,7 +90,7 @@ def prettified_yaml(filepath, check_only=True): if yaml_prettified_string != yaml_original: print(f"{'would be' if check_only else ''} reformatted!") if not check_only: - with open(filepath, "w") as fh: + with open(filepath, "w", encoding="utf-8") as fh: fh.write(yaml_prettified_string) return False @@ -107,7 +107,7 @@ def write_to_string(repository, check_type=True): def write_to_file(repository, filename, check_type=True): output_str = write_to_string(repository, check_type) - with open(filename, mode="w") as output_file: + with open(filename, mode="w", encoding="utf-8") as output_file: output_file.write(output_str) @@ -125,7 +125,7 @@ def load_yaml(filename): ruamel_instance.width = 1000 # Avoid ruamel wrapping long try: - with open(filename) as repo_handle: + with open(filename, encoding="utf-8") as repo_handle: return ruamel_instance.load(repo_handle) except ( diff --git a/komodo/reverse_dep_graph.py b/komodo/reverse_dep_graph.py index 901681db4..e3d94919b 100644 --- a/komodo/reverse_dep_graph.py +++ b/komodo/reverse_dep_graph.py @@ -11,7 +11,9 @@ def run(base_pkgfile, repofile, dot, display_pkg, out): - with open(base_pkgfile) as bp, open(repofile) as r: + with open(base_pkgfile, encoding="utf-8") as bp, open( + repofile, encoding="utf-8" + ) as r: base_pkgs, repo = yaml.safe_load(bp), yaml.safe_load(r) reverse = build_reverse(base_pkgs, repo) @@ -150,7 +152,7 @@ def main(): print(f"you entered {pkg}") if args.out: - with open(args.out, "w") as out: + with open(args.out, "w", encoding="utf-8") as out: run(args.base_pkgs, args.repo, args.dot, pkg, out) elif args.display_dot: try: diff --git a/komodo/shebang.py b/komodo/shebang.py index 74157dcb8..cb1e2bb8e 100644 --- a/komodo/shebang.py +++ b/komodo/shebang.py @@ -32,7 +32,7 @@ def fixup_python_shebangs(prefix, release): # executables with wrong shebang for bin_ in os.listdir(binpath): try: - with open(os.path.join(binpath, bin_)) as f: + with open(os.path.join(binpath, bin_), encoding="utf-8") as f: shebang = f.readline().strip() if _is_shebang(shebang): bins_.append(bin_) diff --git a/komodo/switch.py b/komodo/switch.py index cdf937f9d..43a7f058d 100644 --- a/komodo/switch.py +++ b/komodo/switch.py @@ -33,8 +33,10 @@ def create_activator_switch(data, prefix, release): os.makedirs(release_path) - with open(os.path.join(release_path, "enable"), "w") as activator, open( - data.get("activator_switch.tmpl"), + with open( + os.path.join(release_path, "enable"), "w", encoding="utf-8" + ) as activator, open( + data.get("activator_switch.tmpl"), encoding="utf-8" ) as activator_tmpl: activator.write( Template(activator_tmpl.read(), keep_trailing_newline=True).render( @@ -44,8 +46,10 @@ def create_activator_switch(data, prefix, release): ), ) - with open(os.path.join(release_path, "enable.csh"), "w") as activator, open( - data.get("activator_switch.csh.tmpl"), + with open( + os.path.join(release_path, "enable.csh"), "w", encoding="utf-8" + ) as activator, open( + data.get("activator_switch.csh.tmpl"), encoding="utf-8" ) as activator_tmpl: activator.write( Template(activator_tmpl.read(), keep_trailing_newline=True).render( diff --git a/komodo/symlink/create_links.py b/komodo/symlink/create_links.py index 7c3e77494..30fc90dde 100644 --- a/komodo/symlink/create_links.py +++ b/komodo/symlink/create_links.py @@ -90,7 +90,7 @@ def symlink_main(): if not os.path.isfile(args.config): sys.exit(f"The file {args.config} can not be found") - with open(args.config) as input_file: + with open(args.config, encoding="utf-8") as input_file: input_dict = json.load(input_file) errors = verify_integrity(input_dict) diff --git a/pyproject.toml b/pyproject.toml index be3644796..31797e40a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,7 +101,6 @@ disable = [ "too-many-locals", "too-many-statements", "unnecessary-lambda", - "unspecified-encoding", "unused-argument", "use-a-generator", "use-implicit-booleaness-not-comparison", diff --git a/tests/__init__.py b/tests/__init__.py index 803970e15..1ff79aa6e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,5 +15,5 @@ def _load_yaml(filename): offset=2, ) ruamel_instance.width = 1000 # Avoid ruamel wrapping long - with open(filename) as repo_handle: + with open(filename, encoding="utf-8") as repo_handle: return ruamel_instance.load(repo_handle) diff --git a/tests/test_cli.py b/tests/test_cli.py index 9eaaa19d3..11692c46f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -69,7 +69,7 @@ def test_main(args, tmpdir): assert os.path.exists(downloaded_file) assert os.access(downloaded_file, os.X_OK) - with open(os.path.join(release_path, release_name)) as releasedoc: + with open(os.path.join(release_path, release_name), encoding="utf-8") as releasedoc: releasedoc_content = releasedoc.read() # test specifically for the regression introduced by diff --git a/tests/test_enable_scipts.py b/tests/test_enable_scipts.py index 7c571bc98..c70baa8a5 100644 --- a/tests/test_enable_scipts.py +++ b/tests/test_enable_scipts.py @@ -6,11 +6,11 @@ def _load_envs(): - with open("pre_source.env") as pre: + with open("pre_source.env", encoding="utf-8") as pre: pre_env = json.loads(pre.read()) - with open("sourced.env") as sourced: + with open("sourced.env", encoding="utf-8") as sourced: sourced_env = json.loads(sourced.read()) - with open("post_disable.env") as post: + with open("post_disable.env", encoding="utf-8") as post: post_env = json.loads(post.read()) return pre_env, sourced_env, post_env @@ -36,7 +36,7 @@ def test_enable_bash_nopresets(tmpdir): with tmpdir.as_cwd(): Path("bleeding").mkdir() create_enable_scripts(komodo_prefix="prefix", komodo_release="bleeding") - with open("test_enable.sh", "w") as test_file: + with open("test_enable.sh", "w", encoding="utf-8") as test_file: test_file.write( TEST_SCRIPT_SIMPLE.format( set_envs=CLEAN_BASH_ENV, @@ -64,7 +64,7 @@ def test_enable_csh_no_presets(tmpdir): with tmpdir.as_cwd(): Path("bleeding").mkdir() create_enable_scripts(komodo_prefix="prefix", komodo_release="bleeding") - with open("test_enable.sh", "w") as test_file: + with open("test_enable.sh", "w", encoding="utf-8") as test_file: test_file.write( TEST_SCRIPT_SIMPLE.format( set_envs=CLEAN_CSH_ENV, diff --git a/tests/test_link_io_structure.py b/tests/test_link_io_structure.py index 9a57ac630..4f510a7f3 100644 --- a/tests/test_link_io_structure.py +++ b/tests/test_link_io_structure.py @@ -131,7 +131,7 @@ def test_integration(tmpdir): test_folder = _get_test_root() shutil.copy(os.path.join(test_folder, "data/links.json"), tmpdir) with tmpdir.as_cwd(): - with open("links.json") as link_file: + with open("links.json", encoding="utf-8") as link_file: input_dict = json.load(link_file) input_dict["root_folder"] = os.path.realpath(input_dict["root_folder"]) @@ -150,7 +150,7 @@ def test_root_links(tmpdir): test_folder = _get_test_root() shutil.copy(os.path.join(test_folder, "data/links.json"), tmpdir) with tmpdir.as_cwd(): - with open("links.json") as link_file: + with open("links.json", encoding="utf-8") as link_file: input_dict = json.load(link_file) assert_root_nodes(input_dict) @@ -257,12 +257,14 @@ def test_executables(tmpdir): sys.argv = ["run", "links_test.json"] try: test_folder = _get_test_root() - with open(os.path.join(test_folder, "data/links_full.json")) as input_file: + with open( + os.path.join(test_folder, "data/links_full.json"), encoding="utf-8" + ) as input_file: input_data = json.load(input_file) with tmpdir.as_cwd(): input_data["root_folder"] = str(tmpdir) - with open("links_test.json", "w") as test_file: + with open("links_test.json", "w", encoding="utf-8") as test_file: test_file.write(json.dumps(input_data)) with pytest.raises(SystemExit): diff --git a/tests/test_lint_maturity.py b/tests/test_lint_maturity.py index 9f0419dc6..d1e257413 100644 --- a/tests/test_lint_maturity.py +++ b/tests/test_lint_maturity.py @@ -22,7 +22,7 @@ def _create_tmp_test_files(release_sample, file_names_sample): for file_name in file_names_sample: list_files.append(folder_name + file_name) - with open(folder_name + file_name, "w") as file_sample: + with open(folder_name + file_name, "w", encoding="utf-8") as file_sample: file_sample.write(release_sample) return list_files diff --git a/tests/test_non_deployed.py b/tests/test_non_deployed.py index 5a003d54a..86c39fe1b 100644 --- a/tests/test_non_deployed.py +++ b/tests/test_non_deployed.py @@ -47,9 +47,13 @@ def test_non_deployed(tmpdir): os.makedirs(os.path.join(install_root, "2019.11.05-py38-rhel7/root")) # Create matrix files - with open(os.path.join(release_folder, "2019.11.05.yml"), "a"): + with open( + os.path.join(release_folder, "2019.11.05.yml"), "a", encoding="utf-8" + ): pass - with open(os.path.join(release_folder, "2019.12.02.yml"), "a"): + with open( + os.path.join(release_folder, "2019.12.02.yml"), "a", encoding="utf-8" + ): pass expected = ("2019.12.02",) @@ -74,9 +78,13 @@ def test_links_ignored(tmpdir): ), root=install_root, ) - with open(os.path.join(release_folder, "2019.12.01.yml"), "a"): + with open( + os.path.join(release_folder, "2019.12.01.yml"), "a", encoding="utf-8" + ): pass - with open(os.path.join(release_folder, "2022.02.02.yml"), "a"): + with open( + os.path.join(release_folder, "2022.02.02.yml"), "a", encoding="utf-8" + ): pass non_deployed = fetch_non_deployed(install_root, release_folder) diff --git a/tests/test_post_messages.py b/tests/test_post_messages.py index 12051d8bd..2f05c6798 100644 --- a/tests/test_post_messages.py +++ b/tests/test_post_messages.py @@ -11,7 +11,7 @@ def test_get_messages(): motd_db_file = os.path.join(_get_test_root(), "data/test_messages/motd_db.yml") yaml = YAML() - with open(motd_db_file) as f: + with open(motd_db_file, encoding="utf-8") as f: motd_db = yaml.load(f) release = "2020.01.01-py27-rhel6" @@ -148,7 +148,7 @@ def test_main_success_symlinks(tmpdir): os.path.join("2020.01.01-py27-rhel6", "motd", "scripts"), ) yaml = YAML() - with open(motd_db_file) as f: + with open(motd_db_file, encoding="utf-8") as f: motd_db = yaml.load(f) msg = motd_db["stable"]["inline"][0] filename = hashlib.md5(msg.encode()).hexdigest() diff --git a/tests/test_release_cleanup.py b/tests/test_release_cleanup.py index a40df4c15..6defd4d31 100644 --- a/tests/test_release_cleanup.py +++ b/tests/test_release_cleanup.py @@ -112,7 +112,7 @@ def test_write_to_file(tmpdir): unused_versions = find_unused_versions(used_versions, repository) remove_unused_versions(repository, unused_versions) write_to_file(repository, "output_repo.yml") - with open("output_repo.yml") as output: + with open("output_repo.yml", encoding="utf-8") as output: assert output.read() == expected_result diff --git a/tests/test_release_transpiler.py b/tests/test_release_transpiler.py index b79dbf515..f394cc414 100644 --- a/tests/test_release_transpiler.py +++ b/tests/test_release_transpiler.py @@ -46,7 +46,7 @@ def test_build_release_matrix_py_coords( build_matrix_file(release_base, release_folder, builtins, py_coords_input) new_release_file = f"{release_base}.yml" assert os.path.isfile(new_release_file) - with open(new_release_file) as f: + with open(new_release_file, encoding="utf-8") as f: release_matrix = yaml.safe_load(f) assert release_matrix["lib1"] == builtins["lib1"] diff --git a/tests/test_up_to_date_pypi.py b/tests/test_up_to_date_pypi.py index c36771592..86ab628f0 100644 --- a/tests/test_up_to_date_pypi.py +++ b/tests/test_up_to_date_pypi.py @@ -244,7 +244,7 @@ def test_check_up_to_date_file_output(monkeypatch, tmpdir, capsys): ) result = {} - with open(f"{base_path}/repository_file.yml") as fin: + with open(f"{base_path}/repository_file.yml", encoding="utf-8") as fin: result["updated_repo"] = yaml.load(fin) assert result == { @@ -441,9 +441,9 @@ def test_run_up_to_date( result = {} yaml = YAML() - with open("new_file") as fin: + with open("new_file", encoding="utf-8") as fin: result["release"] = yaml.load(fin) - with open("repository_file") as fin: + with open("repository_file", encoding="utf-8") as fin: result["repo"] = yaml.load(fin) assert result == expected