Skip to content

Commit

Permalink
Update dev tools (#24)
Browse files Browse the repository at this point in the history
* Switch to ruff
* Clean code to pass linting
  • Loading branch information
maabuu authored Feb 20, 2024
1 parent b904484 commit 2689bcf
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 184 deletions.
161 changes: 74 additions & 87 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,87 @@ ci:
exclude: ^tests/conftest/|^.vscode/|^posebusters/datasets/pdb

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# - id: no-commit-to-branch # branch protected on github
- id: forbid-submodules
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: check-toml
- id: check-json
- id: check-ast
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace
- id: name-tests-test
args: [--pytest-test-first]
- id: sort-simple-yaml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# - id: no-commit-to-branch # branch protected on github
- id: forbid-submodules
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: check-toml
- id: check-json
- id: check-ast
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace
- id: name-tests-test
args: [--pytest-test-first]
- id: sort-simple-yaml

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-log-warn
- id: python-no-eval
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

# update syntax
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]

# sort imports
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--settings-path=pyproject.toml"]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-log-warn
- id: python-no-eval
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

# find unused imports
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: pycln
args: ["--config=pyproject.toml"]
stages: ["manual"]
# update syntax
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]

# format code
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
language_version: python3.11
args: ["--config=pyproject.toml"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.2
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format

# lint code
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: ["flake8-black", "flake8-docstrings", "flake8-pyproject"]
# find unused imports
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: pycln
args: ["--config=pyproject.toml"]
stages: ["manual"]

# check types
- repo: https://github.com/pre-commit/mirrors-mypy
# check types
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
hooks:
- id: mypy
- id: mypy
additional_dependencies: ["types-PyYAML"]

# find typos
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies: ["tomli"]
# find typos
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies: ["tomli"]

# security lint
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
# security lint
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
61 changes: 31 additions & 30 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,26 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug Tests",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
"presentation": {
"hidden": true
},
"justMyCode": false,
"env": {
"PYTEST_ADDOPTS": "--no-cov"
}
},
{
"name": "bust conditioned on protein and ligand",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -22,7 +39,7 @@
},
{
"name": "bust conditioned on protein and ligand -- long",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -40,7 +57,7 @@
},
{
"name": "bust conditioned on protein",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -54,7 +71,7 @@
},
{
"name": "bust unconditioned",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -66,7 +83,7 @@
},
{
"name": "bust unconditioned - yael test case",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -78,7 +95,7 @@
},
{
"name": "bust table input",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -91,7 +108,7 @@
},
{
"name": "bust table -- long",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -106,7 +123,7 @@
},
{
"name": "bust table -- csv",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -119,25 +136,9 @@
"csv",
]
},
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"cwd": "${workspaceFolder}",
"purpose": [
"debug-test"
],
"stopOnEntry": false,
"console": "integratedTerminal",
"justMyCode": true,
"env": {
"PYTEST_ADDOPTS": "--no-cov"
}
},
{
"name": "bust conditioned on protein and ligand -- 1ia1",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -156,7 +157,7 @@
},
{
"name": "bust conditioned on protein -- 1ia1",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -170,7 +171,7 @@
},
{
"name": "bust conditioned on protein -- 1w1p crystal",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -189,7 +190,7 @@
},
{
"name": "bust conditioned on protein -- 1g9v gold",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -210,7 +211,7 @@
},
{
"name": "bust conditioned on protein -- 1gkc",
"type": "python",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "posebusters",
Expand All @@ -228,6 +229,6 @@
"--outfmt",
"long",
]
}
},
]
}
18 changes: 5 additions & 13 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,19 @@
"editor.defaultFormatter": "vscode.json-language-features"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
},
"python.analysis.typeCheckingMode": "basic",
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"black-formatter.args": [
"--config=pyproject.toml"
],
"flake8.args": [
"--toml-config=pyproject.toml"
],
"isort.args": [
"--settings-path=pyproject.toml"
],
"pylint.args": [
"--rcfile=pyproject.toml"
"python.testing.pytestArgs": [
"--no-cov"
],
"autoDocstring.docstringFormat": "google-notypes",
"autoDocstring.generateDocstringOnEnter": true,
Expand Down
2 changes: 1 addition & 1 deletion posebusters/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main():
logger.error(e)


def bust(
def bust( # noqa: PLR0913
mol_pred: list[Path | Mol] = [],
mol_true: Path | Mol | None = None,
mol_cond: Path | Mol | None = None,
Expand Down
6 changes: 3 additions & 3 deletions posebusters/modules/distance_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}


def check_geometry(
def check_geometry( # noqa: PLR0913, PLR0915
mol_pred: Mol,
threshold_bad_bond_length: float = 0.2,
threshold_clash: float = 0.2,
Expand Down Expand Up @@ -234,8 +234,8 @@ def _two_bonds_to_angle(bond1: tuple[int, int], bond2: tuple[int, int]) -> None
set1 = set(bond1)
set2 = set(bond2)
all_atoms = set1 | set2
# angle requires two bonds to share exactly one atom
if len(all_atoms) != 3:
# angle requires two bonds to share exactly one atom, that is we must have 3 atoms
if len(all_atoms) != 3: # noqa: PLR2004
return None
# find shared atom
shared_atom = set1 & set2
Expand Down
Loading

0 comments on commit 2689bcf

Please sign in to comment.