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):
|
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):
|
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")
|
_mbar_log = logging.getLogger("pymbar.timeseries")
|
||||||
|
|||||||
@@ -727,7 +727,7 @@ class AbsoluteBindingProtocol(gufe.Protocol):
|
|||||||
lambda_components = [lambda_vdw, lambda_elec, lambda_restraints]
|
lambda_components = [lambda_vdw, lambda_elec, lambda_restraints]
|
||||||
it = iter(lambda_components)
|
it = iter(lambda_components)
|
||||||
the_len = len(next(it))
|
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 = (
|
errmsg = (
|
||||||
"Components elec, vdw, and restraints must have equal amount"
|
"Components elec, vdw, and restraints must have equal amount"
|
||||||
f" of lambda windows. Got {len(lambda_elec)} elec lambda"
|
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]
|
lambda_components = [lambda_vdw, lambda_elec, lambda_restraints]
|
||||||
it = iter(lambda_components)
|
it = iter(lambda_components)
|
||||||
the_len = len(next(it))
|
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 = (
|
errmsg = (
|
||||||
"Components elec, vdw, and restraints must have equal amount"
|
"Components elec, vdw, and restraints must have equal amount"
|
||||||
f" of lambda windows. Got {len(lambda_elec)} elec lambda"
|
f" of lambda windows. Got {len(lambda_elec)} elec lambda"
|
||||||
|
|||||||
@@ -103,9 +103,9 @@ class LambdaProtocol(object):
|
|||||||
else:
|
else:
|
||||||
self.lambda_schedule = np.linspace(0., 1., windows)
|
self.lambda_schedule = np.linspace(0., 1., windows)
|
||||||
|
|
||||||
if type(self.functions) == dict:
|
if isinstance(self.functions, dict):
|
||||||
self.type = 'user-defined'
|
self.type = 'user-defined'
|
||||||
elif type(self.functions) == str:
|
elif isinstance(self.functions, str):
|
||||||
self.functions = None # will be set later
|
self.functions = None # will be set later
|
||||||
self.type = functions
|
self.type = functions
|
||||||
|
|
||||||
|
|||||||
@@ -406,8 +406,8 @@ def load_orion_network(
|
|||||||
|
|
||||||
with open(network_file, "r") as f:
|
with open(network_file, "r") as f:
|
||||||
network_lines = [
|
network_lines = [
|
||||||
l.strip().split(" ") for l in f
|
line.strip().split(" ") for line in f
|
||||||
if not l.startswith("#")
|
if not line.startswith("#")
|
||||||
] # fmt: skip
|
] # fmt: skip
|
||||||
|
|
||||||
names = []
|
names = []
|
||||||
@@ -451,7 +451,7 @@ def load_fepplus_network(
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
with open(network_file, "r") as f:
|
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 = []
|
names = []
|
||||||
for entry in network_lines:
|
for entry in network_lines:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# For details, see https://github.com/OpenFreeEnergy/openfe
|
# For details, see https://github.com/OpenFreeEnergy/openfe
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from importlib import resources
|
from importlib import resources
|
||||||
|
|
||||||
@@ -361,7 +362,7 @@ def am1bcc_ref_charges():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
urllib.request.urlopen("https://www.google.com")
|
urllib.request.urlopen("https://www.google.com")
|
||||||
except: # -no-cov-
|
except urllib.error.URLError: # -no-cov-
|
||||||
HAS_INTERNET = False
|
HAS_INTERNET = False
|
||||||
else:
|
else:
|
||||||
HAS_INTERNET = True
|
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_file = request.getfixturevalue(file_fixture)
|
||||||
|
|
||||||
network = loader(
|
network = loader(
|
||||||
ligands=[l for l in benzene_modifications.values()],
|
ligands=[lig for lig in benzene_modifications.values()],
|
||||||
mapper=openfe.LomapAtomMapper(),
|
mapper=openfe.LomapAtomMapper(),
|
||||||
network_file=network_file,
|
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):
|
def test_network_from_external_unknown_edge(file_fixture, loader, request, benzene_modifications):
|
||||||
network_file = request.getfixturevalue(file_fixture)
|
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"):
|
with pytest.raises(KeyError, match="Invalid name"):
|
||||||
_ = loader(
|
_ = loader(
|
||||||
@@ -750,7 +750,7 @@ def test_bad_orion_network(benzene_modifications, tmpdir):
|
|||||||
|
|
||||||
with pytest.raises(KeyError, match="line does not match"):
|
with pytest.raises(KeyError, match="line does not match"):
|
||||||
_ = openfe.setup.ligand_network_planning.load_orion_network(
|
_ = 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(),
|
mapper=openfe.LomapAtomMapper(),
|
||||||
network_file="bad_orion_net.dat",
|
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"):
|
with pytest.raises(KeyError, match="line does not match"):
|
||||||
_ = openfe.setup.ligand_network_planning.load_fepplus_network(
|
_ = 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(),
|
mapper=openfe.LomapAtomMapper(),
|
||||||
network_file="bad_edges.edges",
|
network_file="bad_edges.edges",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ class MsgIncludesStringFilter:
|
|||||||
self.string = string
|
self.string = string
|
||||||
|
|
||||||
def filter(self, record):
|
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")
|
gpu = logging.getLogger(basename + ".gpu")
|
||||||
hostname = logging.getLogger(basename + ".hostname")
|
hostname = logging.getLogger(basename + ".hostname")
|
||||||
loggers = [base, gpu, 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"]
|
sysinfo = _probe_system(pl_paths)["system information"]
|
||||||
base.log(level, "SYSTEM CONFIG DETAILS:")
|
base.log(level, "SYSTEM CONFIG DETAILS:")
|
||||||
hostname.log(level, f"hostname: '{sysinfo['hostname']}'")
|
hostname.log(level, f"hostname: '{sysinfo['hostname']}'")
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urllib.request.urlopen("https://www.google.com")
|
urllib.request.urlopen("https://www.google.com")
|
||||||
except: # -no-cov-
|
except urllib.error.URLError: # -no-cov-
|
||||||
HAS_INTERNET = False
|
HAS_INTERNET = False
|
||||||
else:
|
else:
|
||||||
HAS_INTERNET = True
|
HAS_INTERNET = True
|
||||||
|
|||||||
@@ -58,15 +58,15 @@ def _should_configure_logger(logger: logging.Logger):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# walk up the logging tree to see if any parent loggers are not default
|
# walk up the logging tree to see if any parent loggers are not default
|
||||||
l = logger
|
_logger = logger
|
||||||
while (
|
while (
|
||||||
l.parent is not None # not the root logger
|
_logger.parent is not None # not the root logger
|
||||||
and l.level == logging.NOTSET # level not already set
|
and _logger.level == logging.NOTSET # level not already set
|
||||||
and l.propagate # configured to use parent when not 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
|
return is_default
|
||||||
|
|
||||||
|
|||||||
@@ -52,17 +52,16 @@ line-length = 100
|
|||||||
|
|
||||||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||||
lint.select = [
|
lint.select = [
|
||||||
|
"E", # pycodestyle errors
|
||||||
"F", # Pyflakes
|
"F", # Pyflakes
|
||||||
"I", # isort
|
"I", # isort
|
||||||
"W", # pycodestyle warnings
|
"W", # pycodestyle warnings
|
||||||
# "E", # pycodestyle errors
|
|
||||||
# "C901" # mccabe complexity TODO: add this back in
|
# "C901" # mccabe complexity TODO: add this back in
|
||||||
# "UP", # TODO: add this in
|
# "UP", # TODO: add this in
|
||||||
]
|
]
|
||||||
lint.ignore = [
|
lint.ignore = [
|
||||||
"E402", # module-level import not at top (conflicts w/ isort)
|
"E402", # module-level import not at top (conflicts w/ isort)
|
||||||
"E722", # bare excepts (TODO: we should fix these in a follow-up PR)
|
"E501", # line length too long, resolve this for comments
|
||||||
"E731", # lambda expressions (TODO: we should fix these)
|
|
||||||
"F401", # unused imports (TODO: we should fix these)
|
"F401", # unused imports (TODO: we should fix these)
|
||||||
"F811",
|
"F811",
|
||||||
"F841",
|
"F841",
|
||||||
|
|||||||
Reference in New Issue
Block a user