Skip to content

Commit 93dc9db

Browse files
authored
Merge pull request #22 from stevenhua0320/pre-commit-auto
style: apply pre-commit hooks with no manual edits
2 parents e8af88f + 6a6749e commit 93dc9db

File tree

4 files changed

+116
-18
lines changed

4 files changed

+116
-18
lines changed

.flake8

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# As of now, flake8 does not natively support configuration via pyproject.toml
2+
# https://github.com/microsoft/vscode-flake8/issues/135
3+
[flake8]
4+
exclude =
5+
.git,
6+
__pycache__,
7+
build,
8+
dist,
9+
docs/source/conf.py
10+
max-line-length = 79
11+
# Ignore some style 'errors' produced while formatting by 'black'
12+
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#labels-why-pycodestyle-warnings
13+
extend-ignore = E203

.isort.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[settings]
2+
# Keep import statement below line_length character limit
3+
line_length = 79
4+
multi_line_output = 3
5+
include_trailing_comma = True

.pre-commit-config.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
default_language_version:
2+
python: python3
3+
ci:
4+
autofix_commit_msg: |
5+
[pre-commit.ci] auto fixes from pre-commit hooks
6+
autofix_prs: true
7+
autoupdate_branch: "pre-commit-autoupdate"
8+
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
9+
autoupdate_schedule: monthly
10+
skip: [no-commit-to-branch]
11+
submodules: false
12+
repos:
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v4.6.0
15+
hooks:
16+
- id: check-yaml
17+
- id: end-of-file-fixer
18+
- id: trailing-whitespace
19+
- id: check-case-conflict
20+
- id: check-merge-conflict
21+
- id: check-toml
22+
- id: check-added-large-files
23+
- repo: https://github.com/psf/black
24+
rev: 24.4.2
25+
hooks:
26+
- id: black
27+
- repo: https://github.com/pycqa/flake8
28+
rev: 7.0.0
29+
hooks:
30+
- id: flake8
31+
- repo: https://github.com/pycqa/isort
32+
rev: 5.13.2
33+
hooks:
34+
- id: isort
35+
args: ["--profile", "black"]
36+
- repo: https://github.com/kynan/nbstripout
37+
rev: 0.7.1
38+
hooks:
39+
- id: nbstripout
40+
- repo: https://github.com/pre-commit/pre-commit-hooks
41+
rev: v4.4.0
42+
hooks:
43+
- id: no-commit-to-branch
44+
name: Prevent Commit to Main Branch
45+
args: ["--branch", "main"]
46+
stages: [pre-commit]
47+
- repo: https://github.com/codespell-project/codespell
48+
rev: v2.3.0
49+
hooks:
50+
- id: codespell
51+
additional_dependencies:
52+
- tomli
53+
# prettier - multi formatter for .json, .yml, and .md files
54+
- repo: https://github.com/pre-commit/mirrors-prettier
55+
rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8
56+
hooks:
57+
- id: prettier
58+
additional_dependencies:
59+
- "prettier@^3.2.4"
60+
# docformatter - PEP 257 compliant docstring formatter
61+
- repo: https://github.com/s-weigand/docformatter
62+
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
63+
hooks:
64+
- id: docformatter
65+
additional_dependencies: [tomli]
66+
args: [--in-place, --config, ./pyproject.toml]

src/diffpy/srxplanargui/imageplot.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,38 +101,50 @@ class ImagePlot(HasTraits):
101101
)
102102
avgmask = DelegatesTo(
103103
"srxconfig",
104-
desc=("Mask the pixels too bright or too dark compared to"
105-
" the average intensity at the similar diffraction angle"),
104+
desc=(
105+
"Mask the pixels too bright or too dark compared to"
106+
" the average intensity at the similar diffraction angle"
107+
),
106108
)
107109
brightpixelr = DelegatesTo(
108110
"srxconfig",
109-
desc=("Pixels with intensity large than this relative threshold"
110-
" (times the local environment) value will be masked"),
111+
desc=(
112+
"Pixels with intensity large than this relative threshold"
113+
" (times the local environment) value will be masked"
114+
),
111115
)
112116
brightpixelsize = DelegatesTo(
113117
"srxconfig", desc="Size of testing area for detecting bright pixels"
114118
)
115119
darkpixelr = DelegatesTo(
116120
"srxconfig",
117-
desc=("Pixels with intensity less than this relative threshold"
118-
" (times the local environment) value will be masked"),
121+
desc=(
122+
"Pixels with intensity less than this relative threshold"
123+
" (times the local environment) value will be masked"
124+
),
119125
)
120126
avgmaskhigh = DelegatesTo(
121127
"srxconfig",
122-
desc=("Comparing to the average intensity at "
123-
"similar diffraction angle, \npixels with intensity larger than"
124-
" avg_int*high will be masked"),
128+
desc=(
129+
"Comparing to the average intensity at "
130+
"similar diffraction angle, \npixels with intensity larger than"
131+
" avg_int*high will be masked"
132+
),
125133
)
126134
avgmasklow = DelegatesTo(
127135
"srxconfig",
128-
desc=("Comparing to the average intensity at "
129-
"similar diffraction angle, \npixels with intensity less than "
130-
"avg_int*low will be masked"),
136+
desc=(
137+
"Comparing to the average intensity at "
138+
"similar diffraction angle, \npixels with intensity less than "
139+
"avg_int*low will be masked"
140+
),
131141
)
132142
cropedges = DelegatesTo(
133143
"srxconfig",
134-
desc=("The number of pixels masked"
135-
" at each edge (left, right, top, bottom)"),
144+
desc=(
145+
"The number of pixels masked"
146+
" at each edge (left, right, top, bottom)"
147+
),
136148
)
137149

138150
def createPlot(self):
@@ -231,7 +243,7 @@ def addPointMask(self, ndx, remove=None):
231243
"""Param ndx -- (x,y) float."""
232244
x, y = ndx
233245
r = self.pts - np.array((x, y))
234-
r = np.sum(r ** 2, axis=1)
246+
r = np.sum(r**2, axis=1)
235247
mask = r < ((self.pointmaskradius + 1) ** 2)
236248
mask = mask.reshape(self.staticmask.shape)
237249
if remove:
@@ -318,9 +330,11 @@ def _enableMaskEditing(self):
318330
self.plot.tools.remove(self.pan)
319331
self.plot.overlays.append(self.lstool)
320332
self.titlebak = self.plot.title
321-
self.plot.title = ("Click: add a vertex; "
322-
"<Ctrl>+Click: remove a vertex; \n "
323-
"<Enter>: finish the selection")
333+
self.plot.title = (
334+
"Click: add a vertex; "
335+
"<Ctrl>+Click: remove a vertex; \n "
336+
"<Enter>: finish the selection"
337+
)
324338
return
325339

326340
def _disableMaskEditing(self):

0 commit comments

Comments
 (0)