From c8b71d247e2fcc666ee8c3fae02f3d93f67be201 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Thu, 3 Feb 2022 09:20:41 +0900 Subject: [PATCH 1/3] fix [E401](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) --- export/fortran/c_to_f.py | 3 ++- export/fortran/make_defs.py | 3 ++- python/setup.py.in | 3 ++- tests/hartree-fock/hartree-fock++-validate.py | 5 ++++- tests/hartree-fock/hartree-fock-validate.py | 4 +++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/export/fortran/c_to_f.py b/export/fortran/c_to_f.py index afce043cd..81115ac23 100644 --- a/export/fortran/c_to_f.py +++ b/export/fortran/c_to_f.py @@ -8,7 +8,8 @@ c_to_f.py ''' -import re, sys +import re +import sys def extract_c_struct_fields(c_code, struct_name): struct_re = re.compile("^\s*typedef\s*struct\s*\{([^\}]*)\}\s*"+struct_name+"\s*;",re.MULTILINE | re.DOTALL) diff --git a/export/fortran/make_defs.py b/export/fortran/make_defs.py index 12ecfd176..55032f507 100644 --- a/export/fortran/make_defs.py +++ b/export/fortran/make_defs.py @@ -1,4 +1,5 @@ -import re, sys +import re +import sys f_in = open(sys.argv[1], 'r') f_out = open(sys.argv[2], 'w') for line in f_in: diff --git a/python/setup.py.in b/python/setup.py.in index 8f1b242e6..406f6218b 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -1,7 +1,8 @@ import setuptools from setuptools import setup, Extension from setuptools.command.build_ext import build_ext -import os, subprocess +import os +import subprocess # sources+tests os.sys.path.append("@PROJECT_SOURCE_DIR@") diff --git a/tests/hartree-fock/hartree-fock++-validate.py b/tests/hartree-fock/hartree-fock++-validate.py index d895a450e..96df5a467 100644 --- a/tests/hartree-fock/hartree-fock++-validate.py +++ b/tests/hartree-fock/hartree-fock++-validate.py @@ -1,5 +1,8 @@ from __future__ import print_function -import sys, re, math, os +import math +import os +import re +import sys def pat_numbers(n): result = '' diff --git a/tests/hartree-fock/hartree-fock-validate.py b/tests/hartree-fock/hartree-fock-validate.py index d771fb6b8..92aaefe93 100644 --- a/tests/hartree-fock/hartree-fock-validate.py +++ b/tests/hartree-fock/hartree-fock-validate.py @@ -1,5 +1,7 @@ from __future__ import print_function -import sys, re, math +import math +import re +import sys # first arg is the input file, if missing read sys.stdin try: From 539fe1aa9cc3562d40c577df4c24d66a1a26cc2f Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Thu, 3 Feb 2022 09:23:29 +0900 Subject: [PATCH 2/3] fix [W292](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) --- export/fortran/c_to_f.py | 2 +- tests/hartree-fock/hartree-fock-validate.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/export/fortran/c_to_f.py b/export/fortran/c_to_f.py index 81115ac23..d4e6d9917 100644 --- a/export/fortran/c_to_f.py +++ b/export/fortran/c_to_f.py @@ -78,4 +78,4 @@ def convert_type_c_to_f(dtype): f_out.write("end type\n") c_in.close() -f_out.close() \ No newline at end of file +f_out.close() diff --git a/tests/hartree-fock/hartree-fock-validate.py b/tests/hartree-fock/hartree-fock-validate.py index 92aaefe93..643176050 100644 --- a/tests/hartree-fock/hartree-fock-validate.py +++ b/tests/hartree-fock/hartree-fock-validate.py @@ -26,4 +26,4 @@ if len(sys.argv) > 1: instr.close() -sys.exit(returncode) \ No newline at end of file +sys.exit(returncode) From df8cb268ca7d32da3ede1de113e6da48461c9365 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Thu, 3 Feb 2022 09:17:28 +0900 Subject: [PATCH 3/3] fix [W605](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) --- export/fortran/c_to_f.py | 4 +-- tests/hartree-fock/hartree-fock++-validate.py | 32 +++++++++---------- tests/hartree-fock/hartree-fock-validate.py | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/export/fortran/c_to_f.py b/export/fortran/c_to_f.py index d4e6d9917..f724d14c7 100644 --- a/export/fortran/c_to_f.py +++ b/export/fortran/c_to_f.py @@ -12,7 +12,7 @@ import sys def extract_c_struct_fields(c_code, struct_name): - struct_re = re.compile("^\s*typedef\s*struct\s*\{([^\}]*)\}\s*"+struct_name+"\s*;",re.MULTILINE | re.DOTALL) + struct_re = re.compile(r"^\s*typedef\s*struct\s*\{([^\}]*)\}\s*"+struct_name+r"\s*;",re.MULTILINE | re.DOTALL) m = struct_re.search(c_code) if not m: return [] fields = m.group(1).splitlines() @@ -27,7 +27,7 @@ def parse_c_struct_fields(fields): for f in fields: words = f.split() var = words.pop() - m = re.match("(\w*)(?:\[(\w+)\])?", var) + m = re.match(r"(\w*)(?:\[(\w+)\])?", var) name.append(m.group(1)) size.append(m.group(2)) dtype.append(' '.join(words)) diff --git a/tests/hartree-fock/hartree-fock++-validate.py b/tests/hartree-fock/hartree-fock++-validate.py index 96df5a467..857e8fd13 100644 --- a/tests/hartree-fock/hartree-fock++-validate.py +++ b/tests/hartree-fock/hartree-fock++-validate.py @@ -7,7 +7,7 @@ def pat_numbers(n): result = '' for i in range(n): - result += '\s*([+-e\d.]+)' + result += r'\s*([+-e\d.]+)' return result def validate(label, data, refdata, tolerance, textline): @@ -110,21 +110,21 @@ def validate(label, data, refdata, tolerance, textline): Hok = False if LIBINT_ONEBODY_DERIV>1 and LIBINT_ERI_DERIV>1 else True for line in instr: - match1 = re.match('\*\* Hartree-Fock energy =' + pat_numbers(1), line) - match2 = re.match('\*\* edipole =' + pat_numbers(3), line) - match3 = re.match('\*\* equadrupole =' + pat_numbers(6), line) - match4 = re.match('\*\* 1-body forces =' + pat_numbers(9), line) - match5 = re.match('\*\* Pulay forces =' + pat_numbers(9), line) - match6 = re.match('\*\* 2-body forces =' + pat_numbers(9), line) - match7 = re.match('\*\* nuclear repulsion forces =' + pat_numbers(9), line) - match8 = re.match('\*\* Hartree-Fock forces =' + pat_numbers(9), line) - match9 = re.match('\*\* 1-body hessian =' + pat_numbers(45), line) - match10 = re.match('\*\* Pulay hessian =' + pat_numbers(45), line) - match11 = re.match('\*\* 2-body hessian =' + pat_numbers(45), line) - match12 = re.match('\*\* nuclear repulsion hessian =' + pat_numbers(45), line) - match13 = re.match('\*\* Hartree-Fock hessian =' + pat_numbers(45), line) - match14 = re.match('\*\* sph edipole =' + pat_numbers(3), line) - match15 = re.match('\*\* sph equadrupole =' + pat_numbers(5), line) + match1 = re.match(r'\*\* Hartree-Fock energy =' + pat_numbers(1), line) + match2 = re.match(r'\*\* edipole =' + pat_numbers(3), line) + match3 = re.match(r'\*\* equadrupole =' + pat_numbers(6), line) + match4 = re.match(r'\*\* 1-body forces =' + pat_numbers(9), line) + match5 = re.match(r'\*\* Pulay forces =' + pat_numbers(9), line) + match6 = re.match(r'\*\* 2-body forces =' + pat_numbers(9), line) + match7 = re.match(r'\*\* nuclear repulsion forces =' + pat_numbers(9), line) + match8 = re.match(r'\*\* Hartree-Fock forces =' + pat_numbers(9), line) + match9 = re.match(r'\*\* 1-body hessian =' + pat_numbers(45), line) + match10 = re.match(r'\*\* Pulay hessian =' + pat_numbers(45), line) + match11 = re.match(r'\*\* 2-body hessian =' + pat_numbers(45), line) + match12 = re.match(r'\*\* nuclear repulsion hessian =' + pat_numbers(45), line) + match13 = re.match(r'\*\* Hartree-Fock hessian =' + pat_numbers(45), line) + match14 = re.match(r'\*\* sph edipole =' + pat_numbers(3), line) + match15 = re.match(r'\*\* sph equadrupole =' + pat_numbers(5), line) if match1: eok = validate("HF energy", match1.groups(), eref, etol, line) elif match2: diff --git a/tests/hartree-fock/hartree-fock-validate.py b/tests/hartree-fock/hartree-fock-validate.py index 643176050..c89c9513d 100644 --- a/tests/hartree-fock/hartree-fock-validate.py +++ b/tests/hartree-fock/hartree-fock-validate.py @@ -16,7 +16,7 @@ returncode = 1 for line in instr: print(line,end="") - x = re.match('\*\* Hartree-Fock energy =\s*([-\d.]+)', line) + x = re.match(r'\*\* Hartree-Fock energy =\s*([-\d.]+)', line) if x: efound_str = x.group(1) if (math.fabs(eref - float(efound_str)) < tol):