Commit 4c4ac61a authored by Mark Hymers's avatar Mark Hymers

Initial port from Python2 to Python2 and 3

Signed-off-by: Mark Hymers's avatarMark Hymers <mark.hymers@hankel.co.uk>
parent 4e9ef0e6
# vim: set noexpandtab ts=4 sw=4:
# There must be a nicer way to do this
PYTHONARCH=$(shell utils/pythonarch)
PYTHONARCH=$(shell python utils/pythonarch)
PYTHONARCH3=$(shell python3 utils/pythonarch)
BINS=$(shell python setup.py --list-scripts)
BINS=$(shell python3 setup.py --list-scripts)
DEVELVERSION ?= 0.DEVEL.$(shell date +%Y%m%d%H%M)
RELEASEVERSION ?= $(DEVELVERSION)
all: $(PY4UICFILES)
python3 setup.py build
all2: $(PY4UICFILES)
python setup.py build
doc: doc-html
doc-html: all
python setup.py build_sphinx
python3 setup.py build_sphinx
clean:
python setup.py clean
python3 setup.py clean
# Stupid python setuptools don't even clean the build directory
rm -fr build
rm -fr doc/build
test: all
cd build && PYTHONPATH=lib.$(PYTHONARCH)/:$${PYTHONPATH} nosetests -c ../nose.cfg lib.$(PYTHONARCH)/anamnesis
cd build && PYTHONPATH=lib$(PYTHONARCH3)/:$${PYTHONPATH} nosetests3 -c ../nose.cfg lib$(PYTHONARCH3)/anamnesis
testv: all
cd build && PYTHONPATH=lib.$(PYTHONARCH)/:$${PYTHONPATH} nosetests --with-coverage --cover-package=anamnesis -c ../nose.cfg -s -v lib.$(PYTHONARCH)/anamnesis
cd build && PYTHONPATH=lib$(PYTHONARCH3)/:$${PYTHONPATH} nosetests3 --with-coverage --cover-package=anamnesis -c ../nose.cfg -s -v lib$(PYTHONARCH3)/anamnesis
test2: all2
cd build && PYTHONPATH=lib$(PYTHONARCH3)/:$${PYTHONPATH} nosetests -c ../nose.cfg lib$(PYTHONARCH3)/anamnesis
testv2: all2
cd build && PYTHONPATH=lib$(PYTHONARCH3)/:$${PYTHONPATH} nosetests --with-coverage --cover-package=anamnesis -c ../nose.cfg -s -v lib$(PYTHONARCH3)/anamnesis
install:
python setup.py install --prefix=$(DESTDIR)/usr
python3 setup.py install --prefix=$(DESTDIR)/usr
mkdir -p $(DESTDIR)/usr/share/doc/anam
cp -a doc/build/html $(DESTDIR)/usr/share/doc/anam
.PHONY: clean doc doc-html all test testv pythonarch
.PHONY: clean doc doc-html all all2 test testv test2 testv4 pythonarch
This diff is collapsed.
......@@ -131,7 +131,7 @@ __all__.append('MPIHandler')
def mpi_print(txt):
print "NODE %s: %s" % (MPIHandler().rank, txt)
print("NODE %s: %s" % (MPIHandler().rank, txt))
__all__.append('mpi_print')
......@@ -139,7 +139,7 @@ __all__.append('mpi_print')
if __name__ == '__main__':
import mpi4py
print mpi4py.__version__
print(mpi4py.__version__)
m = MPIHandler(use_mpi=True)
......@@ -150,16 +150,16 @@ if __name__ == '__main__':
data = m.scatter_array(data)
print "NODE %s, %s" % (m.rank, data.shape)
print("NODE %s, %s" % (m.rank, data.shape))
final = m.gather(data)
if final is not None:
print "GATHER NODE %s, %s" % (m.rank, final.shape)
print("GATHER NODE %s, %s" % (m.rank, final.shape))
else:
print "GATHER NODE %s NONE" % (m.rank)
print("GATHER NODE %s NONE" % (m.rank))
finalall = m.allgather(data)
print "ALLGATHER NODE %s, %s" % (m.rank, finalall.shape)
print("ALLGATHER NODE %s, %s" % (m.rank, finalall.shape))
m.done()
......@@ -57,7 +57,7 @@ class MPI4PyImplementor(object):
elif t == 'NORMAL':
return self.mpi.recv(None, source=source, tag=tag, status=status)
else:
raise StandardError("Rank %d cannot understand MPI recieve type "
raise Exception("Rank %d cannot understand MPI recieve type "
"%s, expecting ANAM or NORMAL" %
(self.rank, t))
......@@ -90,7 +90,7 @@ class MPI4PyImplementor(object):
elif t == 'NORMAL':
return self.mpi.bcast(None, root=root)
else:
raise StandardError("Rank %d cannot understand MPI broadcast "
raise Exception("Rank %d cannot understand MPI broadcast "
"type %s, expecting ANAM or NORMAL" %
(self.rank, t))
else:
......@@ -268,7 +268,7 @@ class MPI4PyImplementor(object):
# Gather up the data
for node in range(len(scatterindices)):
pos = 0
for trialnum in xrange(*scatterindices[node]):
for trialnum in range(*scatterindices[node]):
if node == self.mpi.rank:
# (it's us)
obj = data_in[pos]
......
......@@ -134,12 +134,12 @@ def register_class(cls, name=None):
name = '.'.join([cls.__module__, cls.__name__])
if name in c.class_register:
raise StandardError('Name %s already registered' % name)
raise Exception('Name %s already registered' % name)
c.class_register[name] = cls
for aname in getattr(cls(), 'hdf5_aliases', []):
if aname in c.class_register:
raise StandardError('Alias name %s already registered' % aname)
raise Exception('Alias name %s already registered' % aname)
c.class_register[aname] = cls
......@@ -151,7 +151,11 @@ def find_class(name):
return cls
# Try our best to find and import it whilst not being entirely insecure
if isinstance(name, bytes):
name = name.decode()
nc = name.split('.')
cnt = len(nc)
while cnt > 0:
try:
......
......@@ -20,7 +20,7 @@ class Store(AbstractAnam):
def __eq__(self, other):
seenkeys = {}
for k in self.extra_data.keys():
for k in list(self.extra_data.keys()):
seenkeys[k] = 1
if k in other.extra_data:
if self.extra_data[k] != other.extra_data[k]:
......@@ -28,7 +28,7 @@ class Store(AbstractAnam):
else:
return False
for k in other.extra_data.keys():
for k in list(other.extra_data.keys()):
if k not in seenkeys:
return False
......
......@@ -22,17 +22,17 @@ def find_path(varname, sentinal, subdir=None):
dir = os.environ.get(varname, None)
if not dir:
raise StandardError("%s is not set, cannot find test files" % varname)
raise Exception("%s is not set, cannot find test files" % varname)
if subdir is not None:
dir = join(dir, subdir)
if not isdir(dir):
raise StandardError("%s is not a directory" % varname)
raise Exception("%s is not a directory" % varname)
# Our test file
if not isfile(join(dir, sentinal)):
raise StandardError("%s does not seem to contain sentinal "
raise Exception("%s does not seem to contain sentinal "
"file %s" % (varname, sentinal))
return abspath(dir)
......@@ -125,7 +125,7 @@ class AnamTestBase(unittest.TestCase):
abs_dirname = join(self.tempdir, dirname)
try:
os.makedirs(abs_dirname)
except OSError, e:
except OSError as e:
if e.errno != EEXIST:
raise e
......
......@@ -65,6 +65,11 @@ class TestArrayContainer(AbstractAnam):
self.data1 = data1
self.data2 = data2
def __lt__(self, other):
# This isn't a proper test, it just sorts
# by object ID for test purposes
return id(self) < id(other)
register_class(TestArrayContainer)
......@@ -658,9 +663,9 @@ class AbstractCollectionTest(AnamTestBase):
assert('data2' in n._cache)
assert(n._cache['data1'].shape == (10, 1))
assert(n._cache['data2'].shape == (20, 1))
assert(len(n.keys()) == 2)
assert('data1' in n.keys())
assert('data2' in n.keys())
assert(len(list(n.keys())) == 2)
assert('data1' in list(n.keys()))
assert('data2' in list(n.keys()))
def test_update_cache_with_multiple_members(self):
"""Check that we can update our cache on a collection with multiple
......@@ -978,7 +983,7 @@ class AnamDictTest(AnamTestBase):
a = AnamDict(d)
assert(len(a.data.keys()) == 2)
assert(len(list(a.data.keys())) == 2)
def test_bad_create_anam_dict(self):
"""Test that we fail to create an AnamDict with bad data"""
......
......@@ -3,7 +3,15 @@
"""Tests for options module"""
# vim: set expandtab ts=4 sw=4:
from StringIO import StringIO
import sys
# Deal with gratuitous changes in str/bytes/unicode between python 2 and 3 I'm
# sure it's all nice and neat now - and a complete pain if you live in the real
# world and have to support both simultaneously.
if sys.version_info.major == 2:
from io import BytesIO as StringIO
else:
from io import StringIO
from ..test import AnamTestBase
......@@ -55,8 +63,6 @@ class OptionsTest(AnamTestBase):
a.write_progress("Should be written", target=s)
s.seek(0)
t = s.read()
print(len(t), t)
print(len("Should be written"))
assert(t == "Should be written")
s.close()
......@@ -79,8 +85,6 @@ class OptionsTest(AnamTestBase):
a.write("Should be written", target=s)
s.seek(0)
t = s.read()
print(len(t), t)
print(len("Should be written"))
assert(t == "Should be written")
s.close()
......@@ -63,7 +63,7 @@ class TestRegister(unittest.TestCase):
register_class(Foo, 'test.tdr_foo')
self.assertRaises(StandardError, register_class, Foo, 'test.tdr_foo')
self.assertRaises(Exception, register_class, Foo, 'test.tdr_foo')
def test_doubleregisteralias(self):
"""Test that we handle not double registering aliases"""
......@@ -72,7 +72,7 @@ class TestRegister(unittest.TestCase):
register_class(Foo2, 'test.tdra.Foo2')
self.assertRaises(StandardError, register_class, Foo3,
self.assertRaises(Exception, register_class, Foo3,
'test.tdra.foo3')
def test_permitted_prefix(self):
......
......@@ -57,18 +57,18 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'anamnesis'
copyright = u'2010-2017 Mark Hymers'
author = u'Mark Hymers'
project = 'anamnesis'
copyright = '2010-2017 Mark Hymers'
author = 'Mark Hymers'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'1.0.0'
version = '1.0.0'
# The full version, including alpha/beta/rc tags.
release = u'1.0.0'
release = '1.0.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
......@@ -268,8 +268,8 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'anamnesis.tex', u'anamnesis Documentation',
u'Mark Hymers', 'manual'),
(master_doc, 'anamnesis.tex', 'anamnesis Documentation',
'Mark Hymers', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
......@@ -310,7 +310,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'anamnesis', u'anamnesis Documentation',
(master_doc, 'anamnesis', 'anamnesis Documentation',
[author], 1)
]
......@@ -325,7 +325,7 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'anamnesis', u'anamnesis Documentation',
(master_doc, 'anamnesis', 'anamnesis Documentation',
author, 'anamnesis', 'One line description of project.',
'Miscellaneous'),
]
......
#!/usr/bin/python
#!/usr/bin/python3
# vim: set expandtab ts=4 sw=4:
......@@ -6,5 +6,9 @@
import distutils.util, sys
print("%s-%s" % (distutils.util.get_platform(), sys.version[0:3]))
if sys.version[0] == '2':
print(".%s-%s" % (distutils.util.get_platform(), sys.version[0:3]))
else:
# Python 3
print("")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment