Skip to content

Commit

Permalink
Fix Python 3.12 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Nov 4, 2023
1 parent ecebeaa commit f866722
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions docs/generate_input_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,30 @@ def main() -> None:
# ======================================================================================
def build_bibliography(references_html_fn: str, output_dir: Path) -> None:
content = Path(references_html_fn).read_text()
entries = re.findall("<TR>.*?</TR>", content, re.DOTALL)
entries = re.findall(r"<TR>.*?</TR>", content, re.DOTALL)

output = []
output += ["%", "% This file was created by generate_input_reference.py", "%"]
output += ["# Bibliography", ""]

for entry in entries:
pattern = (
'<TR><TD>\[(.*?)\]</TD><TD>\n <A NAME="reference_\d+">(.*?)</A><br>'
"(.*?)</TD></TR>"
r'<TR><TD>\[(.*?)\]</TD><TD>\n <A NAME="reference_\d+">(.*?)</A><br>'
r"(.*?)</TD></TR>"
)
parts = re.search(pattern, entry, re.DOTALL)
assert parts
key = parts.group(1)
title = parts.group(3).strip()
if "<br>" in parts.group(2):
m = re.match("(.*?)<br>(.*)", parts.group(2), re.DOTALL)
m = re.match(r"(.*?)<br>(.*)", parts.group(2), re.DOTALL)
assert m
authors, mix = m.groups()
else:
authors, mix = "", parts.group(2)

if "https://doi.org" in mix:
m = re.match('\s*<A HREF="(.*?)">(.*?)</A>', mix, re.DOTALL)
m = re.match(r'\s*<A HREF="(.*?)">(.*?)</A>', mix, re.DOTALL)
assert m
doi, ref = m.groups()
else:
Expand Down Expand Up @@ -367,13 +367,13 @@ def sanitize_name(name: str) -> str:
# ======================================================================================
def escape_markdown(text: str) -> str:
# Code blocks without a language get mistaken for the end of the py:data directive.
text = text.replace("\n\n```\n", "\n\n```none\n")
text = text.replace(r"\n\n```\n", r"\n\n```none\n")

# Underscores are very common in our docs. Luckily asterisks also work for emphasis.
text = text.replace("__", "\_\_")
text = text.replace(r"__", r"\_\_")

# Headings mess up the page structure. Please use paragraphs and bold text instead.
text = text.replace("#", "\#")
text = text.replace(r"#", r"\#")

return text

Expand Down
4 changes: 2 additions & 2 deletions tools/docker/generate_dockerfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ def install_cp2k(
if revision:
input_lines.append("ARG GIT_COMMIT_SHA")
run_lines.append(
'if [ -n "${GIT_COMMIT_SHA}" ] ; then'
' echo "git:\${GIT_COMMIT_SHA::7}" > REVISION; fi'
r'if [ -n "${GIT_COMMIT_SHA}" ] ; then'
r' echo "git:\${GIT_COMMIT_SHA::7}" > REVISION; fi'
)

input_lines.append("COPY ./Makefile .")
Expand Down
6 changes: 3 additions & 3 deletions tools/precommit/check_file_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pathlib
import re
import sys
from datetime import datetime
from datetime import datetime, timezone
from functools import lru_cache
import itertools
from typing import Tuple, List, TypeVar
Expand Down Expand Up @@ -77,7 +77,7 @@
FLAG_EXCEPTIONS_RE = re.compile(r"|".join(FLAG_EXCEPTIONS))
PORTABLE_FILENAME_RE = re.compile(r"^[a-zA-Z0-9._/#~=+-]*$")
OP_RE = re.compile(r"[\\|()!&><=*/+-]")
NUM_RE = re.compile("[0-9]+[ulUL]*")
NUM_RE = re.compile(r"[0-9]+[ulUL]*")
CP2K_FLAGS_RE = re.compile(
r"FUNCTION cp2k_flags\(\)(.*)END FUNCTION cp2k_flags", re.DOTALL
)
Expand Down Expand Up @@ -183,7 +183,7 @@ def check_file(path: pathlib.Path) -> List[str]:
warnings += [f"{path}:{i+1} Double space in multi-line string"]

# check banner
year = datetime.utcnow().year
year = datetime.now(timezone.utc).year
bsd_licensed = any(str(path).startswith(d) for d in BSD_DIRECTORIES)
spdx = "BSD-3-Clause " if bsd_licensed else "GPL-2.0-or-later"
if fn_ext == ".F" and not content.startswith(BANNER_F.format(year, spdx)):
Expand Down

0 comments on commit f866722

Please sign in to comment.