Skip to content

Commit 001c684

Browse files
authored
Merge pull request #10 from chiahaoliu/CLN_history_v2
CLN: test and repo structure
2 parents 6b1816f + 112dbf4 commit 001c684

29 files changed

+164
-51
lines changed

.travis.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
language: python
2+
sudo: false
3+
4+
cache:
5+
directories:
6+
- $HOME/.cache/pip
7+
- $HOME/.cache/matplotlib
8+
9+
python:
10+
- 2.7
11+
- 3.5
12+
- 3.6
13+
14+
before_install:
15+
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
16+
- chmod +x miniconda.sh
17+
- ./miniconda.sh -b -p ~/mc
18+
- export PATH=~/mc/bin:$PATH
19+
- conda config --add channels conda-forge
20+
- conda config --set always_yes yes --set changeps1 no --set quiet true
21+
- conda update conda --yes
22+
23+
install:
24+
- export GIT_FULL_HASH=`git rev-parse HEAD`
25+
- conda create --yes -n testenv python=$TRAVIS_PYTHON_VERSION
26+
- source activate testenv
27+
- conda install --yes --file requirements/build.txt
28+
- conda install pip
29+
- pip install -r requirements/pip.txt
30+
- python setup.py install
31+
- git clean -xfd
32+
33+
script:
34+
- set -e
35+
- conda install --yes --file requirements/run.txt
36+
- conda install --yes --file requirements/test.txt
37+
- coverage run run_tests.py
38+
- coverage report -m
39+
- codecov
40+
# - |
41+
# if [ $TRAVIS_PYTHON_VERSION = "3.6" ]; then
42+
# conda install --yes --file requirements/docs.txt
43+
# cd doc
44+
# make html
45+
# cd ..
46+
# doctr deploy . --built-docs ./docs/_build/html;
47+
# fi
48+
49+
after_script:
50+
- set +e
51+
- flake8 diffpy

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
==========================
2+
diffpy.pdfmorph Change Log
3+
==========================
4+
5+
.. current developments
6+

diffpy/pdfmorph/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
__id__ = "$Id$"
2020

2121
# obtain version information
22-
from diffpy.pdfmorph.version import __version__
22+
__version__ = '1.0'
2323

2424
# End of file

diffpy/pdfmorph/morphs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
MorphISpheroid, MorphResolutionDamping, MorphShift]
3939

4040
# obtain version information
41-
from diffpy.pdfmorph.version import __version__
41+
from diffpy.pdfmorph import __version__
4242

4343
# End of file

diffpy/pdfmorph/morphs/morph.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ class Morph(object):
8989
(self.xobjout, self.yobjout, self.xrefout, self.yrefout),
9090
doc='Return a tuple of all output arrays')
9191

92-
def __init__(self, config = {}):
92+
def __init__(self, config=None):
9393
'''Create a default Morph instance.
9494
9595
config -- dictionary that contains all configuration variables
9696
'''
9797
# declare empty attributes
98+
if config is None:
99+
config = {}
98100
self.xobjin = None
99101
self.yobjin = None
100102
self.xobjout = None
@@ -205,7 +207,6 @@ def __getattr__(self, name):
205207
else:
206208
emsg = 'Object has no attribute %r' % name
207209
raise AttributeError(emsg)
208-
return
209210

210211

211212
def __setattr__(self, name, val):

diffpy/pdfmorph/morphs/morphchain.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def __getattr__(self, name):
134134
else:
135135
emsg = 'Object has no attribute %r' % name
136136
raise AttributeError(emsg)
137-
return
138137

139138

140139
def __setattr__(self, name, val):

diffpy/pdfmorph/morphs/morphsmear.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def morph(self, xobj, yobj, xref, yref):
5555
# later.
5656
r = self.xobjin
5757
rr = self.yobjin
58-
r0 = r[len(r) / 2]
58+
r0 = r[len(r) // 2]
5959
gaussian = numpy.exp(-0.5 * ((r - r0)/self.smear)**2 )
6060

6161
# Get the full convolution

diffpy/pdfmorph/pdfmorphapp.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import os
1818
import os.path
1919

20-
20+
import numpy
2121
from diffpy.pdfmorph import __version__
2222
import diffpy.pdfmorph.tools as tools
2323
import diffpy.pdfmorph.pdfplot as pdfplot
@@ -214,12 +214,12 @@ def main():
214214
rptemp.append("scale")
215215
refiner.refine(*rptemp)
216216
refiner.refine(*refpars)
217-
except ValueError, e:
217+
except ValueError as e:
218218
parser.error(str(e))
219219
elif "smear" in refpars and opts.baselineslope is None:
220220
try:
221221
refiner.refine("baselineslope", baselineslope = -0.5)
222-
except ValueError, e:
222+
except ValueError as e:
223223
parser.error(str(e))
224224
else:
225225
chain(xobj, yobj, xref, yref)
@@ -231,12 +231,12 @@ def main():
231231
chain[0] = morphs.Morph()
232232
chain(xobj, yobj, xref, yref)
233233

234-
items = config.items()
234+
items = list(config.items())
235235
items.sort()
236236
output = "\n".join("# %s = %f"%i for i in items)
237237
output += "\n# Rw = %f" % rw
238238
output += "\n# Pearson = %f" % pcc
239-
print output
239+
print(output)
240240
if opts.savefile is not None:
241241
header = "# PDF created by pdfmorph\n"
242242
header += "# from %s\n" % os.path.abspath(pargs[0])
@@ -245,10 +245,10 @@ def main():
245245
if opts.savefile == "-":
246246
outfile = sys.stdout
247247
else:
248-
outfile = file(opts.savefile, 'w')
249-
print >> outfile, header
250-
import numpy
251-
numpy.savetxt(outfile, zip(chain.xobjout, chain.yobjout))
248+
outfile = open(opts.savefile, 'w')
249+
print(header, file=outfile)
250+
numpy.savetxt(outfile, numpy.transpose([chain.xobjout,
251+
chain.yobjout]))
252252
outfile.close()
253253

254254
if opts.plot:
@@ -269,11 +269,11 @@ def getPDFFromFile(fn):
269269
from diffpy.pdfmorph.tools import readPDF
270270
try:
271271
r, gr = readPDF(fn)
272-
except IOError, (errno, errmsg):
273-
print >> sys.stderr, "%s: %s" % (fn, errmsg)
272+
except IOError as (errno, errmsg):
273+
print("%s: %s" % (fn, errmsg), file=sys.stderr)
274274
sys.exit(1)
275-
except ValueError, errmsg:
276-
print >> sys.stderr, "Cannot read %s" % fn
275+
except ValueError as errmsg:
276+
print("Cannot read %s" % fn, file=sys.stderr)
277277
sys.exit(1)
278278

279279
return r, gr

diffpy/pdfmorph/pdfplot.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# FIXME - make this return the figure object in the future, so several views
2121
# can be composed.
22-
def plotPDFs(pairlist, labels = [], offset = 'auto', rmin = None, rmax = None):
22+
def plotPDFs(pairlist, labels=None, offset ='auto', rmin = None, rmax = None):
2323
"""Plots several PDFs on top of one another.
2424
2525
pairlist -- iterable of (r, gr) pairs to plot
@@ -36,6 +36,8 @@ def plotPDFs(pairlist, labels = [], offset = 'auto', rmin = None, rmax = None):
3636
upper bound of the PDF is not altered.
3737
3838
"""
39+
if labels is None:
40+
labels = []
3941
if offset is 'auto':
4042
offset = _findOffset(pairlist)
4143

@@ -59,8 +61,8 @@ def plotPDFs(pairlist, labels = [], offset = 'auto', rmin = None, rmax = None):
5961
pylab.show()
6062
return
6163

62-
def comparePDFs(pairlist, labels = [], rmin = None, rmax = None, show = True,
63-
maglim = None, mag = 5, rw = None, legend = True):
64+
def comparePDFs(pairlist, labels=None, rmin = None, rmax = None, show = True,
65+
maglim = None, mag = 5, rw = None, legend = True):
6466
"""Plot two PDFs on top of each other and difference curve.
6567
6668
pairlist -- iterable of (r, gr) pairs to plot
@@ -82,6 +84,8 @@ def comparePDFs(pairlist, labels = [], rmin = None, rmax = None, show = True,
8284
line. The difference curve will be in green and offset for clarity.
8385
8486
"""
87+
if labels is None:
88+
labels = []
8589
rfit, grfit = pairlist[0]
8690
rdat, grdat = pairlist[1]
8791
labeldata = labels[1]

news/TEMPLATE.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
**Added:** None
2+
3+
**Changed:** None
4+
5+
**Deprecated:** None
6+
7+
**Removed:** None
8+
9+
**Fixed:** None
10+
11+
**Security:** None

0 commit comments

Comments
 (0)