From 66ba47b05101a2e8644c9ff1d277931ed77a6695 Mon Sep 17 00:00:00 2001 From: Laura Mendoza Date: Tue, 19 Nov 2019 16:58:20 +0100 Subject: [PATCH 1/4] [py3] took out all tests of python version --- _updateversion.py | 11 +----- tofu/__init__.py | 4 -- tofu/geom/_comp.py | 26 +++++------- tofu/tests/tests01_geom/tests01_GG.py | 57 --------------------------- tofu/utils.py | 16 +------- 5 files changed, 12 insertions(+), 102 deletions(-) diff --git a/_updateversion.py b/_updateversion.py index b14f878f2..e36de4124 100644 --- a/_updateversion.py +++ b/_updateversion.py @@ -12,12 +12,7 @@ def updateversion(path=_HERE): # Also, when git is not available (PyPi package), use stored version.py version_py = os.path.join(path,"version.py") try: - if sys.version[0]=='2': - version_git = subprocess.check_output(["git","describe"]).rstrip() - elif sys.version[0]=='3': - version_git = subprocess.check_output(["git","describe"]).rstrip().decode() - else: - raise Exception("Wrong python version !") + version_git = subprocess.check_output(["git","describe"]).rstrip().decode() except: with open(version_py,'r') as fh: version_git = fh.read().strip().split("=")[-1].replace("'",'') @@ -28,7 +23,3 @@ def updateversion(path=_HERE): msg = "{0}__version__ = '{1}'{0}".format(os.linesep, version_git) fh.write(version_msg + msg) return version_git - - - - diff --git a/tofu/__init__.py b/tofu/__init__.py index 8ffba0a2d..562102aba 100644 --- a/tofu/__init__.py +++ b/tofu/__init__.py @@ -53,10 +53,6 @@ """ import sys import warnings -if sys.version[0] == '2': - from .version import __version__ -elif sys.version[0] == '3': - from .version import __version__ # For tests without display with nosetests if not 'matplotlib.pyplot' in sys.modules: diff --git a/tofu/geom/_comp.py b/tofu/geom/_comp.py index 30719f26f..8a8e3275e 100644 --- a/tofu/geom/_comp.py +++ b/tofu/geom/_comp.py @@ -11,11 +11,6 @@ import scipy.interpolate as scpinterp import scipy.integrate as scpintg -if sys.version[0] == "3": - from inspect import signature as insp -elif sys.version[0] == "2": - from inspect import getargspec as insp - # ToFu-specific try: import tofu.geom._def as _def @@ -1027,18 +1022,15 @@ def LOS_calc_signal( D, u, dL, DL=DL, dLMode=dLMode, method=method, Test=Test ) out = insp(ff) - if sys.version[0] == "3": - N = np.sum( - [ - ( - pp.kind == pp.POSITIONAL_OR_KEYWORD - and pp.default is pp.empty - ) - for pp in out.parameters.values() - ] - ) - else: - N = len(out.args) + N = np.sum( + [ + ( + pp.kind == pp.POSITIONAL_OR_KEYWORD + and pp.default is pp.empty + ) + for pp in out.parameters.values() + ] + ) if N == 1: Vals = ff(Pts) diff --git a/tofu/tests/tests01_geom/tests01_GG.py b/tofu/tests/tests01_geom/tests01_GG.py index 9609132da..b0437ff4e 100644 --- a/tofu/tests/tests01_geom/tests01_GG.py +++ b/tofu/tests/tests01_geom/tests01_GG.py @@ -456,13 +456,6 @@ def test10_Ves_Smesh_Tor_PhiMinMax(VPoly=VPoly, plot=True): [[3.*np.pi/4.,5.*np.pi/4.], [np.pi/2.,np.pi]], [[3.*np.pi/4.,5.*np.pi/4.], [7.*np.pi/6.,5.*np.pi/6.]]] - if plot and sys.version[0]=='2': - f = plt.figure(figsize=(11.7,8.3),facecolor="w") - axarr = mplgrid.GridSpec(2,len(LPhi)/2) - axarr.update(left=0.05, right=0.95, top=0.95, bottom=0.05, - wspace=0.05, hspace=0.05) - Lax = [] - for ii in range(0,len(LPhi)): Pts, dS, ind,\ NL, dLr, Rref,\ @@ -476,20 +469,6 @@ def test10_Ves_Smesh_Tor_PhiMinMax(VPoly=VPoly, plot=True): Out='(R,Z,Phi)', margin=1.e-9) - if plot and sys.version[0]=='2': - Lax.append( f.add_subplot(axarr[ii], facecolor='w', - projection='3d') ) - pts = GG.CoordShift(Pts, In='(R,Z,Phi)', Out='(X,Y,Z)', - CrossRef=None) - Lax[-1].plot(pts[0,:],pts[1,:],pts[2,:], '.k', ms=3.) - rad180 = 180./np.pi - Lax[-1].set_title( - "Phi = [{0:02.0f},{1:02.0f}]\n" - "DPhi = [{2:02.0f},{3:02.0f}] ".format(LPhi[ii][0][0]*rad180, - LPhi[ii][0][1]*rad180, - LPhi[ii][1][0]*rad180, - LPhi[ii][1][1]*rad180)) - #try: assert Pts.ndim==2 and Pts.shape[0]==3 LPhi[ii][0][0] = np.arctan2(np.sin(LPhi[ii][0][0]), @@ -549,12 +528,6 @@ def test10_Ves_Smesh_Tor_PhiMinMax(VPoly=VPoly, plot=True): # range(0,len(ind)) if ind[jj]==lii[ii]]]) - if plot and sys.version[0]=='2': - f.canvas.draw() - f.savefig('./test_GG_test07_Ves_Smesh_Tor_PhiMinMax.png', format='png') - plt.close(f) - - def test11_Ves_Smesh_TorStruct(VPoly=VPoly, plot=True): @@ -573,14 +546,6 @@ def test11_Ves_Smesh_TorStruct(VPoly=VPoly, plot=True): [[3.*np.pi/4.,5.*np.pi/4.], [np.pi/2.,np.pi]], [[3.*np.pi/4.,5.*np.pi/4.], [7.*np.pi/6.,5.*np.pi/6.]]] - - if plot and sys.version[0]=='2': - f = plt.figure(figsize=(11.7,8.3),facecolor="w") - axarr = mplgrid.GridSpec(2,len(LPhi)/2) - axarr.update(left=0.05, right=0.95, top=0.95, bottom=0.05, wspace=0.05, - hspace=0.05) - Lax = [] - for ii in range(0,len(LPhi)): Pts, dS, ind, NL, \ dLr, Rref, \ @@ -595,19 +560,6 @@ def test11_Ves_Smesh_TorStruct(VPoly=VPoly, plot=True): Out='(R,Z,Phi)', margin=1.e-9) - if plot and sys.version[0]=='2': - Lax.append(f.add_subplot(axarr[ii], facecolor='w', projection='3d')) - pts = GG.CoordShift(Pts, In='(R,Z,Phi)', Out='(X,Y,Z)', - CrossRef=None) - Lax[-1].plot(pts[0,:],pts[1,:],pts[2,:], '.k', ms=3.) - rad180 = 180./np.pi - Lax[-1].set_title( - "Phi = [{0:02.0f},{1:02.0f}]\n" - "DPhi = [{2:02.0f},{3:02.0f}] ".format(LPhi[ii][0][0]*rad180, - LPhi[ii][0][1]*rad180, - LPhi[ii][1][0]*rad180, - LPhi[ii][1][1]*rad180)) - #try: assert Pts.ndim==2 and Pts.shape[0]==3 LPhi[ii][0][0] = np.arctan2(np.sin(LPhi[ii][0][0]), @@ -678,15 +630,6 @@ def test11_Ves_Smesh_TorStruct(VPoly=VPoly, plot=True): for hh in [jj for jj in range(0,len(ind)) if ind[jj]==lii[ii]]]) """ - if plot and sys.version[0]=='2': - f.canvas.draw() - f.savefig('./test_GG_test08_Ves_Smesh_TorStruct.png', format='png') - plt.close(f) - - - - - def test12_Ves_Smesh_Lin(VPoly=VPoly): XMinMax = np.array([0.,10.]) diff --git a/tofu/utils.py b/tofu/utils.py index 7679c6864..827df9024 100644 --- a/tofu/utils.py +++ b/tofu/utils.py @@ -24,7 +24,6 @@ _sep = '_' _dict_lexcept_key = [] -_pyv = int(sys.version[0]) _SAVETYP = '__type__' _NSAVETYP = len(_SAVETYP) @@ -1847,10 +1846,7 @@ def save(self, path=None, name=None, strip=strip, compressed=compressed, return_pfe=return_pfe, verb=verb) -if sys.version[0]=='2': - ToFuObject.save.__func__.__doc__ = save.__doc__ -else: - ToFuObject.save.__doc__ = save.__doc__ +ToFuObject.save.__doc__ = save.__doc__ ############################################# @@ -1910,11 +1906,6 @@ def __init__(self, Cls=None, Name=None, Type=None, Deg=None, SavePath=None, usr=None, dUSR=None, lObj=None, fromdict=None, include=None): - # To replace __init_subclass__ for Python 2 - if sys.version[0]=='2': - self._dstrip = ToFuObjectBase._dstrip.copy() - self.__class__._strip_init() - kwdargs = locals() del kwdargs['self'] #super() @@ -2038,10 +2029,7 @@ def _strip_init(cls): nMax = max(cls._dstrip['allowed']) doc = "" doc = ToFuObjectBase.strip.__doc__.format(doc,nMax) - if sys.version[0]=='2': - cls.strip.__func__.__doc__ = doc - else: - cls.strip.__doc__ = doc + cls.strip.__doc__ = doc def strip(self, strip=0): #super() From 440bb17ce74dce5f9e31666b9a1c85779bfb31bc Mon Sep 17 00:00:00 2001 From: Laura Mendoza Date: Tue, 19 Nov 2019 18:03:26 +0100 Subject: [PATCH 2/4] [py3] reversed back version in tofu init --- tofu/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tofu/__init__.py b/tofu/__init__.py index 562102aba..9b6505ff7 100644 --- a/tofu/__init__.py +++ b/tofu/__init__.py @@ -53,6 +53,7 @@ """ import sys import warnings +from .version import __version__ # For tests without display with nosetests if not 'matplotlib.pyplot' in sys.modules: From 32e13e1f1d124e5d74734867da93f67e5be6229b Mon Sep 17 00:00:00 2001 From: Laura Mendoza Date: Tue, 19 Nov 2019 18:08:12 +0100 Subject: [PATCH 3/4] [pep8] complianes --- _updateversion.py | 3 ++- tofu/utils.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/_updateversion.py b/_updateversion.py index e36de4124..d77a0be47 100644 --- a/_updateversion.py +++ b/_updateversion.py @@ -12,7 +12,8 @@ def updateversion(path=_HERE): # Also, when git is not available (PyPi package), use stored version.py version_py = os.path.join(path,"version.py") try: - version_git = subprocess.check_output(["git","describe"]).rstrip().decode() + version_git = subprocess.check_output(["git", + "describe"]).rstrip().decode() except: with open(version_py,'r') as fh: version_git = fh.read().strip().split("=")[-1].replace("'",'') diff --git a/tofu/utils.py b/tofu/utils.py index 827df9024..9a2c5a113 100644 --- a/tofu/utils.py +++ b/tofu/utils.py @@ -1846,6 +1846,7 @@ def save(self, path=None, name=None, strip=strip, compressed=compressed, return_pfe=return_pfe, verb=verb) + ToFuObject.save.__doc__ = save.__doc__ From 17dbcb3c70b93d221456504a3b26e33ef32a8e39 Mon Sep 17 00:00:00 2001 From: "Laura S. Mendoza" Date: Wed, 20 Nov 2019 09:43:01 +0100 Subject: [PATCH 4/4] [py3] restored import to insp --- tofu/geom/_comp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tofu/geom/_comp.py b/tofu/geom/_comp.py index 8a8e3275e..8ddef84bf 100644 --- a/tofu/geom/_comp.py +++ b/tofu/geom/_comp.py @@ -10,6 +10,7 @@ import numpy as np import scipy.interpolate as scpinterp import scipy.integrate as scpintg +from inspect import signature as insp # ToFu-specific try: