Skip to content

Commit 6842737

Browse files
ndem0mtezzele
authored andcommitted
python 3 compatibility (#111)
* python 3 compatibility * Add python3 test to Travis configuration
1 parent 823b131 commit 6842737

File tree

6 files changed

+61
-50
lines changed

6 files changed

+61
-50
lines changed

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ matrix:
1313
- os: osx
1414
language: generic
1515
env: TOXENV=py27
16+
- os: linux
17+
python: 3.5
18+
env: TOXENV=py35
19+
- os: osx
20+
language: generic
21+
env: TOXENV=py35
1622

1723
before_script:
1824
- "export DISPLAY=:99.0"
@@ -39,6 +45,7 @@ before_install:
3945
- conda update -q conda
4046
# Useful for debugging any issues with conda
4147
- conda info -a
48+
- conda config --add channels conda-forge
4249

4350
install:
4451
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
@@ -47,7 +54,7 @@ install:
4754
conda create --yes -n test python="2.7";
4855
fi
4956
- source activate test
50-
- conda install --yes numpy scipy matplotlib pip nose vtk sip=4.18
57+
- conda install --yes numpy scipy matplotlib vtk pip nose sip=4.18
5158
- conda install --yes -c https://conda.anaconda.org/dlr-sc pythonocc-core==0.17
5259
- pip install setuptools
5360
- pip install enum34

pygem/affine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import math
55
import sys
66
import numpy as np
7+
from functools import reduce
78

89

910
def angles2matrix(rot_z=0, rot_y=0, rot_x=0):

pygem/filehandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _check_filename_type(filename):
6060
6161
:param string filename: file to check.
6262
"""
63-
if not isinstance(filename, basestring):
63+
if not isinstance(filename, str):
6464
raise TypeError(
6565
'The given filename ({0!s}) must be a string'.format(filename)
6666
)

pygem/nurbshandler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def parse(self, filename):
109109

110110
# cycle over the poles to get their coordinates
111111
i = 0
112-
for pole_u_direction in xrange(n_poles_u):
113-
for pole_v_direction in xrange(n_poles_v):
112+
for pole_u_direction in range(n_poles_u):
113+
for pole_v_direction in range(n_poles_v):
114114
control_point_coordinates = occ_face.Pole(\
115115
pole_u_direction + 1, pole_v_direction + 1)
116116
control_polygon_coordinates[i, :] = [control_point_coordinates.X(),\
@@ -172,8 +172,8 @@ def write(self, mesh_points, filename, tolerance=None):
172172
n_poles_v = occ_face.NbVPoles()
173173

174174
i = 0
175-
for pole_u_direction in xrange(n_poles_u):
176-
for pole_v_direction in xrange(n_poles_v):
175+
for pole_u_direction in range(n_poles_u):
176+
for pole_v_direction in range(n_poles_v):
177177
control_point_coordinates = mesh_points[i + control_point_position[n_faces], :]
178178
point_xyz = gp_XYZ(*control_point_coordinates)
179179

pygem/params.py

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""
22
Utilities for reading and writing parameters files to perform the desired geometrical morphing.
33
"""
4-
import ConfigParser
4+
try:
5+
import configparser as configparser
6+
except ImportError:
7+
import ConfigParser as configparser
58
import os
69

710
import numpy as np
@@ -123,15 +126,15 @@ def read_parameters(self, filename='parameters.prm'):
123126
124127
:param string filename: parameters file to be read in.
125128
"""
126-
if not isinstance(filename, basestring):
129+
if not isinstance(filename, str):
127130
raise TypeError("filename must be a string")
128131

129132
# Checks if the parameters file exists. If not it writes the default class into filename.
130133
if not os.path.isfile(filename):
131134
self.write_parameters(filename)
132135
return
133136

134-
config = ConfigParser.RawConfigParser()
137+
config = configparser.RawConfigParser()
135138
config.read(filename)
136139

137140
self.n_control_points[0] = config.getint('Box info', 'n control points x')
@@ -197,7 +200,7 @@ def write_parameters(self, filename='parameters.prm'):
197200
198201
:param string filename: parameters file to be written out.
199202
"""
200-
if not isinstance(filename, basestring):
203+
if not isinstance(filename, str):
201204
raise TypeError("filename must be a string")
202205

203206
with open(filename, 'w') as output_file:
@@ -280,33 +283,33 @@ def print_info(self):
280283
"""
281284
This method prints all the FFD parameters on the screen. Its purpose is for debugging.
282285
"""
283-
print 'conversion_unit = ' + str(self.conversion_unit) + '\n'
284-
print '(lenght_box_x, lenght_box_y, lenght_box_z) = (' + str(self.lenght_box_x) + \
285-
', ' + str(self.lenght_box_y) + ', ' + str(self.lenght_box_z) + ')'
286-
print 'origin_box = ' + str(self.origin_box)
287-
print 'n_control_points = ' + str(self.n_control_points)
288-
print '(rot_angle_x, rot_angle_y, rot_angle_z) = (' + str(self.rot_angle_x) + \
289-
', ' + str(self.rot_angle_y) + ', ' + str(self.rot_angle_z) + ')'
290-
print '\narray_mu_x ='
291-
print self.array_mu_x
292-
print '\narray_mu_y ='
293-
print self.array_mu_y
294-
print '\narray_mu_z ='
295-
print self.array_mu_z
296-
print '\npsi_mapping ='
297-
print self.psi_mapping
298-
print '\ninv_psi_mapping ='
299-
print self.inv_psi_mapping
300-
print '\nrotation_matrix ='
301-
print self.rotation_matrix
302-
print '\nposition_vertex_0 ='
303-
print self.position_vertex_0
304-
print '\nposition_vertex_1 ='
305-
print self.position_vertex_1
306-
print '\nposition_vertex_2 ='
307-
print self.position_vertex_2
308-
print '\nposition_vertex_3 ='
309-
print self.position_vertex_3
286+
print('conversion_unit = ' + str(self.conversion_unit) + '\n')
287+
print('(lenght_box_x, lenght_box_y, lenght_box_z) = (' + str(self.lenght_box_x) + \
288+
', ' + str(self.lenght_box_y) + ', ' + str(self.lenght_box_z) + ')')
289+
print('origin_box = ' + str(self.origin_box))
290+
print('n_control_points = ' + str(self.n_control_points))
291+
print('(rot_angle_x, rot_angle_y, rot_angle_z) = (' + str(self.rot_angle_x) + \
292+
', ' + str(self.rot_angle_y) + ', ' + str(self.rot_angle_z) + ')')
293+
print('\narray_mu_x =')
294+
print(self.array_mu_x)
295+
print('\narray_mu_y =')
296+
print(self.array_mu_y)
297+
print('\narray_mu_z =')
298+
print(self.array_mu_z)
299+
print('\npsi_mapping =')
300+
print(self.psi_mapping)
301+
print('\ninv_psi_mapping =')
302+
print(self.inv_psi_mapping)
303+
print('\nrotation_matrix =')
304+
print(self.rotation_matrix)
305+
print('\nposition_vertex_0 =')
306+
print(self.position_vertex_0)
307+
print('\nposition_vertex_1 =')
308+
print(self.position_vertex_1)
309+
print('\nposition_vertex_2 =')
310+
print(self.position_vertex_2)
311+
print('\nposition_vertex_3 =')
312+
print(self.position_vertex_3)
310313

311314
def build_bounding_box(self, shape, tol=1e-6, triangulate=False, triangulate_tol=1e-1):
312315
"""
@@ -442,7 +445,7 @@ def read_parameters(self, filename='parameters_rbf.prm'):
442445
443446
:param string filename: parameters file to be read in. Default value is parameters_rbf.prm.
444447
"""
445-
if not isinstance(filename, basestring):
448+
if not isinstance(filename, str):
446449
raise TypeError('filename must be a string')
447450

448451
# Checks if the parameters file exists. If not it writes the default class into filename.
@@ -459,7 +462,7 @@ def read_parameters(self, filename='parameters_rbf.prm'):
459462
self.write_parameters(filename)
460463
return
461464

462-
config = ConfigParser.RawConfigParser()
465+
config = configparser.RawConfigParser()
463466
config.read(filename)
464467

465468
self.basis = config.get('Radial Basis Functions', 'basis function')
@@ -469,7 +472,7 @@ def read_parameters(self, filename='parameters_rbf.prm'):
469472
lines = ctrl_points.split('\n')
470473
self.n_control_points = len(lines)
471474
self.original_control_points = np.zeros((self.n_control_points, 3))
472-
for line, i in zip(lines, range(0, self.n_control_points)):
475+
for line, i in zip(lines, list(range(0, self.n_control_points))):
473476
values = line.split()
474477
self.original_control_points[i] = np.array([float(values[0]), float(values[1]), float(values[2])])
475478

@@ -481,7 +484,7 @@ def read_parameters(self, filename='parameters_rbf.prm'):
481484
" and in the 'deformed control points' section of the parameters file ({0!s})".format(filename))
482485

