Skip to content

Commit a804ae8

Browse files
committed
Merge branch 'support-py2-and-py3'
* make sources Python 3 compatible * keep compatibility with Python 2 using the `six` tool * rename module names to lowercase * provide legacy import hook to support old names * use noarch conda package Closes #23.
2 parents fe1d62d + 4f08815 commit a804ae8

Some content is hidden

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

70 files changed

+2188
-2054
lines changed

.readthedocs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
python:
2+
version: 3
3+
setup_py_install: true
4+
use_system_site_packages: true
5+
6+
# For more fields that can be specified here, see:
7+
# http://docs.readthedocs.io/en/latest/yaml-config.html

.travis.yml

Lines changed: 40 additions & 34 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,46 +7,43 @@ 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
33-
3422

3523
before_install:
3624
- MYNAME=diffpy.structure
3725
- MYCOMMIT="$(git rev-parse HEAD)"
3826
- umask 022
3927
- git fetch origin --tags
28+
- MYPYTHON=python; MYPIP=pip
29+
- NOSYS=true; NOAPT=true; NOBREW=true; NOMC=true
4030
- if ${MYUSEMC}; then
41-
NOAPT=true; NOMC=false;
42-
else
43-
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;
4439
MYPIPFLAGS="--user";
4540
fi
46-
- MYMCREPO=https://repo.continuum.io/miniconda
41+
- MYMCREPO=https://repo.anaconda.com/miniconda
4742
- case ${TRAVIS_OS_NAME} in
4843
linux)
49-
MYMCBUNDLE=Miniconda2-latest-Linux-x86_64.sh ;;
44+
MYMCBUNDLE=Miniconda3-latest-Linux-x86_64.sh ;;
5045
osx)
51-
MYMCBUNDLE=Miniconda2-latest-MacOSX-x86_64.sh ;;
46+
MYMCBUNDLE=Miniconda3-latest-MacOSX-x86_64.sh ;;
5247
*)
5348
echo "Unsupported operating system." >&2;
5449
exit 2 ;;
@@ -65,16 +60,27 @@ before_install:
6560
- $NOMC || popd
6661
- $NOMC || source ~/mc/bin/activate base
6762
- $NOMC || conda update --yes conda
68-
- $NOMC || conda install --yes conda-build jinja2
63+
- $NOMC || conda install --yes conda-build conda-verify jinja2
6964
- $NOMC || conda create --name=testenv --yes python=${MYPYTHON_VERSION} coverage
7065
- $NOMC || conda config --add channels diffpy
66+
# FIXME - keep just the "diffpy" channel for public release.
67+
- $NOMC || conda config --add channels diffpy/channel/dev
7168

7269
- $NOAPT || test "${TRAVIS_OS_NAME}" = "linux" || exit $?
7370
- $NOAPT || PATH="$(echo "$PATH" | sed 's,:/opt/pyenv/[^:]*,,g')"
7471
- $NOAPT || test "$(which python)" = "/usr/bin/python" || (
7572
which python; exit 1)
76-
- $NOAPT || devutils/makesdist
77-
- $NOAPT || MYTARBUNDLE="$(ls -t "${PWD}"/dist/*.tar.gz | head -1)"
73+
- $NOAPT || sudo apt-get update -qq
74+
- $NOAPT || sudo apt-get install -y
75+
python-dev python-numpy python-setuptools build-essential
76+
77+
- $NOBREW || test "${TRAVIS_OS_NAME}" = "osx" || exit $?
78+
- $NOBREW || brew update
79+
- $NOBREW || brew upgrade python
80+
- $NOBREW || brew install gcc || brew link --overwrite gcc
81+
82+
- $NOSYS || devutils/makesdist
83+
- $NOSYS || MYTARBUNDLE="$(ls -t "${PWD}"/dist/*.tar.gz | head -1)"
7884

7985

8086
install:
@@ -84,26 +90,26 @@ install:
8490
- $NOMC || source activate testenv
8591
- $NOMC || conda install --yes --use-local --file=/tmp/mypackage.txt
8692

87-
- $NOAPT || pip install $MYPIPFLAGS coverage
88-
# TODO - remove after fixup release of PyCifRW following 4.3.
89-
- $NOAPT || pip install $MYPIPFLAGS "pycifrw==4.2.1"
90-
- $NOAPT || easy_install --user "${MYTARBUNDLE}"
91-
92-
# We need to capitalize MYNAME to match Python module name.
93-
- MYNAME=diffpy.Structure
93+
- $NOSYS || $MYPIP install $MYPIPFLAGS coverage
94+
- $NOSYS || $MYPIP install $MYPIPFLAGS "${MYTARBUNDLE}"
9495

9596
- cd ${MYRUNDIR}
96-
- MYGIT_REV=$(python -c "import ${MYNAME}.version as v; print(v.__git_commit__)")
97+
- MYGIT_REV=$($MYPYTHON -c "import ${MYNAME}.version as v; print(v.__git_commit__)")
9798
- if [[ "${MYCOMMIT}" != "${MYGIT_REV}" ]]; then
9899
echo "Version mismatch ${MYCOMMIT} vs ${MYGIT_REV}.";
99100
exit 1;
100101
fi
101102

