Skip to content

Commit e21cebf

Browse files
committed
Merge branch 'support-python3'.
Add support for Python 3.4, 3.5, 3.6 and stay compatible with 2.7. Test all supported versions on travis with conda. Test Python 2.7 with Linux system Python and Python 3.6 with homebrew Python on Mac OS X.
2 parents e1d03ea + 1b59e5d commit e21cebf

33 files changed

Lines changed: 232 additions & 124 deletions

.travis.yml

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ os:
88

99
env:
1010
- MYUSEMC=true MYPYTHON_VERSION=2.7
11+
- MYUSEMC=true MYPYTHON_VERSION=3.4
12+
- MYUSEMC=true MYPYTHON_VERSION=3.5
13+
- MYUSEMC=true MYPYTHON_VERSION=3.6
1114
- MYUSEMC=false
1215

13-
matrix:
14-
exclude:
15-
- os: osx
16-
env: MYUSEMC=false
17-
1816
git:
1917
depth: 999999
2018

@@ -26,10 +24,17 @@ before_install:
2624
- MYNAME=diffpy.srreal
2725
- umask 022
2826
- git fetch origin --tags
27+
- MYPYTHON=python; MYPIP=pip
28+
- NOSYS=true; NOAPT=true; NOBREW=true; NOMC=true
2929
- if ${MYUSEMC}; then
30-
NOAPT=true; NOMC=false;
31-
else
32-
NOAPT=false; NOMC=true;
30+
NOMC=false;
31+
elif [[ ${TRAVIS_OS_NAME} == linux ]]; then
32+
NOAPT=false; NOSYS=false;
33+
MYPIPFLAGS="--user";
34+
elif [[ ${TRAVIS_OS_NAME} == osx ]]; then
35+
NOBREW=false; NOSYS=false;
36+
MYPYTHON=python3;
37+
MYPIP=pip3;
3338
MYPIPFLAGS="--user";
3439
fi
3540
- MYMCREPO=https://repo.continuum.io/miniconda
@@ -54,23 +59,36 @@ before_install:
5459
- $NOMC || popd
5560
- $NOMC || source ~/mc/bin/activate root
5661
- $NOMC || conda update --yes conda
57-
- $NOMC || conda install --yes conda-build jinja2
62+
- $NOMC || conda install --yes conda-build jinja2 scons numpy
63+
# Make scons available globally.
64+
- $NOMC || mkdir -p ~/bin
65+
- $NOMC || cp ~/mc/bin/scons ~/bin/
5866
- $NOMC || conda create --name=testenv --yes python=${MYPYTHON_VERSION} coverage
5967
- $NOMC || conda config --add channels diffpy
68+
# FIXME - keep just the "diffpy" channel for public release.
69+
- $NOMC || conda config --add channels diffpy/channel/dev
6070

6171
- $NOAPT || test "${TRAVIS_OS_NAME}" = "linux" || exit $?
6272
- $NOAPT || sudo apt-get update -qq
6373
- $NOAPT || sudo apt-get install -y
6474
libgsl0-dev libboost-all-dev python-dev
6575
python-setuptools python-numpy python-pyparsing
6676
python-lxml python-pip build-essential scons
67-
- $NOAPT || devutils/makesdist
68-
- $NOAPT || MYTARBUNDLE="$(ls -t "${PWD}"/dist/*.tar.gz | head -1)"
69-
- $NOAPT || pushd ~/pkgs
70-
- $NOAPT || git clone https://github.com/diffpy/libObjCryst.git
71-
- $NOAPT || git clone https://github.com/diffpy/libdiffpy.git
72-
- $NOAPT || popd
7377

78+
- $NOBREW || test "${TRAVIS_OS_NAME}" = "osx" || exit $?
79+
- $NOBREW || brew update
80+
- $NOBREW || brew install gsl
81+
- $NOBREW || brew install scons
82+
- $NOBREW || brew install python3
83+
- $NOBREW || brew install boost-python --with-python3
84+
- $NOBREW || brew install numpy --without-python --with-python3
85+
86+
- $NOSYS || devutils/makesdist
87+
- $NOSYS || MYTARBUNDLE="$(ls -t "${PWD}"/dist/*.tar.gz | head -1)"
88+
- $NOSYS || pushd ~/pkgs
89+
- $NOSYS || git clone https://github.com/diffpy/libObjCryst.git
90+
- $NOSYS || git clone https://github.com/diffpy/libdiffpy.git
91+
- $NOSYS || popd
7492

