summaryrefslogtreecommitdiff
path: root/var
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2020-08-14 09:08:42 -0500
committerGitHub <noreply@github.com>2020-08-14 16:08:42 +0200
commit9ab8521a1c09558339900041647b2466c2709de9 (patch)
tree6322876abc28d33d3d3fb756d0fd40fd31205de6 /var
parent512ef506a7dc43df33b4f72ca4d569bf1319a600 (diff)
downloadspack-9ab8521a1c09558339900041647b2466c2709de9.tar.gz
spack-9ab8521a1c09558339900041647b2466c2709de9.tar.bz2
spack-9ab8521a1c09558339900041647b2466c2709de9.tar.xz
spack-9ab8521a1c09558339900041647b2466c2709de9.zip
Python: add spack external find support (#16684)
Diffstat (limited to 'var')
-rw-r--r--var/spack/repos/builtin/packages/python/package.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py
index 16bd621504..4282d8e014 100644
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -224,6 +224,75 @@ class Python(AutotoolsPackage):
# An in-source build with --enable-optimizations fails for python@3.X
build_directory = 'spack-build'
+ executables = [r'^python[\d.]*[mw]?$']
+
+ @classmethod
+ def determine_version(cls, exe):
+ # Newer versions of Python support `--version`,
+ # but older versions only support `-V`
+ # Python 2 sends to STDERR, while Python 3 sends to STDOUT
+ # Output looks like:
+ # Python 3.7.7
+ output = Executable(exe)('-V', output=str, error=str)
+ match = re.search(r'Python\s+(\S+)', output)
+ return match.group(1) if match else None
+
+ @classmethod
+ def determine_variants(cls, exes, version_str):
+ python = Executable(exes[0])
+
+ variants = ''
+ for module in ['readline', 'sqlite3', 'dbm', 'nis',
+ 'zlib', 'bz2', 'lzma', 'ctypes', 'uuid']:
+ try:
+ python('-c', 'import ' + module, error=os.devnull)
+ variants += '+' + module
+ except ProcessError:
+ variants += '~' + module
+
+ # Some variants enable multiple modules
+ try:
+ python('-c', 'import ssl', error=os.devnull)
+ python('-c', 'import hashlib', error=os.devnull)
+ variants += '+ssl'
+ except ProcessError:
+ variants += '~ssl'
+
+ try:
+ python('-c', 'import xml.parsers.expat', error=os.devnull)
+ python('-c', 'import xml.etree.ElementTree', error=os.devnull)
+ variants += '+pyexpat'
+ except ProcessError:
+ variants += '~pyexpat'
+
+ # Some modules changed names in Python 3
+ if Version(version_str) >= Version('3'):
+ try:
+ python('-c', 'import tkinter', error=os.devnull)
+ variants += '+tkinter'
+ except ProcessError:
+ variants += '~tkinter'
+
+ try:
+ python('-c', 'import tkinter.tix', error=os.devnull)
+ variants += '+tix'
+ except ProcessError:
+ variants += '~tix'
+ else:
+ try:
+ python('-c', 'import Tkinter', error=os.devnull)
+ variants += '+tkinter'
+ except ProcessError:
+ variants += '~tkinter'
+
+ try:
+ python('-c', 'import Tix', error=os.devnull)
+ variants += '+tix'
+ except ProcessError:
+ variants += '~tix'
+
+ return variants
+
def url_for_version(self, version):
url = "https://www.python.org/ftp/python/{0}/Python-{1}.tgz"
return url.format(re.split('[a-z]', str(version))[0], version)
@@ -606,6 +675,13 @@ class Python(AutotoolsPackage):
if '+uuid' in spec:
self.command('-c', 'import uuid')
+ # Ensure that tix module works
+ if '+tix' in spec:
+ if spec.satisfies('@3:'):
+ self.command('-c', 'import tkinter.tix')
+ else:
+ self.command('-c', 'import Tix')
+
# ========================================================================
# Set up environment to make install easy for python extensions.
# ========================================================================