Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: update ruff and fix linting rules #624

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions deeprank2/tools/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ def add_target( # noqa: C901
1ATN_xxx-3 0
1ATN_xxx-4 0
"""
target_dict = {}

labels = np.loadtxt(target_list, delimiter=sep, usecols=[0], dtype=str)
values = np.loadtxt(target_list, delimiter=sep, usecols=[1])
for label, value in zip(labels, values, strict=True):
target_dict[label] = value
target_dict = dict(zip(labels, values, strict=False))

if os.path.isdir(graph_path):
graphs = glob.glob(f"{graph_path}/*.hdf5")
Expand Down
27 changes: 9 additions & 18 deletions deeprank2/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ def _precluster(self, dataset: GraphDataset) -> None:
f5.close()

def _put_model_to_device(self, dataset: GraphDataset | GridDataset) -> None:
"""
Puts the model on the available device.
"""Puts the model on the available device.

Args:
dataset (:class:`GraphDataset` | :class:`GridDataset`): GraphDataset object.
Expand Down Expand Up @@ -405,8 +404,7 @@ def configure_optimizers(
lr: float = 0.001,
weight_decay: float = 1e-05,
) -> None:
"""
Configure optimizer and its main parameters.
"""Configure optimizer and its main parameters.

Args:
optimizer (:class:`torch.optim`, optional): PyTorch optimizer object. If none, defaults to :class:`torch.optim.Adam`.
Expand Down Expand Up @@ -435,8 +433,7 @@ def set_lossfunction( # noqa: C901
lossfunction: nn.modules.loss._Loss | None = None,
override_invalid: bool = False,
) -> None:
"""
Set the loss function.
"""Set the loss function.

Args:
lossfunction (optional): Make sure to use a loss function that is appropriate for
Expand Down Expand Up @@ -524,8 +521,7 @@ def train( # noqa: PLR0915, C901
best_model: bool = True,
filename: str | None = "model.pth.tar",
) -> None:
"""
Performs the training of the model.
"""Performs the training of the model.

Args:
nepoch (int, optional): Maximum number of epochs to run.
Expand Down Expand Up @@ -685,8 +681,7 @@ def train( # noqa: PLR0915, C901
self.model.load_state_dict(self.model_load_state_dict)

def _epoch(self, epoch_number: int, pass_name: str) -> float | None:
"""
Runs a single epoch.
"""Runs a single epoch.

Args:
epoch_number (int): the current epoch number
Expand Down Expand Up @@ -751,8 +746,7 @@ def _eval(
epoch_number: int,
pass_name: str,
) -> float | None:
"""
Evaluates the model.
"""Evaluates the model.

Args:
loader (Dataloader): Data to evaluate on.
Expand Down Expand Up @@ -818,8 +812,7 @@ def _eval(

@staticmethod
def _log_epoch_data(stage: str, loss: float, time: float) -> None:
"""
Prints the data of each epoch.
"""Prints the data of each epoch.

Args:
stage (str): Train or valid.
Expand Down Expand Up @@ -863,8 +856,7 @@ def test(
batch_size: int = 32,
num_workers: int = 0,
) -> None:
"""
Performs the testing of the model.
"""Performs the testing of the model.

Args:
batch_size (int, optional): Sets the size of the batch.
Expand Down Expand Up @@ -935,8 +927,7 @@ def _load_params(self) -> None:
self.ngpu = state["ngpu"]

def _save_model(self) -> dict[str, Any]:
"""
Saves the model to a file.
"""Saves the model to a file.

Args:
filename (str, optional): Name of the file. Defaults to None.
Expand Down
8 changes: 1 addition & 7 deletions deeprank2/utils/parsing/residue.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def __init__(
absent_atom_names: list[str],
):
self.class_name = class_name

self.amino_acid_names = amino_acid_names

self.present_atom_names = present_atom_names
self.absent_atom_names = absent_atom_names

Expand All @@ -26,11 +24,7 @@ def matches(self, amino_acid_name: str, atom_names: list[str]) -> bool:
return False

# check the atom names that should be present
if not all(atom_name in atom_names for atom_name in self.present_atom_names):
return False

# all checks passed
return True
return all(atom_name in atom_names for atom_name in self.present_atom_names)


class ResidueClassParser: # noqa: D101
Expand Down
16 changes: 2 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ include = ["deeprank2*"]
addopts = "-ra"

[tool.ruff]
output-format = "concise"
line-length = 159

[tool.ruff.lint]
select = ["ALL"]
pydocstyle.convention = "google" # docstring settings
ignore = [
# Unrealistic for this code base
"PTH", # flake8-use-pathlib
Expand All @@ -117,20 +119,6 @@ ignore = [
"D104", # Missing public package docstring
"D105", # Missing docstring in magic method
"D107", # Missing docstring in `__init__`
# Docstring rules irrelevant to the Google style
"D203", # 1 blank line required before class docstring
"D204", # 1 blank line required after class docstring
"D212", # Multi-line docstring summary should start at the first line
"D213", # Multi-line docstring summary should start at the second line
"D215", # Section underline is over-indented
"D400", # First line should end with a period (clashes with D415:First line should end with a period, question mark, or exclamation point)
"D401", # First line of docstring should be in imperative mood
"D404", # First word of the docstring should not be This
"D406", # Section name should end with a newline
"D407", # Missing dashed underline after section
"D408", # Section underline should be in the line following the section's name
"D409", # Section underline should match the length of its name
"D413", # Missing blank line after last section
]

# Autofix settings
Expand Down
3 changes: 1 addition & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@


def test_cnn() -> None:
"""
Tests processing several PDB files into their features representation HDF5 file.
"""Tests processing several PDB files into their features representation HDF5 file.

Then uses HDF5 generated files to train and test a CnnRegression network.
"""
Expand Down
11 changes: 3 additions & 8 deletions tests/test_querycollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def _querycollection_tester(
cpu_count: int = 1,
combine_output: bool = True,
) -> tuple[QueryCollection, str, list[str]]:
"""
Generic function to test QueryCollection class.
"""Generic function to test QueryCollection class.

Args:
query_type (str): query type to be generated. It accepts only 'ppi' (ProteinProteinInterface) or 'srv' (SingleResidueVariant).
Expand Down Expand Up @@ -203,15 +202,11 @@ def test_querycollection_process_combine_output_true() -> None:
_, output_directory_f, output_paths_f = _querycollection_tester(query_type, feature_modules=modules, combine_output=False, cpu_count=2)
assert len(output_paths_t) == 1

keys_t = {}
with h5py.File(output_paths_t[0], "r") as file_t:
for key, value in file_t.items():
keys_t[key] = value
keys_f = {}
keys_t = dict(file_t.items())
for output_path in output_paths_f:
with h5py.File(output_path, "r") as file_f:
for key, value in file_f.items():
keys_f[key] = value
keys_f = dict(file_f.items())
assert keys_t == keys_f

rmtree(output_directory_t)
Expand Down
Loading