Skip to content

Commit 3577bf0

Browse files
committed
pre-commit fixes
1 parent 0f75ef0 commit 3577bf0

21 files changed

+2102
-2050
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ exclude =
88
max-line-length = 115
99
# Ignore some style 'errors' produced while formatting by 'black'
1010
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#labels-why-pycodestyle-warnings
11-
extend-ignore = E203
11+
extend-ignore = E203

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959

6060
# This step will upload tagged commits to pypi.
6161
# The pypi token must be added to GH secrets
62-
#
62+
#
6363
# - name: Publish package
6464
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
6565
# uses: pypa/gh-action-pypi-publish@release/v1

.pre-commit-config.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
exclude: '\.(rst|txt)$'
20+
- repo: https://github.com/psf/black
21+
rev: 24.4.2
22+
hooks:
23+
- id: black
24+
- repo: https://github.com/pycqa/flake8
25+
rev: 7.0.0
26+
hooks:
27+
- id: flake8
28+
- repo: https://github.com/pycqa/isort
29+
rev: 5.13.2
30+
hooks:
31+
- id: isort
32+
args: ["--profile", "black"]
33+
- repo: https://github.com/kynan/nbstripout
34+
rev: 0.7.1
35+
hooks:
36+
- id: nbstripout
37+
- repo: https://github.com/pre-commit/pre-commit-hooks
38+
rev: v4.4.0
39+
hooks:
40+
- id: no-commit-to-branch
41+
name: Prevent Commit to Main Branch
42+
args: ["--branch", "main"]
43+
#stages: [pre-commit]

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ No notable functional changes from 1.4.1
1313
### Deprecated
1414

1515
### Removed
16-
16+
1717
### Fixed

devutils/makesdist

+22-16
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,57 @@
11
#!/usr/bin/env python
22

3-
'''Create source distribution tar.gz archive, where each file belongs
3+
"""Create source distribution tar.gz archive, where each file belongs
44
to a root user and modification time is set to the git commit time.
5-
'''
5+
"""
66

7-
import sys
7+
import glob
8+
import gzip
89
import os
910
import subprocess
10-
import glob
11+
import sys
1112
import tarfile
12-
import gzip
1313

1414
BASEDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
1515
sys.path.insert(0, BASEDIR)
1616

17-
from setup import versiondata, FALLBACK_VERSION
18-
timestamp = versiondata.getint('DEFAULT', 'timestamp')
17+
from setup import FALLBACK_VERSION, versiondata
1918

20-
vfb = versiondata.get('DEFAULT', 'version').split('.post')[0] + '.post0'
19+
timestamp = versiondata.getint("DEFAULT", "timestamp")
20+
21+
vfb = versiondata.get("DEFAULT", "version").split(".post")[0] + ".post0"
2122
emsg = "Invalid FALLBACK_VERSION. Expected %r got %r."
2223
assert vfb == FALLBACK_VERSION, emsg % (vfb, FALLBACK_VERSION)
2324

25+
2426
def inform(s):
2527
sys.stdout.write(s)
2628
sys.stdout.flush()
2729
return
2830

31+
2932
inform('Run "setup.py sdist --formats=tar" ')
30-
cmd_sdist = [sys.executable] + 'setup.py sdist --formats=tar'.split()
31-
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, 'w'))
32-
if ec: sys.exit(ec)
33+
cmd_sdist = [sys.executable] + "setup.py sdist --formats=tar".split()
34+
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, "w"))
35+
if ec:
36+
sys.exit(ec)
3337
inform("[done]\n")
3438

35-
tarname = max(glob.glob(BASEDIR + '/dist/*.tar'), key=os.path.getmtime)
39+
tarname = max(glob.glob(BASEDIR + "/dist/*.tar"), key=os.path.getmtime)
3640

3741
tfin = tarfile.open(tarname)
38-
fpout = gzip.GzipFile(tarname + '.gz', 'w', mtime=0)
39-
tfout = tarfile.open(fileobj=fpout, mode='w')
42+
fpout = gzip.GzipFile(tarname + ".gz", "w", mtime=0)
43+
tfout = tarfile.open(fileobj=fpout, mode="w")
44+
4045

4146
def fixtarinfo(tinfo):
4247
tinfo.uid = tinfo.gid = 0
43-
tinfo.uname = tinfo.gname = 'root'
48+
tinfo.uname = tinfo.gname = "root"
4449
tinfo.mtime = timestamp
4550
tinfo.mode &= ~0o022
4651
return tinfo
4752

48-
inform('Filter %s --> %s.gz ' % (2 * (os.path.basename(tarname),)))
53+
54+
inform("Filter %s --> %s.gz " % (2 * (os.path.basename(tarname),)))
4955
for ti in tfin:
5056
tfout.addfile(fixtarinfo(ti), tfin.extractfile(ti))
5157

diffpy/pdffit2/ipy_ext.py

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def showfit(self, offset=None):
5454
No return value.
5555
"""
5656
from matplotlib.pyplot import gca
57-
from math import floor
5857

5958
cr = self.r
6059
cGobs = self.Gobs

diffpy/pdffit2/pdffit.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ def intro():
148148
date = __date__[:10]
149149
d = {"version": __version__, "date": date, "year": date[:4] or "2019"}
150150
msg = __intro_message__ % d
151-
def filler(mx): return mx.group(0).rstrip(" *").ljust(77) + "*"
151+
152+
def filler(mx):
153+
return mx.group(0).rstrip(" *").ljust(77) + "*"
154+
152155
msg_ljust = re.sub("(?m)^(.{1,77}|.{79}.*)$", filler, msg)
153156
print(msg_ljust, file=output.stdout)
154157
return
@@ -1288,6 +1291,7 @@ def __getRef(self, var_string):
12881291
retval = f(self._handle, arg_int)
12891292
return retval
12901293