7593
install:
7694
- $NOMC || conda build --python=${MYPYTHON_VERSION} --dirty conda-recipe
@@ -80,25 +98,40 @@ install:
8098
- $NOMC || source activate testenv
8199
- $NOMC || conda install --yes --use-local --file=/tmp/mypackage.txt
82100

83-
- $NOAPT || pip install $MYPIPFLAGS coverage
84-
- $NOAPT || pip install $MYPIPFLAGS periodictable
85-
- $NOAPT || easy_install --user "pycifrw==4.2.1"
86-
- $NOAPT || easy_install --user diffpy.Structure
101+
- $NOAPT || $MYPIP install $MYPIPFLAGS coverage
102+
- $NOAPT || $MYPIP install $MYPIPFLAGS periodictable
103+
- $NOAPT || $MYPIP install $MYPIPFLAGS "pycifrw==4.2.1"
104+
- $NOAPT || $MYPIP install $MYPIPFLAGS diffpy.structure
87105
- $NOAPT || sudo scons -C ~/pkgs/libObjCryst install
88-
- $NOAPT || easy_install --user pyobjcryst
106+
- $NOAPT || $MYPIP install $MYPIPFLAGS pyobjcryst
89107
- $NOAPT || sudo scons -C ~/pkgs/libdiffpy install
90-
- $NOAPT || easy_install --user "${MYTARBUNDLE}"
108+
- $NOAPT || $MYPIP install $MYPIPFLAGS "${MYTARBUNDLE}"
109+
110+
- $NOBREW || $MYPIP install $MYPIPFLAGS coverage
111+
- $NOBREW || $MYPIP install $MYPIPFLAGS periodictable
112+
- $NOBREW || $MYPIP install $MYPIPFLAGS pycifrw
113+
# install diffpy.structure from the python3 development branch.
114+
# TODO - replace with PyPI version later.
115+
- $NOBREW || $MYPIP install $MYPIPFLAGS https://github.com/diffpy/diffpy.structure/archive/python3.tar.gz
116+
- $NOBREW || scons -C ~/pkgs/libObjCryst install
117+
- $NOBREW || $MYPIP install $MYPIPFLAGS pyobjcryst
118+
- $NOBREW || scons -C ~/pkgs/libdiffpy install
119+
- $NOBREW || $MYPIP install $MYPIPFLAGS "${MYTARBUNDLE}"
91120

92121
- cd ${MYRUNDIR}
93-
- MYGIT_REV=$(python -c "import ${MYNAME}.version as v; print(v.__gitsha__)")
122+
- MYGIT_REV=$($MYPYTHON -c "import ${MYNAME}.version as v; print(v.__gitsha__)")
94123
- if [[ "${TRAVIS_COMMIT}" != "${MYGIT_REV}" ]]; then
95124
echo "Version mismatch ${TRAVIS_COMMIT} vs ${MYGIT_REV}.";
96125
exit 1;
97126
fi
98127

128+
before_script:
129+
- $NOBREW || USER_BASE="$(python3 -c 'import site; print(site.USER_BASE)')"
130+
- $NOBREW || PATH="${USER_BASE}/bin:${PATH}"
131+
99132
script:
100133
- coverage run --source ${MYNAME} -m ${MYNAME}.tests.run
101134

102135
after_success:
103-
- pip install $MYPIPFLAGS codecov
136+
- $MYPIP install $MYPIPFLAGS codecov
104137
- codecov

README.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function (PDF), bond valence sums (BVS), atom overlaps for a hard-sphere
1414
model, bond distances and directions up to specified maximum distance. The
1515
atomic structure models are represented with internal classes as non-periodic,
1616
periodic or structures with space group symmetries. The package provides
17-
implicit adapters from diffpy.Structure class or from Crystal or Molecule
17+
implicit adapters from diffpy.structure classes or from Crystal or Molecule
1818
objects from pyobjcryst. Adapters can be easily defined for any other
1919
structure representations in Python allowing their direct use with the
2020
calculators. Calculators support two evaluation models - BASIC, which
@@ -46,18 +46,18 @@ http://diffpy.github.io/diffpy.srreal.
4646
REQUIREMENTS
4747
------------------------------------------------------------------------
4848

