Skip to content

Commit

Permalink
ruff unignore PLR, only ignore specific PLR0912 PLR0913 PLR0915
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Jun 5, 2024
1 parent bd589e8 commit 6b28e82
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
10 changes: 7 additions & 3 deletions chgnet/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,18 @@ def __init__(self, nodes: list[Node]) -> None:
self.undirected_edges: dict[frozenset[int], list[UndirectedEdge]] = {}
self.undirected_edges_list: list[UndirectedEdge] = []

def add_edge(self, center_index, neighbor_index, image, distance) -> None:
def add_edge(
self, center_index, neighbor_index, image, distance, dist_tol: float = 1e-6
) -> None:
"""Add an directed edge to the graph.
Args:
center_index (int): center node index
neighbor_index (int): neighbor node index
image (np.array): the periodic cell image the neighbor is from
distance (float): distance between center and neighbor.
dist_tol (float): tolerance for distance comparison between edges.
Default = 1e-6
"""
# Create directed_edge (DE) index using the length of added DEs
directed_edge_index = len(self.directed_edges_list)
Expand Down Expand Up @@ -173,7 +177,7 @@ def add_edge(self, center_index, neighbor_index, image, distance) -> None:
# different image and distance (this is possible consider periodicity)
for undirected_edge in self.undirected_edges[tmp]:
if (
abs(undirected_edge.info["distance"] - distance) < 1e-6
abs(undirected_edge.info["distance"] - distance) < dist_tol
and len(undirected_edge.info["directed_edge_index"]) == 1
):
# There is an undirected edge with similar length and only one of
Expand Down Expand Up @@ -286,7 +290,7 @@ def line_graph_adjacency_list(self, cutoff) -> tuple[list[list[int]], list[int]]
# if encountered exception,
# it means after Atom_Graph creation, the UDE has only 1 DE associated
# This exception is not encountered from the develop team's experience
if len(u_edge.info["directed_edge_index"]) != 2:
if len(u_edge.info["directed_edge_index"]) != 2: # noqa: PLR2004
raise ValueError(
"Did not find 2 Directed_edges !!!"
f"undirected edge {u_edge} has:"
Expand Down
2 changes: 1 addition & 1 deletion chgnet/model/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def relax(
dict[str, Structure | TrajectoryObserver]:
A dictionary with 'final_structure' and 'trajectory'.
"""
import ase.filters as filters
from ase import filters
from ase.filters import Filter

valid_filter_names = [
Expand Down
15 changes: 13 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ ignore = [
"ERA001", # found commented out code
"ISC001",
"NPY002", # TODO replace legacy np.random.seed
"PLR", # pylint refactor
"PLR0912", # too many branches
"PLR0913", # too many args in function def
"PLR0915", # too many statements
"PLW2901", # Outer for loop variable overwritten by inner assignment target
"PT006", # pytest-parametrize-names-wrong-type
"PTH", # prefer Path to os.path
Expand All @@ -93,7 +95,16 @@ docstring-code-format = true

[tool.ruff.lint.per-file-ignores]
"site/*" = ["INP001", "S602"]
"tests/*" = ["ANN201", "D100", "D103", "FBT001", "FBT002", "INP001", "S101"]
"tests/*" = [
"ANN201",
"D100",
"D103",
"FBT001",
"FBT002",
"INP001",
"PLR2004",
"S101",
]
# E402 Module level import not at top of file
"examples/*" = ["E402", "I002", "INP001", "N816", "S101", "T201"]
"chgnet/**/*" = ["T201"]
Expand Down
3 changes: 2 additions & 1 deletion site/make_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

# remove all files with less than 20 lines
# these correspond to mostly empty __init__.py files
if markdown.count("\n") < 20:
min_line_cnt = 20
if markdown.count("\n") < min_line_cnt:
os.remove(path)
continue

Expand Down
2 changes: 1 addition & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_directed_edge() -> None:
info = {"image": np.zeros(3), "distance": 1}
edge = DirectedEdge([0, 1], index=0, info=info)
undirected = edge.make_undirected(index=0, info=info)
assert edge == edge
assert edge == edge # noqa: PLR0124
assert edge == undirected
assert edge.nodes == [0, 1]
assert edge.index == 0
Expand Down

0 comments on commit 6b28e82

Please sign in to comment.