mirror of
https://github.com/OpenFreeEnergy/openfe.git
synced 2026-06-04 14:14:22 +08:00
ruff: address pycodestyle changes (#1668)
* apply E741: ambiguous variable name check * apply E713: 'not in' fixes * address E721 with isintance() checks * fix bare excepts * precommit
This commit is contained in:
@@ -3,11 +3,11 @@ import logging
|
||||
|
||||
|
||||
def _mute_timeseries(record):
|
||||
return not "Warning on use of the timeseries module:" in record.msg
|
||||
return "Warning on use of the timeseries module:" not in record.msg
|
||||
|
||||
|
||||
def _mute_jax(record):
|
||||
return not "****** PyMBAR will use 64-bit JAX! *******" in record.msg
|
||||
return "****** PyMBAR will use 64-bit JAX! *******" not in record.msg
|
||||
|
||||
|
||||
_mbar_log = logging.getLogger("pymbar.timeseries")
|
||||
|
||||
@@ -727,7 +727,7 @@ class AbsoluteBindingProtocol(gufe.Protocol):
|
||||
lambda_components = [lambda_vdw, lambda_elec, lambda_restraints]
|
||||
it = iter(lambda_components)
|
||||
the_len = len(next(it))
|
||||
if not all(len(l) == the_len for l in it):
|
||||
if not all(len(lambda_comp) == the_len for lambda_comp in it):
|
||||
errmsg = (
|
||||
"Components elec, vdw, and restraints must have equal amount"
|
||||
f" of lambda windows. Got {len(lambda_elec)} elec lambda"
|
||||
|
||||
@@ -619,7 +619,7 @@ class AbsoluteSolvationProtocol(gufe.Protocol):
|
||||
lambda_components = [lambda_vdw, lambda_elec, lambda_restraints]
|
||||
it = iter(lambda_components)
|
||||
the_len = len(next(it))
|
||||
if not all(len(l) == the_len for l in it):
|
||||
if not all(len(lambda_comp) == the_len for lambda_comp in it):
|
||||
errmsg = (
|
||||
"Components elec, vdw, and restraints must have equal amount"
|
||||
f" of lambda windows. Got {len(lambda_elec)} elec lambda"
|
||||
|
||||
@@ -103,9 +103,9 @@ class LambdaProtocol(object):
|
||||
else:
|
||||
self.lambda_schedule = np.linspace(0., 1., windows)
|
||||
|
||||
if type(self.functions) == dict:
|
||||
if isinstance(self.functions, dict):
|
||||
self.type = 'user-defined'
|
||||
elif type(self.functions) == str:
|
||||
elif isinstance(self.functions, str):
|
||||
self.functions = None # will be set later
|
||||
self.type = functions
|
||||
|
||||
|
||||
@@ -406,8 +406,8 @@ def load_orion_network(
|
||||
|
||||
with open(network_file, "r") as f:
|
||||
network_lines = [
|
||||
l.strip().split(" ") for l in f
|
||||
if not l.startswith("#")
|
||||
line.strip().split(" ") for line in f
|
||||
if not line.startswith("#")
|
||||
] # fmt: skip
|
||||
|
||||
names = []
|
||||
@@ -451,7 +451,7 @@ def load_fepplus_network(
|
||||
"""
|
||||
|
||||
with open(network_file, "r") as f:
|
||||
network_lines = [l.split() for l in f.readlines()]
|
||||
network_lines = [line.split() for line in f.readlines()]
|
||||
|
||||
names = []
|
||||
for entry in network_lines:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# For details, see https://github.com/OpenFreeEnergy/openfe
|
||||
import os
|
||||
import pathlib
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from importlib import resources
|
||||
|
||||
@@ -361,7 +362,7 @@ def am1bcc_ref_charges():
|
||||
|
||||
try:
|
||||
urllib.request.urlopen("https://www.google.com")
|
||||
except: # -no-cov-
|
||||
except urllib.error.URLError: # -no-cov-
|
||||
HAS_INTERNET = False
|
||||
else:
|
||||
HAS_INTERNET = True
|
||||
|
||||
@@ -691,7 +691,7 @@ def test_network_from_external(file_fixture, loader, request, benzene_modificati
|
||||
network_file = request.getfixturevalue(file_fixture)
|
||||
|
||||
network = loader(
|
||||
ligands=[l for l in benzene_modifications.values()],
|
||||
ligands=[lig for lig in benzene_modifications.values()],
|
||||
mapper=openfe.LomapAtomMapper(),
|
||||
network_file=network_file,
|
||||
)
|
||||
@@ -721,7 +721,7 @@ def test_network_from_external(file_fixture, loader, request, benzene_modificati
|
||||
)
|
||||
def test_network_from_external_unknown_edge(file_fixture, loader, request, benzene_modifications):
|
||||
network_file = request.getfixturevalue(file_fixture)
|
||||
ligands = [l for l in benzene_modifications.values() if l.name != "phenol"]
|
||||
ligands = [lig for lig in benzene_modifications.values() if lig.name != "phenol"]
|
||||
|
||||
with pytest.raises(KeyError, match="Invalid name"):
|
||||
_ = loader(
|
||||
@@ -750,7 +750,7 @@ def test_bad_orion_network(benzene_modifications, tmpdir):
|
||||
|
||||
with pytest.raises(KeyError, match="line does not match"):
|
||||
_ = openfe.setup.ligand_network_planning.load_orion_network(
|
||||
ligands=[l for l in benzene_modifications.values()],
|
||||
ligands=[lig for lig in benzene_modifications.values()],
|
||||
mapper=openfe.LomapAtomMapper(),
|
||||
network_file="bad_orion_net.dat",
|
||||
)
|
||||
@@ -773,7 +773,7 @@ def test_bad_edges_network(benzene_modifications, tmpdir):
|
||||
|
||||
with pytest.raises(KeyError, match="line does not match"):
|
||||
_ = openfe.setup.ligand_network_planning.load_fepplus_network(
|
||||
ligands=[l for l in benzene_modifications.values()],
|
||||
ligands=[lig for lig in benzene_modifications.values()],
|
||||
mapper=openfe.LomapAtomMapper(),
|
||||
network_file="bad_edges.edges",
|
||||
)
|
||||
|
||||
@@ -17,4 +17,4 @@ class MsgIncludesStringFilter:
|
||||
self.string = string
|
||||
|
||||
def filter(self, record):
|
||||
return not self.string in record.msg
|
||||
return self.string not in record.msg
|
||||
|
||||
@@ -513,7 +513,7 @@ def log_system_probe(level=logging.DEBUG, paths: Optional[Iterable[os.PathLike]]
|
||||
gpu = logging.getLogger(basename + ".gpu")
|
||||
hostname = logging.getLogger(basename + ".hostname")
|
||||
loggers = [base, gpu, hostname]
|
||||
if any(l.isEnabledFor(level) for l in loggers):
|
||||
if any(logger.isEnabledFor(level) for logger in loggers):
|
||||
sysinfo = _probe_system(pl_paths)["system information"]
|
||||
base.log(level, "SYSTEM CONFIG DETAILS:")
|
||||
hostname.log(level, f"hostname: '{sysinfo['hostname']}'")
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
try:
|
||||
urllib.request.urlopen("https://www.google.com")
|
||||
except: # -no-cov-
|
||||
except urllib.error.URLError: # -no-cov-
|
||||
HAS_INTERNET = False
|
||||
else:
|
||||
HAS_INTERNET = True
|
||||
|
||||
@@ -58,15 +58,15 @@ def _should_configure_logger(logger: logging.Logger):
|
||||
return False
|
||||
|
||||
# walk up the logging tree to see if any parent loggers are not default
|
||||
l = logger
|
||||
_logger = logger
|
||||
while (
|
||||
l.parent is not None # not the root logger
|
||||
and l.level == logging.NOTSET # level not already set
|
||||
and l.propagate # configured to use parent when not set
|
||||
_logger.parent is not None # not the root logger
|
||||
and _logger.level == logging.NOTSET # level not already set
|
||||
and _logger.propagate # configured to use parent when not set
|
||||
):
|
||||
l = l.parent
|
||||
_logger = _logger.parent
|
||||
|
||||
is_default = (l == logging.root and l.level == logging.WARNING) # fmt: skip
|
||||
is_default = (_logger == logging.root and _logger.level == logging.WARNING) # fmt: skip
|
||||
|
||||
return is_default
|
||||
|
||||
|
||||
@@ -52,17 +52,16 @@ line-length = 100
|
||||
|
||||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||
lint.select = [
|
||||
"E", # pycodestyle errors
|
||||
"F", # Pyflakes
|
||||
"I", # isort
|
||||
"W", # pycodestyle warnings
|
||||
# "E", # pycodestyle errors
|
||||
# "C901" # mccabe complexity TODO: add this back in
|
||||
# "UP", # TODO: add this in
|
||||
]
|
||||
lint.ignore = [
|
||||
"E402", # module-level import not at top (conflicts w/ isort)
|
||||
"E722", # bare excepts (TODO: we should fix these in a follow-up PR)
|
||||
"E731", # lambda expressions (TODO: we should fix these)
|
||||
"E501", # line length too long, resolve this for comments
|
||||
"F401", # unused imports (TODO: we should fix these)
|
||||
"F811",
|
||||
"F841",
|
||||
|
||||
Reference in New Issue
Block a user