102103

104+
before_script:
105+
- $NOBREW || USER_BASE="$($MYPYTHON -c 'import site; print(site.USER_BASE)')"
106+
- $NOBREW || PATH="${USER_BASE}/bin:${PATH}"
107+
108+
103109
script:
104110
- coverage run --source ${MYNAME} -m ${MYNAME}.tests.run
105111

106112

107113
after_success:
108-
- pip install $MYPIPFLAGS codecov
114+
- $MYPIP install $MYPIPFLAGS codecov
109115
- codecov

README.rst

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,43 @@
55
:target: https://codecov.io/gh/diffpy/diffpy.structure
66

77

8-
diffpy.Structure
8+
diffpy.structure
99
========================================================================
1010

1111
storage and manipulation of crystal structure data
1212

13-
The diffpy.Structure package provides objects for storing atomic
13+
The diffpy.structure package provides objects for storing atomic
1414
coordinates, displacement parameters and other crystal structure data.
15-
diffpy.Structure supports import and export of structure data in several
15+
diffpy.structure supports import and export of structure data in several
1616
structure formats such as CIF, PDB, and xyz. It provides conversion
1717
between fractional and absolute Cartesian coordinates, functions for
1818
symmetry expansion of atom sites in the asymmetric unit and generation
1919
of symmetry constraints for atom positions and displacement parameters.
20-
diffpy.Structure includes definitions of all space groups in over 500
20+
diffpy.structure includes definitions of all space groups in over 500
2121
symmetry settings.
2222

23-
To learn more about diffpy.Structure library see the
23+
To learn more about diffpy.structure library see the
2424
user manual at http://diffpy.github.io/diffpy.structure.
2525

2626

2727
REQUIREMENTS
2828
------------------------------------------------------------------------
2929

30-
The diffpy.Structure requires Python 2.7 and the following software:
30+
The diffpy.structure package requires Python 3.5 or later or 2.7 and
31+
the following software:
3132

3233
* ``setuptools`` - software distribution tools for Python
3334
* ``NumPy`` - numerical mathematics and fast array operations for Python
3435

3536
We recommend to use `Anaconda Python <https://www.anaconda.com/download>`_
3637
as it allows to install all software dependencies together with
37-
diffpy.Structure. For other Python distributions it is necessary to
38+
diffpy.structure. For other Python distributions it is necessary to
3839
install the required software separately. As an example on Ubuntu
3940
Linux the required software can be installed with ::
4041

41-
sudo aptitude install python-setuptools python-numpy
42+
sudo aptitude install python3-setuptools python3-numpy
4243

43-
diffpy.Structure also uses the
44+
diffpy.structure also uses the
4445
`PyCifRW <https://bitbucket.org/jamesrhester/pycifrw>`_
4546
library, which is automatically deployed during the
4647
installation process.
@@ -55,7 +56,7 @@ The preferred method is to use Anaconda Python and install from the
5556
conda config --add channels diffpy
5657
conda install diffpy.structure
5758

58-
diffpy.Structure is also included in the "diffpy-cmi" collection
59+
diffpy.structure is also included in the "diffpy-cmi" collection
5960
of packages for structure analysis ::
6061

6162
conda install diffpy-cmi
@@ -64,7 +65,7 @@ Another installation option is to use ``easy_install`` to download and
6465
install the latest release from
6566
`Python Package Index <https://pypi.python.org>`_ ::
6667

67-
easy_install diffpy.Structure
68+
easy_install diffpy.structure
6869

6970
If you prefer to install from sources, navigate to the source archive
7071
directory and run ::
@@ -77,18 +78,18 @@ the usage info from ``python setup.py install --help`` for options to
7778
install to user-writable locations. The installation integrity can be
7879
verified by changing to the HOME directory and running ::
7980

80-
python -m diffpy.Structure.tests.run
81+
python -m diffpy.structure.tests.run
8182

8283

8384
DEVELOPMENT
8485
------------------------------------------------------------------------
8586

86-
diffpy.Structure is an open-source software developed as a part of the
87+
diffpy.structure is an open-source software developed as a part of the
8788
DiffPy-CMI complex modeling initiative at the Brookhaven National
88-
Laboratory. The diffpy.Structure sources are hosted at
89+
Laboratory. The diffpy.structure sources are hosted at
8990
https://github.com/diffpy/diffpy.structure.
9091

91-
Feel free to fork the project and contribute. To install diffpy.Structure
92+
Feel free to fork the project and contribute. To install diffpy.structure
9293
in a development mode, where the sources are directly used by Python
9394
rather than copied to a system directory, use ::
9495

@@ -105,7 +106,7 @@ originate from the pymmlib project, http://pymmlib.sourceforge.net.
105106
CONTACTS
106107
------------------------------------------------------------------------
107108

