diff options
author | Adam J. Stewart <ajstewart426@gmail.com> | 2018-09-10 17:14:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-10 17:14:57 -0500 |
commit | ccbff6e0cdc1e4e045656a784e28225f416a8ed4 (patch) | |
tree | 6865d250920ead229db04edf65773c926eb17456 | |
parent | 3dcbe50eb78bfb000790ce68466064afb0c32db2 (diff) | |
download | spack-ccbff6e0cdc1e4e045656a784e28225f416a8ed4.tar.gz spack-ccbff6e0cdc1e4e045656a784e28225f416a8ed4.tar.bz2 spack-ccbff6e0cdc1e4e045656a784e28225f416a8ed4.tar.xz spack-ccbff6e0cdc1e4e045656a784e28225f416a8ed4.zip |
Improve spec['python'].command support for bwpy (#9157)
-rw-r--r-- | var/spack/repos/builtin/packages/python/package.py | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py index ac42ffa547..7a28566386 100644 --- a/var/spack/repos/builtin/packages/python/package.py +++ b/var/spack/repos/builtin/packages/python/package.py @@ -398,37 +398,32 @@ class Python(AutotoolsPackage): on the version of Python and how it was installed. In general, Python 2 comes with ``python`` and ``python2`` commands, - while Python 3 only comes with a ``python3`` command. + while Python 3 only comes with a ``python3`` command. However, some + package managers will symlink ``python`` to ``python3``, while others + may contain ``python3.6``, ``python3.5``, and ``python3.4`` in the + same directory. - :returns: The Python command - :rtype: Executable + Returns: + Executable: the Python command """ # We need to be careful here. If the user is using an externally - # installed python, all 3 commands could be in the same directory. - - # Search for `python2` iff using Python 2 - if (self.spec.satisfies('@:2') and - os.path.exists(os.path.join(self.prefix.bin, 'python2'))): - command = 'python2' - # Search for `python3` iff using Python 3 - elif (self.spec.satisfies('@3:') and - os.path.exists(os.path.join(self.prefix.bin, 'python3'))): - command = 'python3' - # If neither were found, try `python` - elif os.path.exists(os.path.join(self.prefix.bin, 'python')): - command = 'python' + # installed python, several different commands could be located + # in the same directory. Be as specific as possible. Search for: + # + # * python3.6 + # * python3 + # * python + # + # in that order if using python@3.6.5, for example. + version = self.spec.version + for ver in [version.up_to(2), version.up_to(1), '']: + path = os.path.join(self.prefix.bin, 'python{0}'.format(ver)) + if os.path.exists(path): + return Executable(path) else: msg = 'Unable to locate {0} command in {1}' raise RuntimeError(msg.format(self.name, self.prefix.bin)) - # The python command may be a symlink if it was installed - # with Homebrew. Since some packages try to determine the - # location of libraries and headers based on the path, - # return the realpath - path = os.path.realpath(os.path.join(self.prefix.bin, command)) - - return Executable(path) - def print_string(self, string): """Returns the appropriate print string depending on the version of Python. |