mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-21 06:25:15 -04:00
Python: PEP8 fixes (#1926)
* fix [E401](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) * fix [E711](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) * fix [E713](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) * fix [E722](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) * fix [W601](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) * fix [W605](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes)
This commit is contained in:
parent
2e46d64db7
commit
85e7b7d615
14 changed files with 36 additions and 28 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
# ============================================================================
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
# ===============================================================================
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ from typing import Any, List, Dict, cast, Optional, ValuesView, NewType
|
|||
|
||||
try:
|
||||
from typing import Literal
|
||||
except:
|
||||
except ImportError:
|
||||
from typing_extensions import Literal # type: ignore
|
||||
|
||||
import matplotlib as mpl # type: ignore
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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.")
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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":"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -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]
|
||||
|
|
@ -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"]:
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ use(\s+|(?P<intrinsic>\s*,\s*Intrinsic\s+::\s*))
|
|||
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
|
||||
)
|
||||
|
|
@ -320,7 +320,7 @@ def parseRoutine(inFile, logger):
|
|||
break
|
||||
routine["strippedCore"].append(subjline)
|
||||
subF.close()
|
||||
except:
|
||||
except Exception:
|
||||
import traceback
|
||||
|
||||
logger.debug(
|
||||
|
|
@ -484,7 +484,7 @@ def parseRoutine(inFile, logger):
|
|||
break
|
||||
routine["strippedCore"].append(subjline)
|
||||
subF.close()
|
||||
except:
|
||||
except Exception:
|
||||
import traceback
|
||||
|
||||
logger.debug(
|
||||
|
|
@ -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"]))
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ try:
|
|||
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).
|
||||
|
|
@ -255,7 +255,7 @@ class TestType:
|
|||
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])
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue