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

style: update ruff #584

Merged
merged 5 commits into from
Mar 4, 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
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ jobs:
python-version: ${{ matrix.python-version }}
extras-require: test
- name: Check style against standards using ruff
run: ruff .
run: ruff check .
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
},
"notebook.diff.ignoreMetadata": true,

// Pytest
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,

// Format all files on save
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You want to make some kind of change to the code base
#. if needed, fork the repository to your own Github profile and create your own feature branch off of the latest main commit. While working on your feature branch, make sure to stay up to date with the main branch by pulling in changes, possibly from the 'upstream' repository (follow the instructions `here <https://help.github.com/articles/configuring-a-remote-for-a-fork/>`__ and `here <https://help.github.com/articles/syncing-a-fork/>`__);
#. make sure the existing tests still work by running ``python setup.py test``;
#. add your own tests (if necessary);
#. ensure the code is correctly linted (``ruff .``) and formatted (``ruff format .``);
#. ensure the code is correctly linted (``ruff check.``) and formatted (``ruff format .``);
#. see our `developer's readme <README.dev.md>`_ for detailed information on our style conventions, etc.;
#. update or expand the documentation;
#. `push <http://rogerdudler.github.io/git-guide/>`_ your feature branch to (your fork of) the DeepRank2 repository on GitHub;
Expand Down
2 changes: 1 addition & 1 deletion README.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ We use [ruff](https://docs.astral.sh/ruff/) for linting, sorting imports and for

If you are using VS code, please install and activate the [Ruff extension](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) to automatically format and check linting.

Otherwise, please ensure check both linting (`ruff fix .`) and formatting (`ruff format .`) before requesting a review.
Otherwise, please ensure check both linting (`ruff check .`) and formatting (`ruff format .`) before requesting a review.

We use [prettier](https://prettier.io/) for formatting most other files. If you are editing or adding non-python files and using VS code, the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) can be installed to auto-format these files as well.

Expand Down
2 changes: 1 addition & 1 deletion deeprank2/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from deeprank2.utils.earlystopping import EarlyStopping
from deeprank2.utils.exporters import HDF5OutputExporter, OutputExporter, OutputExporterCollection

# ruff: noqa: PYI041 (redundant-numeric-union), they are used differently in this module
# ruff: noqa: PYI041 (usage depends on type in this module)
_log = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion deeprank2/utils/community_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from torch_geometric.nn.pool.pool import pool_batch, pool_edge
from torch_scatter import scatter_max, scatter_mean

# ruff: noqa: ANN001, ANN201 (missing type hints and return types)
# ruff: noqa: ANN001, ANN201


def plot_graph(graph, cluster) -> None: # noqa:D103
Expand Down
2 changes: 1 addition & 1 deletion env/deeprank2-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies:
- freesasa>=2.1.0
- tensorboard>=0.9.0
- protobuf>=3.20.1
- ruff>=0.1.13
- ruff>=0.3.0
- dill>=0.3.8
- pyarrow>=15.0.0
- pip:
Expand Down
2 changes: 1 addition & 1 deletion env/deeprank2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ dependencies:
- freesasa>=2.1.0
- tensorboard>=0.9.0
- protobuf>=3.20.1
- ruff>=0.1.13
- ruff>=0.3.0
- dill>=0.3.8
- pyarrow>=15.0.0
32 changes: 16 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ exclude = ["tests*", "*tests.*", "*tests"]

[tool.ruff]
line-length = 159

[tool.ruff.lint]
select = ["ALL"]
ignore = [
# Unrealistic for this code base
Expand Down Expand Up @@ -105,22 +107,9 @@ ignore = [
"D413", # Missing blank line after last section
]

# Allow autofix for all enabled rules.
# Autofix settings
fixable = ["ALL"]
unfixable = ["F401"] # unused imports (should not disappear while editing)

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"S101", # Use of `assert` detected
"PLR2004", # Magic value used in comparison
"D101", # Missing class docstring
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
]
"docs/*" = ["ALL"]
"tests/perf/*" = ["T201"] # Use of print statements

[tool.ruff.lint]
extend-safe-fixes = [
"D415", # First line should end with a period, question mark, or exclamation point
"D300", # Use triple double quotes `"""`
Expand All @@ -132,5 +121,16 @@ extend-safe-fixes = [
"B006", # Mutable default argument
]

[tool.ruff.isort]
known-first-party = ["deeprank2"]
isort.known-first-party = ["deeprank2"]

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"S101", # Use of `assert` detected
"PLR2004", # Magic value used in comparison
"D101", # Missing class docstring
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"SLF001", # private member access
]
"docs/*" = ["ALL"]
"tests/perf/*" = ["T201"] # Use of print statements
2 changes: 1 addition & 1 deletion tests/domain/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_atomic_forcefield() -> None:
try:
structure = get_structure(pdb, "101M")
finally:
pdb._close() # noqa: SLF001
pdb._close()

# The arginine C-zeta should get a positive charge
arg = next(r for r in structure.get_chain("A").residues if r.amino_acid == arginine)
Expand Down
2 changes: 1 addition & 1 deletion tests/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def build_testgraph( # noqa: C901
try:
structure: PDBStructure = get_structure(pdb, Path(pdb_path).stem)
finally:
pdb._close() # noqa: SLF001
pdb._close()

if not central_res:
nodes = set()
Expand Down
2 changes: 1 addition & 1 deletion tests/features/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _get_contact(
try:
structure = get_structure(pdb, pdb_id)
finally:
pdb._close() # noqa: SLF001
pdb._close()

if not chains:
chains = [structure.chains[0], structure.chains[0]]
Expand Down
2 changes: 1 addition & 1 deletion tests/molstruct/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _get_structure(path: str) -> PDBStructure:
try:
structure = get_structure(pdb, "101M")
finally:
pdb._close() # noqa: SLF001
pdb._close()

assert structure is not None

Expand Down
2 changes: 1 addition & 1 deletion tests/perf/ppi_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
os.makedirs(os.path.join(processed_data_path, "atomic"))


def get_pdb_files_and_target_data(data_path: str) -> (list[str], list):
def get_pdb_files_and_target_data(data_path: str) -> tuple[list[str], list]:
csv_data = pd.read_csv(os.path.join(data_path, "BA_values.csv"))
pdb_files = glob.glob(os.path.join(data_path, "pdb", "*.pdb"))
pdb_files.sort()
Expand Down
2 changes: 1 addition & 1 deletion tests/perf/srv_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
os.makedirs(os.path.join(processed_data_path, "atomic"))


def get_pdb_files_and_target_data(data_path: str) -> (list[str], list, list, list, list):
def get_pdb_files_and_target_data(data_path: str) -> tuple[list[str], list, list, list, list]:
csv_data = pd.read_csv(os.path.join(data_path, "srv_target_values.csv"))
# before running this script change .ent to .pdb
pdb_files = glob.glob(os.path.join(data_path, "pdb", "*.pdb"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _compute_features_manually(
hdf5_path: str,
features_transform: dict,
feat: str,
) -> (NDArray, float, float):
) -> tuple[NDArray, float, float]:
"""Return specified feature.

This function returns the feature specified read from the hdf5 file, after applying manually features_transform dict.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_querycollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _querycollection_tester(
feature_modules: ModuleType | list[ModuleType] | None = None,
cpu_count: int = 1,
combine_output: bool = True,
) -> (QueryCollection, str, list[str]):
) -> tuple[QueryCollection, str, list[str]]:
"""
Generic function to test QueryCollection class.

Expand Down Expand Up @@ -279,6 +279,6 @@ def test_querycollection_duplicates_add() -> None:
"1ATN_2w_2",
"1ATN_3w",
]
assert queries._ids_count["residue-ppi:A-B:1ATN_1w"] == 3 # noqa: SLF001
assert queries._ids_count["residue-ppi:A-B:1ATN_2w"] == 2 # noqa: SLF001
assert queries._ids_count["residue-ppi:A-B:1ATN_3w"] == 1 # noqa: SLF001
assert queries._ids_count["residue-ppi:A-B:1ATN_1w"] == 3
assert queries._ids_count["residue-ppi:A-B:1ATN_2w"] == 2
assert queries._ids_count["residue-ppi:A-B:1ATN_3w"] == 1
8 changes: 4 additions & 4 deletions tests/utils/test_buildgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_get_structure_complete() -> None:
try:
structure = get_structure(pdb, "101M")
finally:
pdb._close() # noqa: SLF001
pdb._close()

assert structure is not None

Expand Down Expand Up @@ -40,7 +40,7 @@ def test_get_structure_from_nmr_with_dna() -> None:
try:
structure = get_structure(pdb, "101M")
finally:
pdb._close() # noqa: SLF001
pdb._close()

assert structure is not None
assert structure.chains[0].residues[0].amino_acid is None # DNA
Expand All @@ -52,7 +52,7 @@ def test_residue_contact_pairs() -> None:
try:
structure = get_structure(pdb, "1ATN")
finally:
pdb._close() # noqa: SLF001
pdb._close()
residue_pairs = get_residue_contact_pairs(pdb_path, structure, "A", "B", 8.5)

assert len(residue_pairs) > 0
Expand All @@ -64,7 +64,7 @@ def test_surrounding_residues() -> None:
try:
structure = get_structure(pdb, "101M")
finally:
pdb._close() # noqa: SLF001
pdb._close()

all_residues = structure.get_chain("A").residues
# A nicely centered residue
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def graph() -> Graph:
try:
structure = get_structure(pdb, entry_id)
finally:
pdb._close() # noqa: SLF001
pdb._close()

# build a contact from two residues
residue0 = structure.chains[0].residues[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_pssmdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_add_pssm() -> None:
try:
structure = get_structure(pdb, "1ATN")
finally:
pdb._close() # noqa: SLF001
pdb._close()

for chain in structure.chains:
with open(f"tests/data/pssm/1ATN/1ATN.{chain.id}.pdb.pssm", encoding="utf-8") as f:
Expand Down
Loading