Skip to content

Commit

Permalink
Remove all specified encoding for open()
Browse files Browse the repository at this point in the history
Disable `unspecified-encoding` for pylint.
  • Loading branch information
CasperWA committed Oct 26, 2021
1 parent e8c6fd3 commit e34979d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion emmopy/emmocheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
12 changes: 6 additions & 6 deletions ontopy/ontodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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", {})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ontopy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def write_catalog(mappings, output="catalog-v001.xml"):
res.append(f' <uri name="{key}" uri="{value}"/>')
res.append(" </group>")
res.append("</catalog>")
with open(output, "wt", encoding="utf8") as handle:
with open(output, "wt") as handle:
handle.write("\n".join(res) + "\n")


Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 5 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,35 @@ 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()
if not _.startswith("#") and "git+" not in _
] + 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<version>.*)"', line)
if match is not None:
Expand Down
12 changes: 6 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 = [
Expand All @@ -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)
4 changes: 2 additions & 2 deletions tools/ontograph
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e34979d

Please sign in to comment.