Skip to content

Commit 03b4432

Browse files
committed
Merge branch 'support-py2-and-py3'
* make sources Python-3 compatible * keep compatibility with Python 2 using the `six` tool * add homebrew CI-test on travis
2 parents 5abcd37 + 7aab3fe commit 03b4432

Some content is hidden

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

68 files changed

+611
-484
lines changed

.travis.yml

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Use container-based travis workers
2-
sudo: false
3-
1+
dist: xenial
42
language: generic
53

64
os:
@@ -9,37 +7,35 @@ os:
97

108
env:
119
- MYUSEMC=true MYPYTHON_VERSION=2.7
10+
- MYUSEMC=true MYPYTHON_VERSION=3.5
11+
- MYUSEMC=true MYPYTHON_VERSION=3.6
12+
- MYUSEMC=true MYPYTHON_VERSION=3.7
1213
- MYUSEMC=false
1314

14-
matrix:
15-
exclude:
16-
- os: osx
17-
env: MYUSEMC=false
18-
1915
git:
2016
depth: 999999
2117

2218
branches:
2319
except:
2420
- /^v[0-9]/
2521

26-
addons:
27-
apt:
28-
packages:
29-
- python-dev
30-
- python-numpy
31-
- python-setuptools
32-
- build-essential
3322

3423
before_install:
3524
- MYNAME=diffpy.srfit
3625
- MYCOMMIT="$(git rev-parse HEAD)"
3726
- umask 022
3827
- git fetch origin --tags
28+
- MYPYTHON=python; MYPIP=pip
29+
- NOSYS=true; NOAPT=true; NOBREW=true; NOMC=true
3930
- if ${MYUSEMC}; then
40-
NOAPT=true; NOMC=false;
41-
else
42-
NOAPT=false; NOMC=true;
31+
NOMC=false;
32+
elif [[ ${TRAVIS_OS_NAME} == linux ]]; then
33+
NOAPT=false; NOSYS=false;
34+
MYPIPFLAGS="--user";
35+
elif [[ ${TRAVIS_OS_NAME} == osx ]]; then
36+
NOBREW=false; NOSYS=false;
37+
MYPYTHON=python3;
38+
MYPIP=pip3;
4339
MYPIPFLAGS="--user";
4440
fi
4541
- MYMCREPO=https://repo.continuum.io/miniconda
@@ -72,8 +68,19 @@ before_install:
7268
- $NOAPT || PATH="$(echo "$PATH" | sed 's,:/opt/pyenv/[^:]*,,g')"
7369
- $NOAPT || test "$(which python)" = "/usr/bin/python" || (
7470
which python; exit 1)
75-
- $NOAPT || devutils/makesdist
76-
- $NOAPT || MYTARBUNDLE="$(ls -t "${PWD}"/dist/*.tar.gz | head -1)"
71+
- $NOAPT || sudo apt-get update -qq
72+
- $NOAPT || sudo apt-get install -y
73+
python-dev python-setuptools python-numpy
74+
build-essential
75+
76+
- $NOBREW || test "${TRAVIS_OS_NAME}" = "osx" || exit $?
77+
- $NOBREW || brew update
78+
- $NOBREW || brew upgrade python
79+
- $NOBREW || brew install gcc || brew link --overwrite gcc
80+
81+
- $NOSYS || devutils/makesdist
82+
- $NOSYS || MYTARBUNDLE="$(ls -t "${PWD}"/dist/*.tar.gz | head -1)"
83+
7784

7885
install:
7986
- $NOMC || conda build --python=${MYPYTHON_VERSION} conda-recipe
@@ -82,23 +89,35 @@ install:
8289
- $NOMC || source activate testenv
8390
- $NOMC || conda install --yes --use-local --file=/tmp/mypackage.txt
8491
- $NOMC || conda install --yes
85-
diffpy.structure pyobjcryst diffpy.srreal srfit-sasview
92+
diffpy.structure pyobjcryst diffpy.srreal
93+
# TODO - always install srfit-sasview when ready for Python 3.
94+
- if $MYUSEMC && [[ "$MYPYTHON_VERSION" == 2.7 ]]; then
95+
conda install --yes srfit-sasview;
96+
fi
8697

87-
- $NOAPT || pip install $MYPIPFLAGS coverage
88-
- $NOAPT || easy_install --user diffpy.Structure
89-
- $NOAPT || easy_install --user "${MYTARBUNDLE}"
98+
- $NOSYS || $MYPIP install $MYPIPFLAGS coverage
99+
- $NOSYS || $MYPIP install $MYPIPFLAGS pycifrw
100+
- $NOSYS || $MYPIP install $MYPIPFLAGS diffpy.structure
101+
- $NOSYS || $MYPIP install $MYPIPFLAGS "${MYTARBUNDLE}"
90102

91103
- cd ${MYRUNDIR}
92-
- MYGIT_REV=$(python -c "import ${MYNAME}.version as v; print(v.__git_commit__)")
104+
- MYGIT_REV=$($MYPYTHON -c "import ${MYNAME}.version as v; print(v.__git_commit__)")
93105
- if [[ "${MYCOMMIT}" != "${MYGIT_REV}" ]]; then
94106
echo "Version mismatch ${MYCOMMIT} vs ${MYGIT_REV}.";
95107
exit 1;
96108
fi
97109

110+
111+
before_script:
112+
- $NOBREW || USER_BASE="$(python3 -c 'import site; print(site.USER_BASE)')"
113+
- $NOBREW || PATH="${USER_BASE}/bin:${PATH}"
114+
115+
98116
script:
99117
- coverage run --source ${MYNAME} -m ${MYNAME}.tests.run
100118

119+
101120
after_success:
102121
# do not post coverage reports when testing with system Python.
103-
- $NOMC || pip install $MYPIPFLAGS codecov
122+
- $NOMC || $MYPIP install $MYPIPFLAGS codecov
104123
- $NOMC || codecov

README.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. image:: https://travis-ci.org/diffpy/diffpy.srfit.svg?branch=master
22
:target: https://travis-ci.org/diffpy/diffpy.srfit
33

4-
.. image:: http://codecov.io/github/diffpy/diffpy.srfit/coverage.svg?branch=master
5-
:target: http://codecov.io/github/diffpy/diffpy.srfit?branch=master
4+
.. image:: https://codecov.io/gh/diffpy/diffpy.srfit/branch/master/graph/badge.svg
5+
:target: https://codecov.io/gh/diffpy/diffpy.srfit/branch/master
66

77

88
diffpy.srfit
@@ -38,7 +38,8 @@ http://diffpy.github.io/diffpy.srfit.
3838
REQUIREMENTS
3939
------------------------------------------------------------------------
4040

41-
The diffpy.srfit package requires Python 2.7 and the following software:
41+
The diffpy.srfit package requires Python 3.5 or later or 2.7 and
42+
the following software:
4243

4344
* ``setuptools`` - software distribution tools for Python
4445
* ``NumPy`` - numerical mathematics and fast array operations for Python
@@ -49,8 +50,8 @@ Recommended software:
4950

5051
Optimizations involving crystal structures or molecules require
5152

52-
* ``diffpy.Structure`` - crystal structure container and parsers,
53-
https://github.com/diffpy/diffpy.Structure
53+
* ``diffpy.structure`` - crystal structure container and parsers,
54+
https://github.com/diffpy/diffpy.structure
5455
* ``pyobjcryst`` - Crystal and Molecule storage, rigid units, bond
5556
length and bond angle restraints, https://github.com/diffpy/pyobjcryst
5657

@@ -73,7 +74,7 @@ install the required software separately. As an example, on Ubuntu
7374
Linux some of the required software can be installed using ::
7475

7576
sudo apt-get install \
76-
python-setuptools python-numpy python-scipy python-matplotlib
77+
python3-setuptools python3-numpy python3-scipy python3-matplotlib
7778

7879
For other required packages see their respective web pages for installation
7980
instructions.

conda-recipe/meta.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ requirements:
1818
build:
1919
- python
2020
- setuptools
21+
- six
2122

2223
run:
2324
- python
2425
- setuptools
2526
- numpy >=1.3
27+
- six
2628

2729
test:
2830
# Python imports
@@ -51,7 +53,8 @@ test:
5153
- diffpy.structure
5254
- pyobjcryst
5355
- diffpy.srreal
54-
- srfit-sasview
56+
# FIXME - correct when packages become available for Python 3.
57+
- srfit-sasview # [py2k]
5558

5659
about:
5760
home: https://github.com/diffpy/diffpy.srfit/

doc/examples/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Advanced:
9494
instructive extension to gaussianrecipe.py_.
9595

9696
* npintensity.py_
97-
Use diffpy.Structure to build a nanoparticle intensity generator, and use
97+
Use diffpy.structure to build a nanoparticle intensity generator, and use
9898
it to refine a structure to simulated data.
9999

100100
* npintensityII.py_
@@ -111,7 +111,7 @@ should read through these use cases to gain an understanding of PDF and SAS
111111
refinement with SrFit.
112112

113113
* crystalpdf.py_
114-
Refine a diffpy.Structure crystal to PDF data using automatic explicit
114+
Refine a diffpy.structure crystal to PDF data using automatic explicit
115115
space group constraints.
116116

117117
* simplepdf.py_

doc/examples/crystalpdf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See LICENSE_DANSE.txt for license information.
1313
#
1414
########################################################################
15-
"""Example of a PDF refinement using diffpy.Structure and PDFGenerator.
15+
16+
"""Example of a PDF refinement using diffpy.structure and PDFGenerator.
1617
1718
This is example of fitting the fcc nickel structure to measured PDF data. The
1819
purpose of this example is to demonstrate and describe the classes in
@@ -26,7 +27,7 @@
2627

2728
import numpy
2829

29-
from diffpy.Structure import Structure
30+
from diffpy.structure import Structure
3031
from diffpy.srfit.pdf import PDFGenerator, PDFParser
3132
from diffpy.srfit.fitbase import Profile
3233
from diffpy.srfit.fitbase import FitContribution, FitRecipe
@@ -56,7 +57,7 @@ def makeRecipe(ciffile, datname):
5657

5758
## The ProfileGenerator
5859
# The PDFGenerator is for configuring and calculating a PDF profile. Here,
59-
# we want to refine a Structure object from diffpy.Structure. We tell the
60+
# we want to refine a Structure object from diffpy.structure. We tell the
6061
# PDFGenerator that with the 'setStructure' method. All other configuration
6162
# options will be inferred from the metadata that is read by the PDFParser.
6263
# In particular, this will set the scattering type (x-ray or neutron), the

