Skip to content

Commit f18bfbb

Browse files
authored
Merge pull request #121 from cadenmyers13/pre-commit
add flake8, pre-commit, pyproject files
2 parents 69b9868 + 6eb7215 commit f18bfbb

File tree

113 files changed

+13752
-14176
lines changed

Some content is hidden

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

113 files changed

+13752
-14176
lines changed

.flake8

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[flake8]
2+
exclude =
3+
.git,
4+
__pycache__,
5+
build,
6+
dist,
7+
doc/source/conf.py
8+
max-line-length = 115
9+
# Ignore some style 'errors' produced while formatting by 'black'
10+
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#labels-why-pycodestyle-warnings
11+
extend-ignore = E203

.pre-commit-config.yaml

Lines changed: 43 additions & 0 deletions
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]

conda-recipe/expandpdfguibase.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
import sys
4+
45
from pkg_resources import Requirement, resource_filename
56

67
pkg = Requirement.parse("diffpy.pdfgui")

devutils/makesdist

Lines changed: 22 additions & 16 deletions
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

pyproject.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[tool.black]
2+
line-length = 115
3+
include = '\.pyi?$'
4+
exclude = '''
5+
/(
6+
\.git
7+
| \.hg
8+
| \.mypy_cache
9+
| \.tox
10+
| \.venv
11+
| \.rst
12+
| \.txt
13+
| _build
14+
| buck-out
15+
| build
16+
| dist
17+
18+
# The following are specific to Black, you probably don't want those.
19+
| blib2to3
20+
| tests/data
21+
)/
22+
'''

setup.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import os
1212
import re
1313
import sys
14-
from setuptools import setup, find_packages
14+
15+
from setuptools import find_packages, setup
1516

1617
# Use this version when git data are not available, like in git zip archive.
1718
# Update when tagging a new release.
@@ -28,7 +29,7 @@
2829

2930

3031
def gitinfo():
31-
from subprocess import Popen, PIPE
32+
from subprocess import PIPE, Popen
3233

3334
kw = dict(stdout=PIPE, cwd=MYDIR, universal_newlines=True)
3435
proc = Popen(["git", "describe", "--tags", "--match=v[[:digit:]]*"], **kw)
@@ -67,10 +68,7 @@ def getversioncfg():
6768
cp = RawConfigParser()
6869
cp.read(versioncfgfile)
6970
d = cp.defaults()
70-
rewrite = not d or (
71-
g["commit"]
72-
and (g["version"] != d.get("version") or g["commit"] != d.get("commit"))
73-
)
71+
rewrite = not d or (g["commit"] and (g["version"] != d.get("version") or g["commit"] != d.get("commit")))
7472
if rewrite:
7573
cp.set("DEFAULT", "version", g["version"])
7674
cp.set("DEFAULT", "commit", g["commit"])

src/diffpy/pdfgui/applications/pdfgui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434

3535
from __future__ import print_function
3636

37-
import sys
38-
import os
3937
import getopt
38+
import os
39+
import sys
4040

4141

4242
def usage():

src/diffpy/pdfgui/control/calculation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import copy
2020
import math
2121

22-
from diffpy.pdfgui.control.controlerrors import ControlConfigError
23-
from diffpy.pdfgui.control.controlerrors import ControlKeyError
24-
from diffpy.pdfgui.control.controlerrors import ControlValueError
22+
from diffpy.pdfgui.control.controlerrors import (
23+
ControlConfigError,
24+
ControlKeyError,
25+
ControlValueError,
26+
)
2527
from diffpy.pdfgui.control.pdfcomponent import PDFComponent
26-
from diffpy.pdfgui.utils import safeCPickleDumps, pickle_loads
28+
from diffpy.pdfgui.utils import pickle_loads, safeCPickleDumps
2729

2830

2931
class Calculation(PDFComponent):

src/diffpy/pdfgui/control/constraint.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
constraints will be stored in { variable : constraint } dictionary
1818
"""
1919

20-
import re
2120
import math
21+
import re
2222

2323
from diffpy.pdfgui.control.controlerrors import ControlSyntaxError
2424

@@ -135,9 +135,7 @@ def __setattr__(self, name, value):
135135
raise ControlSyntaxError(message)
136136
# few more checks of the formula:
137137
if newformula.find("**") != -1:
138-
emsg = (
139-
"invalid constraint formula '{}', " "operator '**' not supported."
140-
).format(newformula)
138+
emsg = ("invalid constraint formula '{}', " "operator '**' not supported.").format(newformula)
141139
raise ControlSyntaxError(emsg)
142140
# checks checked
143141
self.__dict__["formula"] = newformula

src/diffpy/pdfgui/control/fitdataset.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
"""
1818