1294+
12911295
# End of class PdfFit
12921296

12931297

diffpy/pdffit2/tests/ExceptionsTest.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
import unittest
1818

19-
from diffpy.pdffit2 import PdfFit
20-
from diffpy.pdffit2 import pdffit2
19+
from diffpy.pdffit2 import PdfFit, pdffit2
2120
from diffpy.pdffit2.tests.pdffit2testutils import datafile
2221

2322

diffpy/pdffit2/tests/TestPdfFit.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55

66
import unittest
77

8+
from diffpy.pdffit2 import PdfFit, pdffit2
9+
from diffpy.pdffit2.tests.pdffit2testutils import capture_output, datafile
810
from diffpy.structure import loadStructure
911

10-
from diffpy.pdffit2 import PdfFit
11-
from diffpy.pdffit2 import pdffit2
12-
from diffpy.pdffit2.tests.pdffit2testutils import datafile, capture_output
13-
14-
1512
# ----------------------------------------------------------------------------
1613

1714

@@ -324,7 +321,7 @@ def test_getcrw(self):
324321
self.assertAlmostEqual(self.P.getrw(), rw19, self.places)
325322
# renormalize cumulative Rw and compare with Rw at r=15
326323
Gobs19 = numpy.array(self.P.getpdf_obs())
327-
Gnorm19 = numpy.sqrt(numpy.sum(Gobs19 ** 2))
324+
Gnorm19 = numpy.sqrt(numpy.sum(Gobs19**2))
328325
r = numpy.array(self.P.getR())
329326
idx = numpy.nonzero(r <= 15)[0]
330327
Gnorm15 = numpy.sqrt(numpy.sum(Gobs19[idx] ** 2))
@@ -353,7 +350,7 @@ def test_getcrw_two_datasets(self):
353350
rw1 = self.P.getcrw()[-1]
354351
self.P.setdata(2)
355352
rw2 = self.P.getcrw()[-1]
356-
self.assertAlmostEqual(rwtot ** 2, rw1 ** 2 + rw2 ** 2, self.places)
353+
self.assertAlmostEqual(rwtot**2, rw1**2 + rw2**2, self.places)
357354
return
358355

359356
# def test_getpar(self):

diffpy/pdffit2/tests/TestPhaseFractions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_xray_fractions(self):
2929
"""test_xray_fractions -- check phase fractions in x-ray dataset."""
3030
self.P.setdata(1)
3131
ph = self.P.phase_fractions()
32-
bb1 = 28 ** 2
32+
bb1 = 28**2
3333
bb2 = ((8 * 82 + 24 * 8 + 4 * 21 + 2 * 74 + 2 * 22) / 40.0) ** 2
3434
self.assertAlmostEqual(1.0, sum(ph["atom"]), self.places)
3535
self.assertAlmostEqual(1.0, sum(ph["cell"]), self.places)
@@ -57,7 +57,7 @@ def test_neutron_fractions(self):
5757
"""test_neutron_fractions -- check phase fractions in neutron dataset."""
5858
self.P.setdata(2)
5959
ph = self.P.phase_fractions()
60-
bb1 = 10.31 ** 2
60+
bb1 = 10.31**2
6161
bPb = 9.4012
6262
bO = 5.8054
6363
bSc = 12.11

diffpy/pdffit2/tests/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def testsuite(pattern=""):
3535
The TestSuite object containing the matching tests.
3636
"""
3737
import re
38-
from os.path import dirname
3938
from itertools import chain
39+
from os.path import dirname
40+
4041
from pkg_resources import resource_filename
4142

4243
loader = unittest.defaultTestLoader

diffpy/pdffit2/tests/debug.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
if __name__ == "__main__":
2727
import sys
28+
2829
from diffpy.pdffit2.tests import testsuite
2930

3031
pattern = sys.argv[1] if len(sys.argv) > 1 else ""

diffpy/pdffit2/tests/pdffit2testutils.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020

2121
import os.path
22+
2223
import six
24+
2325
import diffpy.pdffit2
2426

2527
# silence the C++ engine output

diffpy/pdffit2/tests/rundeps.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
if __name__ == "__main__":
2323
import sys
24+
2425
from diffpy.pdffit2.tests import testdeps
2526

2627
# produce zero exit code for a successful test

diffpy/pdffit2/tests/testdata/300K.gr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
History written: Fri Apr 30 13:05:36 2004
2-
produced by
2+
produced by
33
##### Run Information runCorrection=T
44
prep=gsas machine=npdf
55
run=300K background=npdf_00907
@@ -27,12 +27,12 @@ density= effDensity=3.4138
2727

2828
##### Banks=6 deltaQ=0.01 matchRef=0 matchScal=T matchOffset=T
2929
bank angle blendQmin blendQmax (0.0 means no info)
30-
1 90.0 1.62 29.42
31-
2 -90.0 1.62 29.42
32-
3 119.0 1.97 35.85
33-
4 -119.0 1.97 35.85
34-
5 148.0 2.20 40.00
35-
6 -148.0 2.20 40.00
30+
1 90.0 1.62 29.42
31+
2 -90.0 1.62 29.42
32+
3 119.0 1.97 35.85
33+
4 -119.0 1.97 35.85
34+
5 148.0 2.20 40.00
35+
6 -148.0 2.20 40.00
3636

3737
##### Program Specific Information
3838
## Ft calcError=1 (1 for true, 0 for false)

diffpy/pdffit2/version.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
from pkg_resources import resource_filename
3030

31-
3231
# obtain version information from the version.cfg file
3332
cp = dict(version="", date="", commit="", timestamp="0")
3433
fcfg = resource_filename(__name__, "version.cfg")

0 commit comments

Comments
 (0)