Skip to content

Commit

Permalink
Merge #3203
Browse files Browse the repository at this point in the history
3203: Code cleanup with pylint r=KaiSzuttor a=jngrad

Follow-up to #3194

Description of changes:
- remove unused imports
- rewrite wildcard imports as explicit imports
- replace mutable optional parameters by immutable equivalents
- fix LB thermostat checkpointing mechanism
- cleanup and simplify conditional statements
- refactor code with numpy and new espresso methods
- remove unused variables/arguments
- rename unused loop variables from `i` to `_`
- fix broken numpy commands in parts of the testsuite that aren't executed
- remove trailling whitespaces


Co-authored-by: Jean-Noël Grad <[email protected]>
Co-authored-by: Kai Szuttor <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2019
2 parents 8e549ad + 1ef1aeb commit 021af38
Show file tree
Hide file tree
Showing 90 changed files with 299 additions and 398 deletions.
12 changes: 6 additions & 6 deletions maintainer/CI/dox_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
# filter out non-critical warnings
warnings = {}
for (filepath, lineno, warning), warning_list in raw_warnings.items():
if re.search('^member \S+ belongs to two different groups\. '
'The second one found here will be ignored\.$', warning):
if re.search(r'^member \S+ belongs to two different groups\. '
r'The second one found here will be ignored\.$', warning):
# happens when a function is declared in a group in the .hpp file but
# defined in another group in the .cpp file; this is usually caused by
# the "Private functions" and "Exported functions" groups in .hpp files
continue
if re.search(
'^documented symbol `\S+\' was not declared or defined\.$', warning):
if re.search(r'^documented symbol `\S+\' was not declared or defined\.$',
warning):
# known bug, fixed in 1.8.16
continue
if re.search('^no uniquely matching class member found for $', warning):
Expand All @@ -75,7 +75,7 @@
# warning, when in reality the warning is silenced because the text on
# the following line is captured and becomes the argument description
continue
filepath = re.sub('^.*(?=src/)', '', filepath)
filepath = re.sub(r'^.*(?=src/)', '', filepath)
if filepath not in warnings:
warnings[filepath] = {}
warnings[filepath][(lineno, warning)] = warning_list
Expand All @@ -94,7 +94,7 @@
f.write(filepath + ':\n')
for (lineno, warning) in sorted(warnings[filepath].keys()):
warning_list = warnings[filepath][(lineno, warning)]
s = re.sub('\(.*\)', '()', warning)
s = re.sub(r'\(.*\)', '()', warning)
if warning_list:
s += ': ' + ', '.join(x.strip() for x in warning_list)
f.write(' line {}: {}\n'.format(lineno, s))
Expand Down
1 change: 0 additions & 1 deletion maintainer/benchmarks/lj.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@


import espressomd
from espressomd import thermostat
if args.visualizer:
from espressomd import visualization
from threading import Thread
Expand Down
4 changes: 1 addition & 3 deletions maintainer/benchmarks/p3m.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@


import espressomd
from espressomd import thermostat
from espressomd import electrostatics
if args.visualizer:
from espressomd import visualization
from threading import Thread

required_features = ["P3M", "LENNARD_JONES", "MASS"]
espressomd.assert_features(required_features)
Expand Down Expand Up @@ -101,7 +99,7 @@
# Integration parameters
#############################################################
system.time_step = 0.01
system.cell_system.skin = .4
system.cell_system.skin = .4
system.thermostat.turn_off()


Expand Down
1 change: 0 additions & 1 deletion maintainer/gh_post_docs_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import os
import sys
import requests
import subprocess

if not os.environ['CI_COMMIT_REF_NAME'].startswith('PR-'):
exit(0)
Expand Down
2 changes: 1 addition & 1 deletion maintainer/gh_post_style_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@
comment += 'You can run `gitlab-runner exec docker style` afterwards to check if your changes worked out properly.\n\n'
comment += 'Please note that there are often multiple ways to correctly format code. As I am just a robot, I sometimes fail to identify the most aesthetically pleasing way. So please look over my suggested changes and adapt them where the style does not make sense.'

if len(patch) > 0:
if patch:
requests.post(URL, json={'body': comment})
7 changes: 3 additions & 4 deletions maintainer/git2changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import string
import re
import os

Expand Down Expand Up @@ -52,14 +51,14 @@
continue

# Match the author line and extract the part we want
m = re.match('^Author:\s*(.*)\s*$', line)
m = re.match(r'^Author:\s*(.*)\s*$', line)
if m is not None:
author = m.group(1)
authorFound = True
continue

# Match the date line
m = re.match('^Date:\s*(.*)\s*$', line)
m = re.match(r'^Date:\s*(.*)\s*$', line)
if m is not None:
date = m.group(1)
dateFound = True
Expand Down Expand Up @@ -92,7 +91,7 @@
continue
# Collect the files for this commit. FIXME: Still need to add +/- to files
elif authorFound & dateFound & messageFound:
fileList = re.split(' \| ', line, 2)
fileList = re.split(r' \| ', line, 2)
if len(fileList) > 1:
if files:
files = files + ", " + fileList[0].strip()
Expand Down
5 changes: 3 additions & 2 deletions src/config/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

class Defines:

def __init__(self, compiler, flags=[]):
def __init__(self, compiler, flags=()):
self._compiler = compiler
self._flags = flags + ["-E", "-dM"]
assert isinstance(flags, (list, tuple))
self._flags = list(flags) + ["-E", "-dM"]