1919
import copy
20+
2021
import numpy
2122

22-
from diffpy.pdfgui.control.pdfdataset import PDFDataSet
23-
from diffpy.pdfgui.control.parameter import Parameter
2423
from diffpy.pdfgui.control.controlerrors import ControlStatusError
24+
from diffpy.pdfgui.control.parameter import Parameter
25+
from diffpy.pdfgui.control.pdfdataset import PDFDataSet
2526

2627

2728
class FitDataSet(PDFDataSet):
@@ -112,9 +113,7 @@ def getYNames(self):
112113
113114
returns list of strings
114115
"""
115-
ynames = ["Gobs", "Gcalc", "Gdiff", "Gtrunc", "dGcalc", "crw"] + list(
116-
self.constraints.keys()
117-
)
116+
ynames = ["Gobs", "Gcalc", "Gdiff", "Gtrunc", "dGcalc", "crw"] + list(self.constraints.keys())
118117
return ynames
119118

120119
def getXNames(self):
@@ -321,10 +320,7 @@ def writeCalcStr(self):
321320
Gdiff = self.Gdiff
322321
drcalc = 0.0
323322
for i in range(len(self.rcalc)):
324-
lines.append(
325-
"%g %g %.1f %g %g"
326-
% (self.rcalc[i], self.Gcalc[i], drcalc, self.dGcalc[i], Gdiff[i])
327-
)
323+
lines.append("%g %g %.1f %g %g" % (self.rcalc[i], self.Gcalc[i], drcalc, self.dGcalc[i], Gdiff[i]))
328324
# lines are ready here
329325
datastring = "\n".join(lines) + "\n"
330326
return datastring
@@ -636,9 +632,7 @@ def _set_fitrmin(self, value):
636632
self._fitrmin = float(value)
637633
return
638634

639-
fitrmin = property(
640-
_get_fitrmin, _set_fitrmin, doc="Lower boundary for simulated PDF curve."
641-
)
635+
fitrmin = property(_get_fitrmin, _set_fitrmin, doc="Lower boundary for simulated PDF curve.")
642636

643637
# fitrmax
644638

@@ -650,9 +644,7 @@ def _set_fitrmax(self, value):
650644
self._fitrmax = float(value)
651645
return
652646

653-
fitrmax = property(
654-
_get_fitrmax, _set_fitrmax, doc="Upper boundary for simulated PDF curve."
655-
)
647+
fitrmax = property(_get_fitrmax, _set_fitrmax, doc="Upper boundary for simulated PDF curve.")
656648

657649
# fitrstep
658650

@@ -664,9 +656,7 @@ def _set_fitrstep(self, value):
664656
self._fitrstep = float(value)
665657
return
666658

667-
fitrstep = property(
668-
_get_fitrstep, _set_fitrstep, doc="R-step used for simulated PDF curve."
669-
)
659+
fitrstep = property(_get_fitrstep, _set_fitrstep, doc="R-step used for simulated PDF curve.")
670660

671661
# rcalc
672662

@@ -707,9 +697,7 @@ def _set_dGcalc(self, value):
707697
self._dGcalc = value
708698
return
709699

710-
dGcalc = property(
711-
_get_dGcalc, _set_dGcalc, doc="List of standard deviations of Gcalc."
712-
)
700+
dGcalc = property(_get_dGcalc, _set_dGcalc, doc="List of standard deviations of Gcalc.")
713701

714702
# Gtrunc
715703

@@ -757,9 +745,7 @@ def _get_Gdiff(self):
757745
rv = []
758746
return rv
759747

760-
Gdiff = property(
761-
_get_Gdiff, doc="Difference between observed and calculated PDF on rcalc grid."
762-
)
748+
Gdiff = property(_get_Gdiff, doc="Difference between observed and calculated PDF on rcalc grid.")
763749

764750
# crw
765751
def _get_crw(self):

0 commit comments

Comments
 (0)