Skip to content

Commit 6eb7215

Browse files
[pre-commit.ci] auto fixes from pre-commit hooks
1 parent 0974ca1 commit 6eb7215

File tree

110 files changed

+13676
-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.

110 files changed

+13676
-14176
lines changed

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

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):

src/diffpy/pdfgui/control/fitstructure.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

1919
import copy
2020
import re
21+
2122
import numpy
2223

23-
from diffpy.pdfgui.control.pdfstructure import PDFStructure
2424
from diffpy.pdfgui.control.constraint import Constraint
25-
from diffpy.pdfgui.control.parameter import Parameter
2625
from diffpy.pdfgui.control.controlerrors import ControlTypeError, ControlValueError
26+
from diffpy.pdfgui.control.parameter import Parameter
27+
from diffpy.pdfgui.control.pdfstructure import PDFStructure
2728
from diffpy.structure import Atom
2829

2930

@@ -309,12 +310,7 @@ def expandSuperCell(self, mno):
309310
# back to business
310311
acd = self._popAtomConstraints()
311312
mnofloats = numpy.array(mno[:3], dtype=float)
312-
ijklist = [
313-
(i, j, k)
314-
for i in range(mno[0])
315-
for j in range(mno[1])
316-
for k in range(mno[2])
317-
]
313+
ijklist = [(i, j, k) for i in range(mno[0]) for j in range(mno[1]) for k in range(mno[2])]
318314
# build a list of new atoms
319315
newatoms = []
320316
for a in self.initial:
@@ -389,9 +385,7 @@ def getSpaceGroupList(self):
389385
existing_names[sg.short_name] = True
390386
# sort by International Tables number, stay compatible with 2.3
391387
n_sg = [(sg.number % 1000, sg) for sg in unique_named_list]
392-
n_sg = sorted(
393-
n_sg, key=lambda x: x[0]
394-
) # sort by the first element of tuple.
388+
n_sg = sorted(n_sg, key=lambda x: x[0]) # sort by the first element of tuple.
395389
FitStructure.sorted_standard_space_groups = [sg for n, sg in n_sg]
396390
sglist = list(FitStructure.sorted_standard_space_groups)
397391
if self.custom_spacegroup:
@@ -438,9 +432,7 @@ def expandAsymmetricUnit(self, spacegroup, indices, sgoffset=[0, 0, 0]):
438432
coreatoms = [self.initial[i] for i in ruindices]
439433
corepos = [a.xyz for a in coreatoms]
440434
coreUijs = [a.U for a in coreatoms]
441-
eau = ExpandAsymmetricUnit(
442-
spacegroup, corepos, coreUijs, sgoffset=sgoffset, eps=self.symposeps
443-
)
435+
eau = ExpandAsymmetricUnit(spacegroup, corepos, coreUijs, sgoffset=sgoffset, eps=self.symposeps)
444436
# build a nested list of new atoms:
445437
newatoms = []
446438
for i in range(len(coreatoms)):
@@ -469,9 +461,7 @@ def expandAsymmetricUnit(self, spacegroup, indices, sgoffset=[0, 0, 0]):
469461
self._restoreAtomConstraints(acd)
470462
return
471463

472-
def applySymmetryConstraints(
473-
self, spacegroup, indices, posflag, Uijflag, sgoffset=[0, 0, 0]
474-
):
464+
def applySymmetryConstraints(self, spacegroup, indices, posflag, Uijflag, sgoffset=[0, 0, 0]):
475465
"""Generate symmetry constraints for positions and thermal factors.
476466
Both positions and thermal factors may get corrected to reflect
477467
space group symmetry. Old positional and thermal constraints get
@@ -511,9 +501,7 @@ def applySymmetryConstraints(
511501
selatoms = [self.initial[i] for i in uindices]
512502
selpos = [a.xyz for a in selatoms]
513503
selUijs = [a.U for a in selatoms]
514-
symcon = SymmetryConstraints(
515-
spacegroup, selpos, selUijs, sgoffset=sgoffset, eps=self.symposeps
516-
)
504+
symcon = SymmetryConstraints(spacegroup, selpos, selUijs, sgoffset=sgoffset, eps=self.symposeps)
517505
# deal with positions
518506
if posflag:
519507
# fix positions:
@@ -762,8 +750,8 @@ def load(self, z, subpath):
762750
subpath -- path to its own storage within project file
763751
"""
764752
# subpath = projname/fitname/structure/myname/
765-
from diffpy.pdfgui.utils import asunicode
766753
from diffpy.pdfgui.control.pdfguicontrol import CtrlUnpickler
754+
from diffpy.pdfgui.utils import asunicode
767755

768756
subs = subpath.split("/")
769757
rootDict = z.fileTree[subs[0]][subs[1]][subs[2]][subs[3]]

src/diffpy/pdfgui/control/fitting.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,25 @@
1818
import threading
1919
import time
2020

21+
from diffpy.pdfgui.control.controlerrors import (
22+
ControlError,
23+
ControlStatusError,
24+
ControlValueError,
25+
)
2126
from diffpy.pdfgui.control.organizer import Organizer
22-
from diffpy.pdfgui.control.controlerrors import ControlError
23-
from diffpy.pdfgui.control.controlerrors import ControlStatusError
24-
from diffpy.pdfgui.control.controlerrors import ControlValueError
25-
from diffpy.pdfgui.utils import safeCPickleDumps, pickle_loads
27+
from diffpy.pdfgui.utils import pickle_loads, safeCPickleDumps
2628

2729
# helper routines to deal with PDFfit2 exceptions
2830

2931

3032
def getEngineExceptions():
3133
"""Return a tuple of possible exceptions from diffpy.pdffit2.pdffit2."""
3234
from diffpy.pdffit2.pdffit2 import (
33-
dataError,
34-
unassignedError,
35+
calculationError,
3536
constraintError,
37+
dataError,
3638
structureError,
37-
calculationError,
39+
unassignedError,
3840
)
3941

4042
engine_exceptions = (
@@ -212,9 +214,7 @@ def load(self, z, subpath):
212214

213215
self.parameters = CtrlUnpickler.loads(z.read(subpath + "parameters"))
214216
if "steps" in rootDict:
215-
self.itemIndex, self.dataNameDict, self.snapshots = pickle_loads(
216-
z.read(subpath + "steps")
217-
)
217+
self.itemIndex, self.dataNameDict, self.snapshots = pickle_loads(z.read(subpath + "steps"))
218218
if "result" in rootDict:
219219
self.rw, self.res = pickle_loads(z.read(subpath + "result"))
220220

@@ -582,9 +582,7 @@ def close(self, force=False):
582582
# way while user choose to stop forcefully
583583
else:
584584
if self.isThreadRunning():
585-
raise ControlStatusError(
586-
"Fitting: Fitting %s is still running" % self.name
587-
)
585+
raise ControlStatusError("Fitting: Fitting %s is still running" % self.name)
588586
if self.thread is not None:
589587
self.thread.join()
590588

0 commit comments

Comments
 (0)