Skip to content

Commit c9a2ca4

Browse files
Change docformatter, update all other hooks (diffpy#302)
* Change docformatter, update all other hooks * News * [pre-commit.ci] auto fixes from pre-commit hooks * Fix black/docformatter conflict --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> # Conflicts: # src/diffpy/morph/morph_io.py
1 parent 001feb4 commit c9a2ca4

32 files changed

Lines changed: 120 additions & 144 deletions

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ci:
1111
submodules: false
1212
repos:
1313
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: v4.6.0
14+
rev: v6.0.0
1515
hooks:
1616
- id: check-yaml
1717
- id: end-of-file-fixer
@@ -21,45 +21,45 @@ repos:
2121
- id: check-toml
2222
- id: check-added-large-files
2323
- repo: https://github.com/psf/black
24-
rev: 24.4.2
24+
rev: 26.3.1
2525
hooks:
2626
- id: black
2727
- repo: https://github.com/pycqa/flake8
28-
rev: 7.0.0
28+
rev: 7.3.0
2929
hooks:
3030
- id: flake8
3131
- repo: https://github.com/pycqa/isort
32-
rev: 5.13.2
32+
rev: 9.0.0a3
3333
hooks:
3434
- id: isort
3535
args: ["--profile", "black"]
3636
- repo: https://github.com/kynan/nbstripout
37-
rev: 0.7.1
37+
rev: 0.9.1
3838
hooks:
3939
- id: nbstripout
4040
- repo: https://github.com/pre-commit/pre-commit-hooks
41-
rev: v4.4.0
41+
rev: v6.0.0
4242
hooks:
4343
- id: no-commit-to-branch
4444
name: Prevent Commit to Main Branch
4545
args: ["--branch", "main"]
4646
stages: [pre-commit]
4747
- repo: https://github.com/codespell-project/codespell
48-
rev: v2.3.0
48+
rev: v2.4.2
4949
hooks:
5050
- id: codespell
5151
additional_dependencies:
5252
- tomli
5353
# prettier - multi formatter for .json, .yml, and .md files
5454
- repo: https://github.com/pre-commit/mirrors-prettier
55-
rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8
55+
rev: v4.0.0-alpha.8
5656
hooks:
5757
- id: prettier
5858
additional_dependencies:
5959
- "prettier@^3.2.4"
6060
# docformatter - PEP 257 compliant docstring formatter
61-
- repo: https://github.com/s-weigand/docformatter
62-
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
61+
- repo: https://github.com/PyCQA/docformatter
62+
rev: v1.7.8
6363
hooks:
6464
- id: docformatter
6565
additional_dependencies: [tomli]

news/docformatter.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* Now use `PyCQA/docformatter` to format Python docstrings.
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/morph/morph_helpers/transformpdftordf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
##############################################################################
1515
"""Class TransformXtalPDFtoRDF -- Transform crystal PDFs to RDFs."""
1616

17-
1817
from diffpy.morph.morphs.morph import LABEL_GR, LABEL_RA, LABEL_RR, Morph
1918

2019

src/diffpy/morph/morph_helpers/transformrdftopdf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
##############################################################################
1515
"""Class TransformXtalRDFtoPDF -- Transform crystal RDFs to PDFs."""
1616

17-
1817
import numpy
1918

2019
from diffpy.morph.morphs.morph import LABEL_GR, LABEL_RA, LABEL_RR, Morph

src/diffpy/morph/morph_io.py

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -124,61 +124,9 @@ def build_morph_inputs_container(
124124
return morph_inputs
125125

126126

127-
def get_terminal_morph_output(mr_copy, uncertainties):
128-
morphs_out = "# Optimized morphing parameters:\n"
129-
# Handle special inputs (numerical)
130-
if "squeeze" in mr_copy:
131-
sq_dict = mr_copy.pop("squeeze")
132-
rw_pos = list(mr_copy.keys()).index("Rw")
133-
morph_results_list = list(mr_copy.items())
134-
for idx, _ in enumerate(sq_dict):
135-
morph_results_list.insert(
136-
rw_pos + idx, (f"squeeze a{idx}", sq_dict[f"a{idx}"])
137-
)
138-
mr_copy = dict(morph_results_list)
139-
140-
# Handle special inputs (functional remove)
141-
func_dicts = {
142-
"funcxy": [None, None],
143-
"funcx": [None, None],
144-
"funcy": [None, None],
145-
}
146-
for func in func_dicts.keys():
147-
if f"{func}_function" in mr_copy:
148-
func_dicts[func][0] = mr_copy.pop(f"{func}_function")
149-
if func in mr_copy:
150-
func_dicts[func][1] = mr_copy.pop(func)
151-
rw_pos = list(mr_copy.keys()).index("Rw")
152-
morph_results_list = list(mr_copy.items())
153-
for idx, key in enumerate(func_dicts[func][1]):
154-
morph_results_list.insert(
155-
rw_pos + idx, (f"{func} {key}", func_dicts[func][1][key])
156-
)
157-
mr_copy = dict(morph_results_list)
158-
159-
# Get uncertainties
160-
if uncertainties is None:
161-
morphs_out += "\n".join(
162-
f"# {key} = {mr_copy[key]:.6f}" for key in mr_copy.keys()
163-
)
164-
else:
165-
morphs_out += "\n".join(
166-
f"# {key} = {mr_copy[key]:.6f}"
167-
+ (
168-
f" +/- {uncertainties[key]:.6f}"
169-
if key in uncertainties
170-
else ""
171-
)
172-
for key in mr_copy
173-
)
174-
175-
return morphs_out, func_dicts
176-
177-
178127
def single_morph_output(
179128
morph_inputs,
180129
morph_results,
181-
uncertainties=None,
182130
save_file=None,
183131
morph_file=None,
184132
xy_out=None,
@@ -194,8 +142,6 @@ def single_morph_output(
194142
Parameters given by the user.
195143
morph_results: dict
196144
Resulting data after morphing.
197-
uncertainties: dict
198-
Uncertainties of all morphed parameters.
199145
save_file
200146
Name of file to print to. If None (default) print to terminal.
201147
morph_file
@@ -220,7 +166,41 @@ def single_morph_output(
220166
)
221167

222168
mr_copy = morph_results.copy()
223-
morphs_out, func_dicts = get_terminal_morph_output(mr_copy, uncertainties)
169+
morphs_out = "# Optimized morphing parameters:\n"
170+
# Handle special inputs (numerical)
171+
if "squeeze" in mr_copy:
172+
sq_dict = mr_copy.pop("squeeze")
173+
rw_pos = list(mr_copy.keys()).index("Rw")
174+
morph_results_list = list(mr_copy.items())
175+
for idx, _ in enumerate(sq_dict):
176+
morph_results_list.insert(
177+
rw_pos + idx, (f"squeeze a{idx}", sq_dict[f"a{idx}"])
178+
)
179+
mr_copy = dict(morph_results_list)
180+
181+
# Handle special inputs (functional remove)
182+
func_dicts = {
183+
"funcxy": [None, None],
184+
"funcx": [None, None],
185+
"funcy": [None, None],
186+
}
187+
for func in func_dicts.keys():
188+
if f"{func}_function" in mr_copy:
189+
func_dicts[func][0] = mr_copy.pop(f"{func}_function")
190+
if func in mr_copy:
191+
func_dicts[func][1] = mr_copy.pop(func)
192+
rw_pos = list(mr_copy.keys()).index("Rw")
193+
morph_results_list = list(mr_copy.items())
194+
for idx, key in enumerate(func_dicts[func][1]):
195+
morph_results_list.insert(
196+
rw_pos + idx, (f"{func} {key}", func_dicts[func][1][key])
197+
)
198+
mr_copy = dict(morph_results_list)
199+
200+
# Normal inputs
201+
morphs_out += "\n".join(
202+
f"# {key} = {mr_copy[key]:.6f}" for key in mr_copy.keys()
203+
)
224204

225205
# Handle special inputs (functional add)
226206
for func in func_dicts.keys():
@@ -360,7 +340,6 @@ def multiple_morph_output(
360340
morph_inputs,
361341
morph_results,
362342
target_files,
363-
uncertainties_dict=None,
364343
field=None,
365344
field_list=None,
366345
save_directory=None,
@@ -381,8 +360,6 @@ def multiple_morph_output(
381360
Resulting data after morphing.
382361
target_files: list
383362
Files that acted as targets to morphs.
384-
uncertainties_dict: dict
385-
Dictionary of uncertainties for each morph.
386363
save_directory
387364
Name of directory to save morphs in.
388365
field
@@ -422,11 +399,11 @@ def multiple_morph_output(
422399
output = f"\n# Target: {target}\n"
423400
else:
424401
output = f"\n# Morph: {target}\n"
425-
426-
mr_copy = morph_results[target].copy()
427-
uncertainties = uncertainties_dict[target]
428-
output_body, _ = get_terminal_morph_output(mr_copy, uncertainties)
429-
output += output_body
402+
output += "# Optimized morphing parameters:\n"
403+
output += "\n".join(
404+
f"# {param} = {morph_results[target][param]:.6f}"
405+
for param in morph_results[target]
406+
)
430407
verbose_outputs += f"{output}\n"
431408

432409
# Get items we want to put in table

src/diffpy/morph/morphapp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def morph_error(self, msg, error):
258258
help=(
259259
"Slope of the baseline. "
260260
"For a bulk material with scale factor 1, "
261-
"this will have value -4\u03C0 times the atomic density. "
261+
"this will have value -4\u03c0 times the atomic density. "
262262
"Otherwise, you can estimate it by dividing the y "
263263
"position from the x position "
264264
"of the base of the first peak. "
@@ -350,7 +350,7 @@ def morph_error(self, msg, error):
350350
"--noplot",
351351
action="store_false",
352352
dest="plot",
353-
help="""Do not show a plot.""",
353+
help="Do not show a plot.",
354354
)
355355
group.add_option(
356356
"--mlabel",
@@ -462,7 +462,7 @@ def morph_error(self, msg, error):
462462
"--reverse",
463463
dest="reverse",
464464
action="store_true",
465-
help="""Sort from highest to lowest instead.""",
465+
help="Sort from highest to lowest instead.",
466466
)
467467
group.add_option(
468468
"--serial-file",
@@ -1320,7 +1320,7 @@ def getPDFFromFile(fn):
13201320

13211321
def main():
13221322
parser = create_option_parser()
1323-
(opts, pargs) = parser.parse_args()
1323+
opts, pargs = parser.parse_args()
13241324
if opts.multiple_targets:
13251325
multiple_targets(parser, opts, pargs, stdout_flag=True)
13261326
elif opts.multiple_morphs:

src/diffpy/morph/morphpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_args(parser, params, kwargs):
2222
else:
2323
inputs.append(f"--{key}")
2424
inputs.append(f"{value}")
25-
(opts, pargs) = parser.parse_args(inputs)
25+
opts, pargs = parser.parse_args(inputs)
2626
return opts, pargs
2727

2828

src/diffpy/morph/morphs/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
##############################################################################
1515
"""Definition of morphs."""
1616

17-
1817
from diffpy.morph.morphs.morph import Morph # noqa: F401
1918
from diffpy.morph.morphs.morphchain import MorphChain # noqa: F401
2019
from diffpy.morph.morphs.morphfuncx import MorphFuncx

src/diffpy/morph/morphs/morph.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#
1414
##############################################################################
1515
"""Morph -- base class for defining a morph."""
16+
1617
import numpy
1718

1819
LABEL_RA = "r (A)" # r-grid
@@ -189,9 +190,10 @@ def applyConfig(self, config):
189190
return
190191

191192
def checkConfig(self):
192-
"""Verify data in self.config. No action by default.
193+
"""Verify data in self.config.
193194
194-
To be overridden in a derived class.
195+
No action by default. To be overridden in a derived
196+
class.
195197
"""
196198
return
197199

@@ -257,7 +259,6 @@ def set_extrapolation_info(self, x_true, x_extrapolate):
257259
x_extrapolate : array
258260
x values after a morphing process
259261
"""
260-
261262
cutoff_low = min(x_true)
262263
extrap_low_x = numpy.where(x_extrapolate < cutoff_low)[0]
263264
is_extrap_low = False if len(extrap_low_x) == 0 else True

src/diffpy/morph/morphs/morphchain.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
# See LICENSE.txt for license information.
1313
#
1414
##############################################################################
15-
"""MorphChain -- Chain of morphs executed in order.
16-
"""
15+
"""MorphChain -- Chain of morphs executed in order."""
16+
17+
# Comment required to resolve black/docformatter conflict
1718

1819

1920
class MorphChain(list):

0 commit comments

Comments
 (0)