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

Add ruff to pre-commit hooks #573

Merged
merged 6 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ ci:
skip: []
submodules: false
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
hooks:
# Run the linter.
- id: ruff
args: [--line-length=80, --fix]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: 'setup.cfg'
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
args: [--line-length=80]
exclude: 'setup.cfg|foyer/tests/files/.*'

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args: [--profile=black, --line-length=80]
- repo: https://github.com/pycqa/pydocstyle
rev: '6.3.0'
hooks:
- id: pydocstyle
exclude: ^(foyer/tests/|docs/|devtools/|setup.py)
args: [--convention=numpy]
exclude: "foyer/tests/files/.*"
5 changes: 2 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import pathlib
import sys

import sphinx_rtd_theme

sys.path.insert(0, os.path.abspath("../.."))
sys.path.insert(0, os.path.abspath("sphinxext"))

base_path = pathlib.Path(__file__).parent
os.system("python {} --name".format((base_path / "../../setup.py").resolve()))


import foyer

# -- Project information -----------------------------------------------------

project = "foyer"
Expand Down Expand Up @@ -147,7 +147,6 @@
# a list of builtin themes.
#
# html_theme = 'alabaster'
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"
hhtml_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
Expand Down
16 changes: 4 additions & 12 deletions foyer/atomtyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def find_atomtypes(structure, forcefield, max_iter=10):
topology_graph = TopologyGraph.from_gmso_topology(structure)

if isinstance(forcefield, Forcefield):
atomtype_rules = AtomTypingRulesProvider.from_foyer_forcefield(
forcefield
)
atomtype_rules = AtomTypingRulesProvider.from_foyer_forcefield(forcefield)
elif isinstance(forcefield, AtomTypingRulesProvider):
atomtype_rules = forcefield
else:
Expand Down Expand Up @@ -110,9 +108,7 @@ def find_atomtypes(structure, forcefield, max_iter=10):
atomic_number = atom_data.atomic_number
atomic_symbol = atom_data.element
try:
element_from_num = ele.element_from_atomic_number(
atomic_number
).symbol
element_from_num = ele.element_from_atomic_number(atomic_number).symbol
element_from_sym = ele.element_from_symbol(atomic_symbol).symbol
assert element_from_num == element_from_sym
system_elements.add(element_from_num)
Expand Down Expand Up @@ -210,13 +206,9 @@ def _iterate_rules(rules, topology_graph, typemap, max_iter):

def _resolve_atomtypes(topology_graph, typemap):
"""Determine the final atomtypes from the white- and blacklists."""
atoms = {
atom_idx: data for atom_idx, data in topology_graph.atoms(data=True)
}
atoms = {atom_idx: data for atom_idx, data in topology_graph.atoms(data=True)}
for atom_id, atom in typemap.items():
atomtype = [
rule_name for rule_name in atom["whitelist"] - atom["blacklist"]
]
atomtype = [rule_name for rule_name in atom["whitelist"] - atom["blacklist"]]
if len(atomtype) == 1:
atom["atomtype"] = atomtype[0]
elif len(atomtype) > 1:
Expand Down
Loading
Loading