Improve spec['python'].command support for bwpy (#9157)
This commit is contained in:
parent
3dcbe50eb7
commit
ccbff6e0cd
@ -398,37 +398,32 @@ def command(self):
|
|||||||
on the version of Python and how it was installed.
|
on the version of Python and how it was installed.
|
||||||
|
|
||||||
In general, Python 2 comes with ``python`` and ``python2`` commands,
|
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
|
Returns:
|
||||||
:rtype: Executable
|
Executable: the Python command
|
||||||
"""
|
"""
|
||||||
# We need to be careful here. If the user is using an externally
|
# We need to be careful here. If the user is using an externally
|
||||||
# installed python, all 3 commands could be in the same directory.
|
# installed python, several different commands could be located
|
||||||
|
# in the same directory. Be as specific as possible. Search for:
|
||||||
# Search for `python2` iff using Python 2
|
#
|
||||||
if (self.spec.satisfies('@:2') and
|
# * python3.6
|
||||||
os.path.exists(os.path.join(self.prefix.bin, 'python2'))):
|
# * python3
|
||||||
command = 'python2'
|
# * python
|
||||||
# Search for `python3` iff using Python 3
|
#
|
||||||
elif (self.spec.satisfies('@3:') and
|
# in that order if using python@3.6.5, for example.
|
||||||
os.path.exists(os.path.join(self.prefix.bin, 'python3'))):
|
version = self.spec.version
|
||||||
command = 'python3'
|
for ver in [version.up_to(2), version.up_to(1), '']:
|
||||||
# If neither were found, try `python`
|
path = os.path.join(self.prefix.bin, 'python{0}'.format(ver))
|
||||||
elif os.path.exists(os.path.join(self.prefix.bin, 'python')):
|
if os.path.exists(path):
|
||||||
command = 'python'
|
return Executable(path)
|
||||||
else:
|
else:
|
||||||
msg = 'Unable to locate {0} command in {1}'
|
msg = 'Unable to locate {0} command in {1}'
|
||||||
raise RuntimeError(msg.format(self.name, self.prefix.bin))
|
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):
|
def print_string(self, string):
|
||||||
"""Returns the appropriate print string depending on the
|
"""Returns the appropriate print string depending on the
|
||||||
version of Python.
|
version of Python.
|
||||||
|
Loading…
Reference in New Issue
Block a user