Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backwards compatible with Python 2.7 #7

Merged
merged 4 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals
import os
import re
import sys
from os import path
from io import open # Python 2
from subprocess import check_output

from setuptools import find_packages, setup
Expand All @@ -29,11 +31,11 @@ def update_version():
re.MULTILINE).group(1)

with open(path.join('zernike', 'version.py'), 'w', newline='\n') as f:
f.write('#!/usr/bin/env python3\n')
f.write('#!/usr/bin/env python\n')
f.write('# -*- coding: utf-8 -*-\n\n')
f.write(f"__version__ = '{version}'\n")
f.write(f"__date__ = '{date}'\n")
f.write(f"__commit__ = '{commit}'")
f.write("__version__ = '%s'\n"%version)
f.write("__date__ = '%s'\n"%date)
f.write("__commit__ = '%s'"%commit)
except Exception as e:
print('Cannot update version {}'.format(str(e)), file=sys.stderr)

Expand Down Expand Up @@ -68,5 +70,5 @@ def lookup_version():
setup_requires=['numpy'],
install_requires=['numpy', 'h5py', 'matplotlib'],
packages=find_packages(exclude=['tests*', 'examples*']),
python_requires='>=3.7',
python_requires='>=2.7',
)
15 changes: 10 additions & 5 deletions zernike/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
# You should have received a copy of the GNU General Public License
# along with zernike. If not, see <http://www.gnu.org/licenses/>.

from abc import ABC, abstractmethod
from __future__ import print_function, division # Python 2
try:
from abc import ABC, abstractmethod
except: # Probably Python 2
from abc import ABCMeta, abstractmethod
ABC = ABCMeta('ABC', (object,), {'__slots__': ()})
from math import factorial

import h5py
Expand Down Expand Up @@ -297,7 +302,7 @@ def matrix(self, Phi):
if self.shape is None:
raise ValueError('Use make_cart_grid() to define the shape first')
elif self.shape[0] * self.shape[1] != Phi.size:
raise ValueError(f'Phi.shape should be {self.shape}')
raise ValueError('Phi.shape should be %s'%self.shape)
return Phi.reshape(self.shape, order='F')

def make_cart_grid(self, xx, yy, unit_circle=True):
Expand Down Expand Up @@ -382,7 +387,7 @@ def eval_grid(self, a, matrix=False):

"""
if a.size != self.nk:
raise ValueError(f'a.size = {a.size} but self.nk = {self.nk}')
raise ValueError('a.size = %d but self.nk = %d'%(a.size,self.nk))
Phi = np.dot(self.ZZ, a)
if matrix:
return self.matrix(Phi)
Expand Down Expand Up @@ -663,7 +668,7 @@ class CZern(Zern):

"""
def __init__(self, n, normalise=Zern.NORM_NOLL):
super().__init__(n, normalise)
super(CZern, self).__init__(n, normalise)
self.numpy_dtype = 'complex'

def ck(self, n, m):
Expand Down Expand Up @@ -715,7 +720,7 @@ class RZern(Zern):

"""
def __init__(self, n, normalise=Zern.NORM_NOLL):
super().__init__(n, normalise)
super(RZern, self).__init__(n, normalise)
self.numpy_dtype = 'float'

def ck(self, n, m):
Expand Down