doc/examples/npintensity.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class IntensityGenerator(ProfileGenerator):
5959
"""A class for calculating intensity using the Debye equation.
6060
6161
Calculating intensity from a structure is difficult in general. This class
62-
takes a diffpy.Structure.Structure instance and from that generates a
62+
takes a diffpy.structure.Structure instance and from that generates a
6363
theoretical intensity signal. Unlike the example in gaussianrecipe.py, the
6464
intensity generator is not simple. It must take a structure object and some
6565
Parameters, and from that generate a signal. At the same time, the
@@ -93,7 +93,7 @@ def setStructure(self, strufile):
9393
"""Set the structure used in the calculation.
9494
9595
strufile -- The name of a structure file. A
96-
diffpy.Structure.Structure object will be created from
96+
diffpy.structure.Structure object will be created from
9797
the file, and that object will be passed to the 'iofq'
9898
function whenever it is called.
9999
@@ -102,7 +102,7 @@ def setStructure(self, strufile):
102102
DiffpyStructureParSet is a ParameterSet object that organizes and gives
103103
attribute access to Parameters and ParameterSets adapted from a diffpy
104104
Structure object. The Parameters embedded in the DiffpyStructureParSet
105-
are proxies for attributes of the diffpy.Structure.Structure object
105+
are proxies for attributes of the diffpy.structure.Structure object
106106
that is needed by the 'iofq' function. The Parameters will be
107107
accessible by name under the 'phase' attribute of this generator, and
108108
are organized hierarchically:
@@ -130,21 +130,21 @@ def setStructure(self, strufile):
130130
- Uiso
131131
- etc.
132132
133-
The diffpy.Structure.Structure instance is held within the
133+
The diffpy.structure.Structure instance is held within the
134134
DiffpyStructureParSet as the 'stru' attribute.
135135
136136
"""
137137
# Load the structure from file
138-
from diffpy.Structure import Structure
138+
from diffpy.structure import Structure
139139
stru = Structure()
140140
stru.read(strufile)
141141

142142
# Create a ParameterSet designed to interface with
143-
# diffpy.Structure.Structure objects that organizes the Parameter
143+
# diffpy.structure.Structure objects that organizes the Parameter
144144
# hierarchy. Note that the DiffpyStructureParSet holds a handle to the
145145
# loaded structure that we use in the __call__ method below.
146146
#
147-
# We pass the diffpy.Structure.Structure instance, and give the
147+
# We pass the diffpy.structure.Structure instance, and give the
148148
# DiffpyStructureParSet the name "phase".
149149
parset = DiffpyStructureParSet("phase", stru)
150150

@@ -158,7 +158,7 @@ def __call__(self, q):
158158
159159
This ProfileGenerator will be used in a FitContribution that will be
160160
optimized to fit some data. By the time this function is evaluated,
161-
the diffpy.Structure.Structure instance has been updated by the
161+
the diffpy.structure.Structure instance has been updated by the
162162
optimizer via the DiffpyStructureParSet defined in setStructure. Thus,
163163
we need only call iofq with the internal structure object.
164164
@@ -353,7 +353,7 @@ def iofq(S, q):
353353
I(Q) = 2 sum(i,j) f_i(Q) f_j(Q) sinc(rij Q) exp(-0.5 ssij Q**2)
354354
(The exponential term is the Debye-Waller factor.)
355355
356-
S -- A diffpy.Structure.Structure instance. It is assumed that the
356+
S -- A diffpy.structure.Structure instance. It is assumed that the
357357
structure is that of an isolated scatterer. Periodic boundary
358358
conditions are not applied.
359359
q -- The q-points to calculate over.
@@ -378,14 +378,14 @@ def iofq(S, q):
378378
pairdict = {}
379379
elcount = {}
380380
n = len(S)
381-
for i in xrange(n):
381+
for i in range(n):
382382

383383
# count the number of each element
384384
eli = S[i].element
385385
m = elcount.get(eli, 0)
386386
elcount[eli] = m + 1
387387

388-
for j in xrange(i+1,n):
388+
for j in range(i + 1, n):
389389

390390
elj = S[j].element
391391

@@ -473,7 +473,7 @@ def makeData(strufile, q, datname, scale, a, Uiso, sig, bkgc, nl = 1):
473473
474474
"""
475475

476-
from diffpy.Structure import Structure
476+
from diffpy.structure import Structure
477477
S = Structure()
478478
S.read(strufile)
479479

@@ -507,7 +507,7 @@ def makeData(strufile, q, datname, scale, a, Uiso, sig, bkgc, nl = 1):
507507
y = numpy.random.poisson(y*nl) / nl
508508

509509
# Now save it
510-
numpy.savetxt(datname, zip(q, y, u))
510+
numpy.savetxt(datname, numpy.transpose([q, y, u]))
511511
return
512512

513513

doc/examples/simplepdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
It uses the PDFContribution class to simplify fit setup.
2020
"""
2121

22-
from diffpy.Structure import Structure
22+
from diffpy.structure import Structure
2323
from diffpy.srfit.pdf import PDFContribution
2424
from diffpy.srfit.fitbase import FitRecipe, FitResults
2525

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Use this version when git data are not available, like in git zip archive.
1616
# Update when tagging a new release.
17-
FALLBACK_VERSION = '1.3.post0'
17+
FALLBACK_VERSION = '3.0a0.post0'
1818

1919
# determine if we run with Python 3.
2020
PY3 = (sys.version_info[0] == 3)
@@ -85,7 +85,7 @@ def getversioncfg():
8585
package_dir = {'' : 'src'},
8686
test_suite = 'diffpy.srfit.tests',
8787
include_package_data = True,
88-
install_requires = [],
88+
install_requires = ['six'],
8989
zip_safe = False,
9090
author = "Simon J.L. Billinge",
9191
author_email = "[email protected]",
@@ -107,6 +107,9 @@ def getversioncfg():
107107
'Operating System :: MacOS',
108108
'Operating System :: POSIX',
109109
'Programming Language :: Python :: 2.7',
110+
'Programming Language :: Python :: 3.5',
111+
'Programming Language :: Python :: 3.6',
112+
'Programming Language :: Python :: 3.7',
110113
'Topic :: Scientific/Engineering :: Chemistry',
111114
'Topic :: Scientific/Engineering :: Physics',
112115
'Topic :: Software Development :: Libraries',

0 commit comments

Comments
 (0)