build_in = self._build_in_defs()
self._buildin = set(build_in)
Expand Down
5 changes: 2 additions & 3 deletions src/config/featuredefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
# This module parses the feature definition file features.def
#
import fileinput
import string
import re


class SyntaxError:
class SyntaxError(Exception):

def __init__(self, message, instead):
self.message = message
Expand Down Expand Up @@ -171,7 +170,7 @@ def check_validity(self, activated):
for feature in allfeatures:
featurevars[feature] = feature in newset

for feature, expr, undef in self.requirements:
for feature, expr, _ in self.requirements:
# print 'Requirement: ', feature, ' -> ', expr
if feature in newset:
if not eval(expr, featurevars):
Expand Down
2 changes: 0 additions & 2 deletions src/config/gen_sampleconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# This script appends the sample list of features to the file
# myconfig-sample.h.
#
import time
import string
import fileinput
import inspect
import sys
Expand Down
10 changes: 5 additions & 5 deletions src/python/espressomd/MDA_ESP/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ def _read_first_frame(self):
with util.openany(self.filename, 'rt') as espfile:
n_atoms = 1
for pos, line in enumerate(espfile, start=-3):
if (pos == -3):
if pos == -3:
time = float(line[1:-1])
elif(pos == -2):
elif pos == -2:
n_atoms = int(line)
self.n_atoms = n_atoms
positions = np.zeros(
Expand All @@ -224,13 +224,13 @@ def _read_first_frame(self):
self.ts = ts = self._Timestep(
self.n_atoms, **self._ts_kwargs)
self.ts.time = time
elif(pos == -1):
elif pos == -1:
self.ts._unitcell[:3] = np.array(
list(map(float, line[1:-2].split())))
elif(pos < n_atoms):
elif pos < n_atoms:
positions[pos] = np.array(
list(map(float, line[1:-2].split())))
elif(pos < 2 * n_atoms):
elif pos < 2 * n_atoms:
velocities[pos - n_atoms] = np.array(
list(map(float, line[1:-2].split())))
else:
Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/accumulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ def result(self):
-------
numpy.ndarray
The result of the correlation function as a 2d-array.
The result of the correlation function as a 2d-array.
The first column contains the values of the lag time tau.
The second column contains the number of values used to
perform the averaging of the correlation. Further columns contain
perform the averaging of the correlation. Further columns contain
the values of the correlation function. The number of these columns
is the dimension of the output of the correlation operation.
"""
Expand Down
2 changes: 0 additions & 2 deletions src/python/espressomd/checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from collections import OrderedDict
import sys
import inspect
import os
import re
Expand Down Expand Up @@ -97,7 +96,6 @@ def __setattr_submodule(self, obj, name, value):
"""
names = name.split('.')
tmp_obj = obj
for i in range(len(names) - 1):
obj = getattr(obj, names[i], None)

Expand Down
1 change: 0 additions & 1 deletion src/python/espressomd/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .script_interface import ScriptObjectRegistry, ScriptInterfaceHelper, script_interface_register
from espressomd.utils import is_valid_type
import numpy as np
from itertools import product

Expand Down
2 changes: 1 addition & 1 deletion src/python/espressomd/ekboundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .script_interface import ScriptInterfaceHelper, script_interface_register
from .script_interface import script_interface_register
from .__init__ import has_features
import espressomd.lbboundaries

Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/io/writer/vtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def vtf_pid_map(system, types='all'):
id_to_write = []
for p in system.part:
for t in types:
if p.type == t or t == "all":
if t in (p.type, "all"):
id_to_write.append(p.id)
return dict(zip(id_to_write, range(len(id_to_write))))

Expand Down Expand Up @@ -70,7 +70,7 @@ def writevsf(system, fp, types='all'):
system.part[pid].type))
for pid, vtf_id, in vtf_index.items():
for b in system.part[pid].bonds:
if (system.part[b[1]].id in vtf_index):
if system.part[b[1]].id in vtf_index:
fp.write("bond {}:{}\n".format(
vtf_id, vtf_index[system.part[b[1]].id]))

Expand Down
41 changes: 12 additions & 29 deletions src/python/object_in_fluid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,15 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .oif_classes import \
FixedPoint, \
PartPoint, \
Edge, \
Triangle, \
Angle, \
ThreeNeighbors, \
Mesh, \
OifCellType,\
OifCell

from .oif_utils import \
custom_str, \
get_triangle_normal, \
norm, \
vec_distance, \
area_triangle, \
angle_btw_triangles, \
discard_epsilon, \
oif_neo_hookean_nonlin, \
oif_calc_stretching_force, \
oif_calc_linear_stretching_force, \
oif_calc_bending_force, \
oif_calc_local_area_force, \
oif_calc_global_area_force, \
oif_calc_volume_force, \
output_vtk_rhomboid, \
output_vtk_cylinder, \
output_vtk_lines
from .oif_classes import (
FixedPoint, PartPoint, Edge, Triangle, Angle, ThreeNeighbors, Mesh,
OifCellType, OifCell
)
from .oif_utils import (
custom_str, get_triangle_normal, norm, vec_distance, area_triangle,
angle_btw_triangles, discard_epsilon, oif_neo_hookean_nonlin,
oif_calc_stretching_force, oif_calc_linear_stretching_force,
oif_calc_bending_force, oif_calc_local_area_force,
oif_calc_global_area_force, oif_calc_volume_force, output_vtk_rhomboid,
output_vtk_cylinder, output_vtk_lines
)
Loading

0 comments on commit 021af38

Please sign in to comment.