Skip to content

Commit

Permalink
Merge pull request #62 from nwu63/six-fix
Browse files Browse the repository at this point in the history
Fix for requiring the six package
  • Loading branch information
eirikurj authored Nov 15, 2019
2 parents 57fc5e5 + e4616d8 commit 339aadb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pyOpt has the following dependencies:
* Swig 1.3+
* c/FORTRAN compiler (compatible with f2py)
* mpi4py
* six 1.13

Notes:

Expand Down
17 changes: 6 additions & 11 deletions pyoptsparse/pyOpt_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@
except ImportError:
try:
from ordereddict import OrderedDict
except ImportError:
print('Could not find any OrderedDict class. For 2.6 and earlier, \
except:
raise ImportError('Could not find any OrderedDict class. For 2.6 and earlier, \
use:\n pip install ordereddict')

try:
import six
from six import iteritems, iterkeys, next
except ImportError:
six = None
print ('Could not import \'six\' OpenMDAO type tuple return not available.')
except:
raise ImportError('Could not import \'six\'. To install, use\n pip install six')

from .sqlitedict.sqlitedict import SqliteDict

Expand Down Expand Up @@ -1325,12 +1324,8 @@ def processObjectiveGradient(self, funcsSens):
gobj = numpy.zeros((nobj, self.ndvs))

cond = False
if six:
# this version is required for python 3 compatibility
cond = isinstance(next(iterkeys(funcsSens)), str)
else:
# fallback if six is not available
cond = isinstance(funcsSens.keys()[0], str)
# this version is required for python 3 compatibility
cond = isinstance(next(iterkeys(funcsSens)), str)

if cond:
iObj = 0
Expand Down

0 comments on commit 339aadb

Please sign in to comment.