483486
self.deformed_control_points = np.zeros((self.n_control_points, 3))
484-
for line, i in zip(lines, range(0, self.n_control_points)):
487+
for line, i in zip(lines, list(range(0, self.n_control_points))):
485488
values = line.split()
486489
self.deformed_control_points[i] = np.array([float(values[0]), float(values[1]), float(values[2])])
487490

@@ -493,7 +496,7 @@ def write_parameters(self, filename='parameters_rbf.prm'):
493496
494497
:param string filename: parameters file to be written out.
495498
"""
496-
if not isinstance(filename, basestring):
499+
if not isinstance(filename, str):
497500
raise TypeError("filename must be a string")
498501

499502
with open(filename, 'w') as output_file:
@@ -540,10 +543,10 @@ def print_info(self):
540543
"""
541544
This method prints all the RBF parameters on the screen. Its purpose is for debugging.
542545
"""
543-
print 'basis function = ' + str(self.basis)
544-
print 'radius = ' + str(self.radius)
545-
print 'n_control_points = ' + str(self.n_control_points)
546-
print '\noriginal_control_points ='
547-
print self.original_control_points
548-
print '\ndeformed_control_points ='
549-
print self.deformed_control_points
546+
print('basis function = ' + str(self.basis))
547+
print('radius = ' + str(self.radius))
548+
print('n_control_points = ' + str(self.n_control_points))
549+
print('\noriginal_control_points =')
550+
print(self.original_control_points)
551+
print('\ndeformed_control_points =')
552+
print(self.deformed_control_points)

pygem/stlhandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def write(self, mesh_points, filename, write_bin=False):
6868

6969
n_vertices = mesh_points.shape[0]
7070
# number of triplets of vertices
71-
n_triplets = n_vertices / 3
71+
n_triplets = n_vertices // 3
7272
data = np.zeros(n_triplets, dtype=mesh.Mesh.dtype)
7373
stl_mesh = mesh.Mesh(data, remove_empty_areas=False)
7474

0 commit comments

Comments
 (0)