Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 28 deletions.
3 changes: 2 additions & 1 deletion tools/build_utils/check_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# author: Ole Schuett

import sys, os
import os
import sys
from subprocess import check_output
from os import path
from glob import glob
Expand Down
8 changes: 5 additions & 3 deletions tools/build_utils/discover_programs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3

import re, sys, os
import os
import re
import sys
from os import path

# pre-compiled regular expressions
Expand Down Expand Up @@ -45,7 +47,7 @@ def is_fortran_program(fn):
tail = f.read()
f.close()
m = re_program.search(tail.lower())
return m != None
return m is not None


# ============================================================================
Expand All @@ -54,7 +56,7 @@ def has_main_function(fn):
content = f.read()
f.close()
m = re_main.search(content)
return m != None
return m is not None


# ===============================================================================
Expand Down
2 changes: 1 addition & 1 deletion tools/coverage/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
for fn in coverage.keys():
cov_rate, nlines = coverage[fn]
uncov_lines = nlines * (100.0 - cov_rate) / 100.0
if ref_coverage.has_key(fn):
if fn in ref_coverage:
cov_rate0, nlines0 = ref_coverage[fn]
uncov_lines0 = nlines0 * (100.0 - cov_rate0) / 100.0
tol = max(nlines, nlines0) * 0.001 # uncov_lines has limited precision
Expand Down
6 changes: 3 additions & 3 deletions tools/dashboard/generate_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

try:
from typing import Literal
except:
except ImportError:
from typing_extensions import Literal # type: ignore

import matplotlib as mpl # type: ignore
Expand Down Expand Up @@ -687,7 +687,7 @@ def retrieve_report(url: str) -> Optional[str]:
etag_file.write_text(r.headers["ETag"])
return report_text

except:
except Exception:
traceback.print_exc()
return None

Expand Down Expand Up @@ -722,7 +722,7 @@ def parse_report(report_txt: Optional[str], log: GitLog) -> Report:
return Report("FAILED", "Unknown CommitSHA.")

return Report(status, summary, sha=sha, plots=plots, plot_points=points)
except:
except Exception:
traceback.print_exc()
return Report("UNKNOWN", "Error while parsing report.")

Expand Down
2 changes: 1 addition & 1 deletion tools/dashboard/generate_regtest_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def parse_report(report_url):
try:
float(parts[1]) # try parsing float...
values[test_name] = parts[1] # ... but pass on the original string
except:
except TypeError:
pass # ignore values which can not be parsed
else:
pass # ignore line
Expand Down
3 changes: 2 additions & 1 deletion tools/doxify/is_fypp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import sys, re
import re
import sys

FYPP_SYMBOLS = r"(#|\$|@)"
FYPP_LINE = r"^\s*" + FYPP_SYMBOLS + r":"
Expand Down
5 changes: 3 additions & 2 deletions tools/fix_unused_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# author: Ole Schuett

import re, sys
import re
import sys
from os import path
from os.path import dirname, basename, normpath
import os
Expand Down Expand Up @@ -118,7 +119,7 @@ def parse_file(fn):
# re.IGNORECASE is horribly expensive. Converting to lower-case upfront
content = content.lower()
content = re.sub("!.*\n", "\n", content)
content = re.sub("&\s*\n", "", content)
content = re.sub("&\\s*\n", "", content)
content = re.sub("&", " ", content)

mods = re_module.findall(content)
Expand Down
3 changes: 2 additions & 1 deletion tools/maple2f90/maple2f90.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import re, sys
import re
import sys

"""Script to help the conversion of maple generated fortran code to f90"""

Expand Down
2 changes: 1 addition & 1 deletion tools/minimax_tools/minimax_to_fortran_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def parse_data_set(input_path: Path) -> List[Approximation]:
if err == 0.0 or k >= 58:
continue
# slight change of notation e.g. 6E09 --> 6_9
Rc_filename = re.sub("E0?(?=\d)", "_", Rc_str.strip())
Rc_filename = re.sub(r"E0?(?=\d)", "_", Rc_str.strip())
filename = input_path / f"1_xk{k:02d}.{Rc_filename}"
assert filename.exists()

Expand Down
10 changes: 6 additions & 4 deletions tools/package_planner/plan_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

# A tool to help planning CP2K packages, listing currently violated dependencies if any

import re, sys, os
import os
import re
import sys
from os import path
from os.path import dirname, basename, normpath, abspath

Expand Down Expand Up @@ -139,7 +141,7 @@ def parse_file(parsed_files, fn):
content_lower = content.lower()

mods = re_module.findall(content_lower)
prog = re_program.search(content_lower) != None
prog = re_program.search(content_lower) is not None
uses = re_use.findall(content_lower)
incl1_iter = re_incl1.finditer(content_lower) # fortran includes
incls = [content[m.start(1) : m.end(1)] for m in incl1_iter]
Expand Down Expand Up @@ -246,7 +248,7 @@ def find_cycles(parsed_files, mod2fn, fn, S=None):
if "visited" in pf:
return

if S == None:
if S is None:
S = []

for m in pf["module"]:
Expand All @@ -267,7 +269,7 @@ def find_cycles(parsed_files, mod2fn, fn, S=None):

# =============================================================================
def find_pkg_cycles(packages, p, S=None):
if S == None:
if S is None:
S = []

if p in S:
Expand Down
2 changes: 1 addition & 1 deletion tools/precommit/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def process_file(fn, allow_modifications):
orig_lines = orig_content.decode("utf8").split("\n")
new_lines = new_content.decode("utf8").split("\n")
diff = unified_diff(orig_lines, new_lines, "before", "after", lineterm="")
except:
except Exception:
diff = [] #
raise Exception(f"File modified:\n" + "\n".join(diff))

Expand Down
2 changes: 1 addition & 1 deletion tools/prettify/prettify.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def main(argv):
print(f"prettified {filename}")
total_prettified += 1

except:
except Exception:
logger.exception("processing file failed", extra={"ffilename": filename})
failure += 1

Expand Down
10 changes: 5 additions & 5 deletions tools/prettify/prettify_cp2k/normalizeFortranFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
flags=re.IGNORECASE | re.VERBOSE,
)

COMMON_USES_RE = re.compile('^#include\s*"([^"]*(cp_common_uses.f90|base_uses.f90))"')
COMMON_USES_RE = re.compile(r'^#include\s*"([^"]*(cp_common_uses.f90|base_uses.f90))"')
LOCAL_NAME_RE = re.compile(
rf"\s*(?P<localName>{VALID_NAME})(?:\s*=>\s*{VALID_NAME})?\s*$", re.VERBOSE
)
Expand Down Expand Up @@ -320,7 +320,7 @@ def parseRoutine(inFile, logger):
break
routine["strippedCore"].append(subjline)
subF.close()
except:
except Exception:
import traceback

logger.debug(
Expand Down Expand Up @@ -484,7 +484,7 @@ def parseRoutine(inFile, logger):
break
routine["strippedCore"].append(subjline)
subF.close()
except:
except Exception:
import traceback

logger.debug(
Expand Down Expand Up @@ -921,7 +921,7 @@ def cleanDeclarations(routine, logger):
if wrote:
newDecl.write("\n")
routine["declarations"] = [newDecl.getvalue()]
except:
except Exception:
if "name" in routine.keys():
logger.critical("exception cleaning routine " + routine["name"])
logger.critical("parsedDeclartions={}".format(routine["parsedDeclarations"]))
Expand Down Expand Up @@ -1294,7 +1294,7 @@ def rewriteFortranFile(
with open(inc_absfn, "r", encoding="utf8") as fhandle:
implicitUsesRaw = parseUse(fhandle)
implicitUses = prepareImplicitUses(implicitUsesRaw["modules"])
except:
except Exception:
logger.critical(
"failed to parse use statements contained in common uses precompiler file {}".format(
inc_absfn
Expand Down
6 changes: 3 additions & 3 deletions tools/regtesting/do_regtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import Literal # not available before Python 3.8

TestStatus = Literal["OK", "WRONG RESULT", "RUNTIME FAIL", "TIMED OUT"]
except:
except ImportError:
TestStatus = str # type: ignore

# Some tests do not work with --keepalive (which is generally considered a bug).
Expand Down Expand Up @@ -255,7 +255,7 @@ def __init__(self, line: str):
self.pattern = self.pattern.replace(c, f"\\{c}") # escape special chars
try:
self.regex = re.compile(self.pattern)
except:
except Exception:
print("Bad regex: " + self.pattern)
raise
self.column = int(parts[1])
Expand Down Expand Up @@ -458,7 +458,7 @@ async def run_unittests(batch: Batch, cfg: Config) -> List[TestResult]:

# ======================================================================================
async def run_regtests(batch: Batch, cfg: Config) -> List[TestResult]:
if cfg.keepalive and not batch.name in KEEPALIVE_SKIP_DIRS:
if cfg.keepalive and batch.name not in KEEPALIVE_SKIP_DIRS:
return await run_regtests_keepalive(batch, cfg)
else:
return await run_regtests_classic(batch, cfg)
Expand Down

0 comments on commit 85e7b7d

Please sign in to comment.