49-
The diffpy.srreal requires Python 2.7, C++ compiler and
50-
the following software:
49+
The diffpy.srreal package requires Python 3.6, 3.5, 3.4 or 2.7,
50+
C++ compiler and the following software:
5151

5252
* ``setuptools`` - tools for installing Python packages
5353
* ``NumPy`` - library for scientific computing with Python
54-
* ``scons`` - software constructions tool (1.0 or later)
5554
* ``python-dev`` - header files for interfacing Python with C
5655
* ``libboost-all-dev`` - Boost C++ libraries and development files (1.43 or later)
5756
* ``libdiffpy`` - C++ library for PDF, bond valence sum and other pair
5857
quantity calculators https://github.com/diffpy/libdiffpy
59-
* ``diffpy.Structure`` - simple storage and manipulation of atomic structures
60-
https://github.com/diffpy/diffpy.Structure
58+
* ``diffpy.structure`` - simple storage and manipulation of atomic structures
59+
https://github.com/diffpy/diffpy.structure
60+
* ``scons`` - software construction tool (optional)
6161

6262
Optional software:
6363

@@ -103,13 +103,14 @@ You may need to use ``sudo`` with system Python so the process is
103103
allowed to copy files to the system directories. If administrator (root)
104104
access is not available, see the output from
105105
``python setup.py install --help`` for options to install to
106-
a user-writable location. The installation integrity can be verified by
107-
changing to the HOME directory and running ::
106+
a user-writable location. The installation integrity can be
107+
verified by executing the included tests with ::
108108

109109
python -m diffpy.srreal.tests.run
110110

111111
An alternative way of installing diffpy.srreal is to use the SCons tool,
112-
which can speed up the process by compiling the C++ files in parallel (-j4) ::
112+
which can speed up the process by compiling C++ files in several
113+
parallel jobs (-j4) ::
113114

114115
sudo scons -j4 install
115116

conda-recipe/meta.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ requirements:
1919
build:
2020
- python
2121
- setuptools
22-
- numpy 1.9.2
23-
- libdiffpy >=1.3.3,1.3.*
22+
- numpy 1.11.2
23+
- libdiffpy >=1.3.4,1.3.*
2424
- pycifrw
2525
- diffpy.structure
26-
- scons
2726

2827
run:
2928
- python
3029
- setuptools
31-
- numpy >=1.9.2
32-
- libdiffpy >=1.3.3,1.3.*
30+
- numpy >=1.11.2
31+
- libdiffpy >=1.3.4,1.3.*
3332
- pycifrw
3433
- diffpy.structure
3534
- pyobjcryst 2.0*

devutils/tunePeakPrecision.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import numpy
2929

30-
from diffpy.Structure import Structure
30+
from diffpy.structure import Structure
3131
from diffpy.srreal.pdf_ext import PDFCalculator
3232
import diffpy.pdffit2
3333
# make PdfFit silent

doc/manual/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function (PDF), bond valence sums (BVS), atom overlaps for a hard-sphere
1919
model, bond distances and directions up to specified maximum distance. The
2020
atomic structure models are represented with internal classes as non-periodic,
2121
periodic or structures with space group symmetries. The package provides
22-
implicit adapters from diffpy.Structure class or from Crystal or Molecule
22+
implicit adapters from diffpy.structure classes or from Crystal or Molecule
2323
objects from pyobjcryst. Adapters can be easily defined for any other
2424
structure representations in Python allowing their direct use with the
2525
calculators. Calculators support two evaluation models - BASIC, which

examples/compareC60PDFs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#!/usr/bin/env python
22

33
"""Plot C60 PDFs calculated with PDFCalculator and DebyePDFCalculator.
4-
The C60 molecule is held in a diffpy.Structure object.
4+
The C60 molecule is held in a diffpy Structure object.
55
"""
66

