Skip to content

Commit 390927e

Browse files
Add Ruff to pre-commit hooks (#1207)
* update CI and precommit files * add ruff changes * remove gmso lines * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * change error type in test * raise the error that is created * remove duplicate windows 3.12 test * fix precommit errors * fix import error * fix CI error --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8d6d62d commit 390927e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+448
-1031
lines changed

.github/workflows/CI.yaml

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ on:
1313
jobs:
1414
test:
1515
if: github.event.pull_request.draft == false
16-
name: mBuild Tests
16+
name: mBuild Tests (python)
1717
runs-on: ${{ matrix.os }}
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
os: [macOS-latest, macOS-13, ubuntu-latest]
21+
os: [ubuntu-latest]
2222
python-version: ["3.9", "3.10", "3.11", "3.12"]
23-
include:
24-
- os: windows-latest
25-
python-version: "3.12"
2623

2724
defaults:
2825
run:
@@ -60,6 +57,45 @@ jobs:
6057
name: mBuild-Coverage
6158
verbose: true
6259
files: ./coverage.xml
60+
arch-test:
61+
if: github.event.pull_request.draft == false
62+
name: mBuild Tests (arch)
63+
runs-on: ${{ matrix.os }}
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
os: [macOS-latest, macOS-13, ubuntu-latest, windows-latest]
68+
python-version: ["3.12"]
69+
70+
defaults:
71+
run:
72+
shell: bash -l {0}
73+
74+
steps:
75+
- uses: actions/checkout@v4
76+
name: Checkout Branch / Pull Request
77+
78+
- name: Install Mamba (Linux)
79+
uses: mamba-org/setup-micromamba@v1
80+
with:
81+
environment-file: environment-dev.yml
82+
create-args: >-
83+
python=${{ matrix.python-version }}
84+
if: runner.os != 'Windows'
85+
86+
- name: Install Mamba (Windows)
87+
uses: mamba-org/setup-micromamba@v1
88+
with:
89+
environment-file: environment-dev-win.yml
90+
create-args: >-
91+
python=${{ matrix.python-version }}
92+
if: runner.os == 'Windows'
93+
94+
- name: Install Package
95+
run: python -m pip install -e .
96+
97+
- name: Test (OS -> ${{ matrix.os }} / Python -> ${{ matrix.python-version }})
98+
run: python -m pytest -v --cov=mbuild --cov-report=xml --cov-append --cov-config=setup.cfg --color yes --pyargs mbuild
6399

64100
bleeding-edge-test:
65101
if: github.event.pull_request.draft == false
@@ -77,7 +113,7 @@ jobs:
77113
uses: mamba-org/setup-micromamba@v1
78114
with:
79115
environment-file: environment-dev.yml
80-
create-args: python=3.11
116+
create-args: python=3.12
81117

82118
- name: Clone Foyer and GMSO
83119
run: |

.pre-commit-config.yaml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
ci:
22
autofix_commit_msg: |
33
[pre-commit.ci] auto fixes from pre-commit.com hooks
4-
54
for more information, see https://pre-commit.ci
65
autofix_prs: true
76
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
87
autoupdate_schedule: weekly
98
skip: []
109
submodules: false
1110
repos:
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
# Ruff version.
13+
rev: v0.7.0
14+
hooks:
15+
# Run the linter.
16+
- id: ruff
17+
args: [--line-length=80, --fix]
18+
# Run the formatter.
19+
- id: ruff-format
1220
- repo: https://github.com/pre-commit/pre-commit-hooks
1321
rev: v5.0.0
1422
hooks:
1523
- id: check-yaml
1624
- id: end-of-file-fixer
1725
- id: trailing-whitespace
18-
exclude: setup.cfg
19-
- repo: https://github.com/psf/black
20-
rev: 24.10.0
21-
hooks:
22-
- id: black
23-
args: [--line-length=80]
26+
2427
- repo: https://github.com/pycqa/isort
2528
rev: 5.13.2
2629
hooks:
2730
- id: isort
2831
name: isort (python)
2932
args: [--profile=black, --line-length=80]
30-
- repo: https://github.com/pycqa/pydocstyle
31-
rev: '6.3.0'
32-
hooks:
33-
- id: pydocstyle
34-
exclude: ^(mbuild/tests/|docs/|devtools/|setup.py|setup.cfg|mbuild/formats/charmm_writer.py|mbuild/formats/gomc_conf_writer.py|mbuild/utils/specific_ff_to_residue.py)
35-
args: [--convention=numpy]

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import sys
1717

1818
import mock
19+
import sphinx_rtd_theme
1920

2021
# If extensions (or modules to document with autodoc) are in another directory,
2122
# add these directories to sys.path here. If the directory is relative to the
@@ -205,7 +206,6 @@
205206
# The theme to use for HTML and HTML Help pages. See the documentation for
206207
# a list of builtin themes.
207208
# html_theme = 'default'
208-
import sphinx_rtd_theme
209209

210210
html_theme = "sphinx_rtd_theme"
211211
hhtml_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

docs/sphinxext/notebook_sphinxext.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ def setup(app):
130130
setup.config = app.config
131131
setup.confdir = app.confdir
132132

133-
app.add_node(
134-
notebook_node, html=(visit_notebook_node, depart_notebook_node)
135-
)
133+
app.add_node(notebook_node, html=(visit_notebook_node, depart_notebook_node))
136134

137135
app.add_directive("notebook", NotebookDirective)

mbuild/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ruff: noqa: F401
2+
# ruff: noqa: F403
13
"""mBuild: a hierarchical, component based molecule builder."""
24

35
from mbuild.box import Box

mbuild/bond_graph.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4040
"""
4141

42-
from collections import defaultdict
43-
4442
import networkx as nx
4543

4644

mbuild/box.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ def from_uvec_lengths(cls, uvec, lengths, precision=None):
9898
scaled_vec = (uvec.T * lengths).T
9999
(alpha, beta, gamma) = _calc_angles(scaled_vec)
100100

101-
return cls(
102-
lengths=lengths, angles=(alpha, beta, gamma), precision=precision
103-
)
101+
return cls(lengths=lengths, angles=(alpha, beta, gamma), precision=precision)
104102

105103
@classmethod
106104
def from_mins_maxs_angles(cls, mins, maxs, angles, precision=None):
@@ -123,28 +121,20 @@ def from_vectors(cls, vectors, precision=None):
123121
Ly = np.linalg.norm(v2)
124122
Lz = np.linalg.norm(v3)
125123
lengths = (Lx, Ly, Lz)
126-
return cls(
127-
lengths=lengths, angles=(alpha, beta, gamma), precision=precision
128-
)
124+
return cls(lengths=lengths, angles=(alpha, beta, gamma), precision=precision)
129125

130126
@classmethod
131-
def from_lengths_tilt_factors(
132-
cls, lengths, tilt_factors=None, precision=None
133-
):
127+
def from_lengths_tilt_factors(cls, lengths, tilt_factors=None, precision=None):
134128
"""Generate a box from box lengths and tilt factors."""
135129
(Lx, Ly, Lz) = lengths
136130
if tilt_factors is None:
137131
(xy, xz, yz) = (0.0, 0.0, 0.0)
138132
else:
139133
(xy, xz, yz) = tilt_factors
140134

141-
vecs = np.asarray(
142-
[[Lx, 0.0, 0.0], [Ly * xy, Ly, 0.0], [Lz * xz, Lz * yz, Lz]]
143-
)
135+
vecs = np.asarray([[Lx, 0.0, 0.0], [Ly * xy, Ly, 0.0], [Lz * xz, Lz * yz, Lz]])
144136
(alpha, beta, gamma) = _calc_angles(vecs)
145-
return cls(
146-
lengths=lengths, angles=[alpha, beta, gamma], precision=precision
147-
)
137+
return cls(lengths=lengths, angles=[alpha, beta, gamma], precision=precision)
148138

149139
@classmethod
150140
def from_lo_hi_tilt_factors(cls, lo, hi, tilt_factors, precision=None):
@@ -159,9 +149,7 @@ def from_lo_hi_tilt_factors(cls, lo, hi, tilt_factors, precision=None):
159149
yhi_bound = yhi + max([0.0, yz])
160150

161151
lengths = [xhi_bound - xlo_bound, yhi_bound - ylo_bound, zhi - zlo]
162-
return cls.from_lengths_tilt_factors(
163-
lengths=lengths, tilt_factors=tilt_factors
164-
)
152+
return cls.from_lengths_tilt_factors(lengths=lengths, tilt_factors=tilt_factors)
165153

166154
@property
167155
def vectors(self):
@@ -327,8 +315,6 @@ def _lengths_angles_to_vectors(lengths, angles, precision):
327315
cos_b = np.clip(np.cos(beta), -1.0, 1.0)
328316
cos_g = np.clip(np.cos(gamma), -1.0, 1.0)
329317

330-
sin_a = np.clip(np.sin(alpha), -1.0, 1.0)
331-
sin_b = np.clip(np.sin(beta), -1.0, 1.0)
332318
sin_g = np.clip(np.sin(gamma), -1.0, 1.0)
333319
a_vec = np.asarray([a, 0.0, 0.0])
334320

@@ -376,9 +362,7 @@ def _normalize_box(vectors):
376362
sign = np.linalg.det(Q)
377363
R = R * sign
378364

379-
signs = np.diag(
380-
np.diag(np.where(R < 0, -np.ones(R.shape), np.ones(R.shape)))
381-
)
365+
signs = np.diag(np.diag(np.where(R < 0, -np.ones(R.shape), np.ones(R.shape))))
382366
transformed_vecs = R.dot(signs)
383367
return _reduced_form_vectors(transformed_vecs.T)
384368

mbuild/coarse_graining.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ def _clone(self, clone_of=None, root_container=None):
113113
if self.labels:
114114
for label, compound in self.labels.items():
115115
if not isinstance(compound, list):
116-
newone.labels[label] = compound._clone(
117-
clone_of, root_container
118-
)
116+
newone.labels[label] = compound._clone(clone_of, root_container)
119117
compound.referrers.add(clone_of[compound])
120118
else:
121119
# compound is a list of compounds, so we create an empty
@@ -150,13 +148,11 @@ def _create_proxy_compounds(real_thing, memo, particle_classes):
150148
proxy = Proxy(real_thing)
151149
memo[real_thing] = proxy
152150

153-
if not type(real_thing) in particle_classes:
151+
if type(real_thing) not in particle_classes:
154152
if not is_leaf(real_thing): # Recurse only if it has parts.
155153
# Recursively create proxies for parts.
156154
for part in real_thing.children:
157-
part_proxy = _create_proxy_compounds(
158-
part, memo, particle_classes
159-
)
155+
part_proxy = _create_proxy_compounds(part, memo, particle_classes)
160156
proxy.add(part_proxy)
161157

162158
return proxy

0 commit comments

Comments
 (0)