Skip to content

Commit

Permalink
python: ruff and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
entorb committed Mar 18, 2023
1 parent 35cd7e4 commit b2f30fb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
28 changes: 17 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ repos:
# - id: sort-simple-yaml
- id: trailing-whitespace

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
hooks:
- id: markdownlint
args: ["--disable", "MD013"]

# - repo: https://github.com/markdownlint/markdownlint
# rev: v0.12.0
# hooks:
# - id: markdownlint

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.257"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
hooks:
Expand Down Expand Up @@ -141,16 +158,5 @@ repos:
# hooks:
# - id: codespell

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
hooks:
- id: markdownlint
args: ["--disable", "MD013"]

# - repo: https://github.com/markdownlint/markdownlint
# rev: v0.12.0
# hooks:
# - id: markdownlint

default_language_version:
python: python3.10
4 changes: 2 additions & 2 deletions chapters/translations/1_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def download_file(url: str, filepath: str):
Download file from url to filepath.
"""
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0 ",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0 ", # noqa: E501
}
cont = requests.get(url, headers=headers, verify=True, timeout=3).content
# verify=False -> skip SSL cert verification: CERTIFICATE_VERIFY_FAILED
with open(filepath, mode="bw") as fh:
fh.write(cont)


def download_all_chapters():
def download_all_chapters() -> None:
"""
Download all chapters.
Expand Down
9 changes: 0 additions & 9 deletions chapters/translations/3_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ def html_modify():
for translator in translators:
print("===" + translator + "===")

# fhAll = open(
# f"4-join/hpmor-{translator}.html", mode="w", encoding="utf-8", newline="\n"
# )
# fhAll.write(html_start)

for fileIn in sorted(glob.glob(f"2-extract/{translator}/*.html")):
(filePath, fileName) = os.path.split(fileIn)
fileOut = f"3-clean/{translator}/{fileName}"
Expand Down Expand Up @@ -74,10 +69,6 @@ def html_modify():
fh.write(html_start)
fh.write(out)
fh.write(html_end)
# fhAll.write(out)
# break
# fhAll.write(html_end)
# fhAll.close()


def html_tuning(s: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_chapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def process_file(file_in: Path) -> bool:
encoding="utf-8",
) as file2:
diff = difflib.ndiff(file1.readlines(), file2.readlines())
delta = "".join(l for l in diff if l.startswith("+ ") or l.startswith("- "))
delta = "".join(x for x in diff if x.startswith("+ ") or x.startswith("- "))
print(file_in.name + "\n" + delta)

return issues_found
Expand Down
4 changes: 2 additions & 2 deletions scripts/compare-translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def download_file(url: str, filepath: str):
Download file from url to filepath.
"""
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0 ",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0 ", # noqa: E501
}
cont = requests.get(url, headers=headers, verify=True, timeout=3).content
# verify=False -> skip SSL cert verification: CERTIFICATE_VERIFY_FAILED
Expand All @@ -69,7 +69,7 @@ def download_file(url: str, filepath: str):

# TODO: FR uses master as branch name
def download_all_chapters():
baseurl = "https://raw.githubusercontent.com/<<repo>>/main/chapters/hpmor-chapter-<<chapter-no>>.tex"
baseurl = "https://raw.githubusercontent.com/<<repo>>/main/chapters/hpmor-chapter-<<chapter-no>>.tex" # noqa: E501

# for lang in translations.keys():
lang = other_lang
Expand Down
2 changes: 1 addition & 1 deletion scripts/ebook/6.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

# remove duplication of author name
cont = re.sub(
r"""<p>Fanfiction.*?<p>Basierend auf der Harry Potter Reihe von J. K. Rowling.*?</p>""",
r"""<p>Fanfiction.*?<p>Basierend auf der Harry Potter Reihe von J. K. Rowling.*?</p>""", # noqa: E501
"<p>Fanfiction basierend auf der Harry Potter Reihe von J. K. Rowling</p>",
cont,
flags=re.DOTALL | re.IGNORECASE,
Expand Down
1 change: 1 addition & 0 deletions scripts/ebook/v1/1_latex2html.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# by Torben Menke https://entorb.net
# flake8: noqa
"""
Converter script.
Expand Down

0 comments on commit b2f30fb

Please sign in to comment.