77
import sys
88
import os
99
from matplotlib.pyplot import plot, show, clf, draw
10-
from diffpy.Structure import Structure
10+
from diffpy.structure import Structure
1111
from diffpy.srreal.pdfcalculator import PDFCalculator, DebyePDFCalculator
1212

1313
mydir = os.path.dirname(os.path.abspath(sys.argv[0]))
1414
buckyfile = os.path.join(mydir, 'datafiles', 'C60bucky.stru')
1515

16-
# load C60 molecule as a diffpy.Structure object
16+
# load C60 molecule as a diffpy.structure object
1717
bucky = Structure(filename=buckyfile)
1818
cfg = { 'qmax' : 25,
1919
'rmin' : 0,

examples/compareC60PDFs_objcryst.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"""
66

77
from matplotlib.pyplot import plot, show, clf, draw
8-
from diffpy.Structure import Structure
8+
from diffpy.structure import Structure
99
from pyobjcryst.crystal import Crystal
1010
from pyobjcryst.molecule import Molecule
1111
from pyobjcryst.scatteringpower import ScatteringPowerAtom
1212
from diffpy.srreal.pdfcalculator import PDFCalculator, DebyePDFCalculator
1313

14-
# load C60 molecule as a diffpy.Structure object
14+
# load C60 molecule as a diffpy.structure object
1515
bucky_diffpy = Structure(filename='datafiles/C60bucky.stru')
1616

1717
# convert to an ObjCryst molecule

examples/distanceprinter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from diffpy.srreal.pairquantity import PairQuantity
8-
from diffpy.Structure import Structure
8+
from diffpy.structure import Structure
99

1010
class DistancePrinter(PairQuantity):
1111

@@ -45,8 +45,8 @@ def _addPairContribution(self, bnds, sumscale):
4545
distprint._setDoubleAttr('rmax', 10)
4646

4747
def get_pyobjcryst_sphalerite():
48-
from pyobjcryst.crystal import CreateCrystalFromCIF
49-
crst = CreateCrystalFromCIF(open('datafiles/sphalerite.cif'))
48+
from pyobjcryst import loadCrystal
49+
crst = loadCrystal('datafiles/sphalerite.cif')
5050
return crst
5151

5252
def main():
@@ -72,7 +72,7 @@ def main():
7272
crst = get_pyobjcryst_sphalerite()
7373
distprint.eval(crst)
7474
print(linesep)
75-
input('Press enter for distances in diffpy.Structure sphalerite.cif.')
75+
input('Press enter for distances in diffpy.structure sphalerite.cif.')
7676
crst = Structure(filename='datafiles/sphalerite.cif')
7777
distprint.eval(crst)
7878
return

examples/lennardjones/ljcalculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import sys
1010
from diffpy.srreal.pairquantity import PairQuantity
11-
from diffpy.Structure import Structure
11+
from diffpy.structure import Structure
1212

1313
class LennardJonesCalculator(PairQuantity):
1414

examples/parallelPDF.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import optparse
1212
import time
1313
import multiprocessing
14-
from diffpy.Structure import Structure
14+
from diffpy.structure import Structure
1515
from diffpy.srreal.pdfcalculator import PDFCalculator
1616
from diffpy.srreal.parallel import createParallelCalculator
1717

@@ -30,14 +30,14 @@
3030
# load menthol structure and make sure Uiso values are non-zero
3131
if opts.pyobjcryst:
3232
# use pyobjcryst if requested by the user
33-
from pyobjcryst.crystal import CreateCrystalFromCIF
33+
from pyobjcryst import loadCrystal
3434
from numpy import pi
35-
menthol = CreateCrystalFromCIF(open(mentholcif))
35+
menthol = loadCrystal(mentholcif)
3636
for sc in menthol.GetScatteringComponentList():
3737
sp = sc.mpScattPow
3838
sp.Biso = sp.Biso or 8 * pi**2 * Uisodefault
3939
else:
40-
# or use diffpy.Structure by default
40+
# or use diffpy.structure by default
4141
menthol = Structure(filename=mentholcif)
4242
for a in menthol:
4343
a.Uisoequiv = a.Uisoequiv or Uisodefault

0 commit comments

Comments
 (0)