From e34979d0f8495e12dc8bbf53af537314331ba74d Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Tue, 26 Oct 2021 15:24:55 +0200 Subject: [PATCH] Remove all specified encoding for open() Disable `unspecified-encoding` for pylint. --- emmopy/emmocheck.py | 2 +- ontopy/ontodoc.py | 12 ++++++------ ontopy/utils.py | 2 +- pyproject.toml | 4 ++-- setup.py | 18 +++++------------- tasks.py | 12 ++++++------ tools/ontograph | 4 ++-- 7 files changed, 23 insertions(+), 31 deletions(-) diff --git a/emmopy/emmocheck.py b/emmopy/emmocheck.py index ef1e1c671..2be9e66a1 100644 --- a/emmopy/emmocheck.py +++ b/emmopy/emmocheck.py @@ -635,7 +635,7 @@ def main(): # pylint: disable=too-many-locals,too-many-branches,too-many-statem if args.configfile: import yaml # pylint: disable=import-outside-toplevel - with open(args.configfile, "rt", encoding="utf8") as handle: + with open(args.configfile, "rt") as handle: TestEMMOConventions.config.update( yaml.load(handle, Loader=yaml.SafeLoader) ) diff --git a/ontopy/ontodoc.py b/ontopy/ontodoc.py index c4063c8b4..52067049e 100644 --- a/ontopy/ontodoc.py +++ b/ontopy/ontodoc.py @@ -1144,7 +1144,7 @@ def write( # pylint: disable=too-many-arguments temp_file.flush() genfile = temp_file.name else: - with open(genfile, "wt", encoding="utf8") as handle: + with open(genfile, "wt") as handle: handle.write(content) run_pandoc( genfile, @@ -1157,14 +1157,14 @@ def write( # pylint: disable=too-many-arguments else: if verbose: print("Writing:", outfile) - with open(outfile, "wt", encoding="utf8") as handle: + with open(outfile, "wt") as handle: handle.write(content) def load_pandoc_option_file(yamlfile): """Loads pandoc options from `yamlfile` and return a list with corresponding pandoc command line arguments.""" - with open(yamlfile, encoding="utf8") as handle: + with open(yamlfile) as handle: pandoc_options = yaml.safe_load(handle) options = pandoc_options.pop("input-files", []) variables = pandoc_options.pop("variables", {}) @@ -1318,9 +1318,9 @@ def run_pandoc_pdf(latex_dir, pdf_engine, outfile, args, verbose=True): # Fixing tex output texfile2 = basename + "2.tex" - with open(texfile, "rt", encoding="utf8") as handle: + with open(texfile, "rt") as handle: content = handle.read().replace(r"\$\Uptheta\$", r"$\Uptheta$") - with open(texfile2, "wt", encoding="utf8") as handle: + with open(texfile2, "wt") as handle: handle.write(content) # Run latex @@ -1411,7 +1411,7 @@ def get_docpp( # pylint: disable=too-many-arguments ): """Read `infile` and return a new docpp instance.""" if infile: - with open(infile, "rt", encoding="utf8") as handle: + with open(infile, "rt") as handle: template = handle.read() basedir = os.path.dirname(infile) else: diff --git a/ontopy/utils.py b/ontopy/utils.py index d3ce686c0..21cca95e0 100644 --- a/ontopy/utils.py +++ b/ontopy/utils.py @@ -369,7 +369,7 @@ def write_catalog(mappings, output="catalog-v001.xml"): res.append(f' ') res.append(" ") res.append("") - with open(output, "wt", encoding="utf8") as handle: + with open(output, "wt") as handle: handle.write("\n".join(res) + "\n") diff --git a/pyproject.toml b/pyproject.toml index b8d56df89..1e917a1ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,8 +6,8 @@ target-version = ['py36', 'py37'] disable = [ "wrong-hanging-indentation", # C0330 "bad-whitespace", # C0326 - "duplicate-code" # R0801 - # "no-name-in-module" + "duplicate-code", # R0801 + "unspecified-encoding" # W1514 ] [tool.pylint.format] diff --git a/setup.py b/setup.py index 1c01ed039..df9ce28e7 100644 --- a/setup.py +++ b/setup.py @@ -26,33 +26,27 @@ def fglob(patt): # Read long description from README.md file replacing references to local # files to github urls BASE_URL = "https://raw.githubusercontent.com/emmo-repo/EMMO-python/master/" -with open(os.path.join(rootdir, "README.md"), "rt", encoding="utf8") as handle: +with open(os.path.join(rootdir, "README.md"), "rt") as handle: long_description = re.sub( r"(\[[^]]+\])\(([^:)]+)\)", fr"\1({BASE_URL}\2)", handle.read() ) # Read requirements from requirements.txt file -with open( - os.path.join(rootdir, "requirements.txt"), "rt", encoding="utf8" -) as handle: +with open(os.path.join(rootdir, "requirements.txt"), "rt") as handle: REQUIREMENTS = [ f"{_.strip()}" for _ in handle.readlines() if not _.startswith("#") and "git+" not in _ ] -with open( - os.path.join(rootdir, "requirements_docs.txt"), "r", encoding="utf8" -) as handle: +with open(os.path.join(rootdir, "requirements_docs.txt"), "r") as handle: DOCS = [ f"{_.strip()}" for _ in handle.readlines() if not _.startswith("#") and "git+" not in _ ] -with open( - os.path.join(rootdir, "requirements_dev.txt"), "r", encoding="utf8" -) as handle: +with open(os.path.join(rootdir, "requirements_dev.txt"), "r") as handle: DEV = [ f"{_.strip()}" for _ in handle.readlines() @@ -60,9 +54,7 @@ def fglob(patt): ] + DOCS # Retrieve emmo-package version -with open( - os.path.join(rootdir, "ontopy/__init__.py"), encoding="utf8" -) as handle: +with open(os.path.join(rootdir, "ontopy/__init__.py")) as handle: for line in handle: match = re.match(r'__version__ = "(?P.*)"', line) if match is not None: diff --git a/tasks.py b/tasks.py index 8809abcf5..99936ac13 100644 --- a/tasks.py +++ b/tasks.py @@ -23,13 +23,13 @@ def update_file( filename: str, sub_line: "Tuple[str, str]", strip: str = None ) -> None: """Utility function for tasks to read, update, and write files""" - with open(filename, "r", encoding="utf8") as handle: + with open(filename, "r") as handle: lines = [ re.sub(sub_line[0], sub_line[1], line.rstrip(strip)) for line in handle ] - with open(filename, "w", encoding="utf8") as handle: + with open(filename, "w") as handle: handle.write("\n".join(lines)) handle.write("\n") @@ -76,13 +76,13 @@ def create_api_reference_docs(context, pre_clean=False, pre_commit=False): def write_file(full_path: Path, content: str) -> None: """Write file with `content` to `full_path`""" if full_path.exists(): - with open(full_path, "r", encoding="utf8") as handle: + with open(full_path, "r") as handle: cached_content = handle.read() if content == cached_content: del cached_content return del cached_content - with open(full_path, "w", encoding="utf8") as handle: + with open(full_path, "w") as handle: handle.write(content) package_dirs = (TOP_DIR / "emmopy", TOP_DIR / "ontopy") @@ -189,7 +189,7 @@ def create_docs_index(_): readme = TOP_DIR / "README.md" docs_index = TOP_DIR / "docs/index.md" - with open(readme, encoding="utf8") as handle: + with open(readme) as handle: content = handle.read() replacement_mapping = [ @@ -201,5 +201,5 @@ def create_docs_index(_): for old, new in replacement_mapping: content = content.replace(old, new) - with open(docs_index, "w", encoding="utf8") as handle: + with open(docs_index, "w") as handle: handle.write(content) diff --git a/tools/ontograph b/tools/ontograph index 22eaaceab..b968a46c0 100755 --- a/tools/ontograph +++ b/tools/ontograph @@ -207,12 +207,12 @@ def main(): # pylint: disable=too-many-locals,too-many-branches,too-many-statem # Update style from json file if args.style_file: - with open(args.style_file, "rt", encoding="utf8") as handle: + with open(args.style_file, "rt") as handle: style.update(json.load(handle)) # Write style to json file if args.generate_style_file: - with open(args.generate_style_file, "wt", encoding="utf8") as handle: + with open(args.generate_style_file, "wt") as handle: json.dump(style, handle, indent=4) # Join all --leafs options