108-
For more information on diffpy.Structure please visit the project web-page
109+
For more information on diffpy.structure please visit the project web-page
109110

110111
http://www.diffpy.org/
111112

conda-recipe/meta.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ source:
1010

1111
build:
1212
preserve_egg_dir: True
13+
noarch: python
14+
1315
# entry_points:
1416
# Put any entry points (scripts to be generated automatically) here. The
1517
# syntax is module:function. For example
@@ -18,27 +20,33 @@ build:
1820
#
1921
# Would create an entry point called diffpy.structure that calls diffpy.structure.main()
2022

21-
2223
# If this is a new build for the same version, increment the build
2324
# number. If you do not include this key, it defaults to 0.
2425
# number: 0
2526

2627
requirements:
2728
build:
28-
- python
29+
- python >=3.5|2.7*
2930
- setuptools
31+
- six
3032
- pycifrw
3133

3234
run:
33-
- python
35+
- python >=3.5|2.7*
3436
- setuptools
3537
- numpy >=1.3
3638
- pycifrw
39+
- six
3740

3841
test:
3942
# Python imports
4043
imports:
41-
- diffpy
44+
- diffpy.structure
45+
- diffpy.structure.parsers
46+
- diffpy.structure.applications
47+
- diffpy.structure.expansion
48+
- diffpy.structure.tests
49+
# legacy imports
4250
- diffpy.Structure
4351
- diffpy.Structure.Parsers
4452
- diffpy.Structure.applications

conda-recipe/run_test.py

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

3-
import diffpy.Structure.tests
4-
assert diffpy.Structure.tests.test().wasSuccessful()
3+
import diffpy.structure.tests
4+
assert diffpy.structure.tests.test().wasSuccessful()

devutils/sgtbx_extra_groups.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
import re
1414
import math
1515
import numpy
16-
from diffpy.Structure.SpaceGroups import SpaceGroup, SymOp
17-
from diffpy.Structure.SpaceGroups import mmLibSpaceGroupList
18-
from diffpy.Structure.SpaceGroups import IsSpaceGroupIdentifier
16+
from diffpy.structure.spacegroups import SpaceGroup, SymOp
17+
from diffpy.structure.spacegroups import mmLibSpaceGroupList
18+
from diffpy.structure.spacegroups import IsSpaceGroupIdentifier
1919
from cctbx import sgtbx
2020

2121
def tupleToSGArray(tpl):
2222
if not _rtarrays:
23-
import diffpy.Structure.SpaceGroups as sgmod
23+
import diffpy.structure.SpaceGroups as sgmod
2424
for n in dir(sgmod):
2525
if not n.startswith('Rot_') and not n.startswith('Tr_'): continue
2626
a = getattr(sgmod, n)
@@ -39,7 +39,6 @@ def mmSpaceGroupFromSymbol(symbol):
3939
"""
4040
sginfo = sgtbx.space_group_info(symbol)
4141
symop_list = []
42-
unique_rotations = set()
4342
symop_list = getSymOpList(sginfo.group())
4443
sgtype = sginfo.type()
4544
uhm = sgtype.lookup_symbol()
@@ -60,7 +59,7 @@ def mmSpaceGroupFromSymbol(symbol):
6059

6160

6261
def adjustMMSpaceGroupNumber(mmsg):
63-
sg0 = filter(lambda x : x.number == mmsg.number, mmLibSpaceGroupList)
62+
sg0 = [x for x in mmLibSpaceGroupList if x.number == mmsg.number]
6463
if sg0 and cmpSpaceGroups(sg0[0], mmsg):
6564
return
6665
while mmsg.number in sgnumbers:
@@ -121,13 +120,13 @@ def hashMMSpaceGroup(sg):
121120
s = '\n'.join(lines)
122121
return s
123122

123+
124124
def hashSgtbxGroup(grp):
125125
n = grp.type().number()
126126
lines = [str(n)] + sorted(map(str, getSymOpList(grp)))
127127
s = '\n'.join(lines)
128128
return s
129129

130-
131130
sgnumbers = [sg.number for sg in mmLibSpaceGroupList]
132131

133132
_SGsrc = '''\
@@ -159,7 +158,7 @@ def SymOpsCode(mmsg):
159158

160159
def SymOpCode(op):
161160
if not _rtnames:
162-
import diffpy.Structure.SpaceGroups as sgmod
161+
import diffpy.structure.SpaceGroups as sgmod
163162
for n in dir(sgmod):
164163
if not n.startswith('Rot_') and not n.startswith('Tr_'): continue
165164
a = getattr(sgmod, n)
@@ -185,7 +184,7 @@ def main():
185184
if hsg in duplicates: continue
186185
adjustMMSpaceGroupNumber(sg)
187186
duplicates.add(hsg)
188-
print SGCode(sg)
187+
print(SGCode(sg))
189188
return
190189

191190
if __name__ == '__main__':

0 commit comments

Comments
 (0)