2016-05-12 12:22:25 +08:00
|
|
|
##############################################################################
|
|
|
|
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
|
|
|
|
# Produced at the Lawrence Livermore National Laboratory.
|
|
|
|
#
|
|
|
|
# This file is part of Spack.
|
|
|
|
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
|
|
|
|
# LLNL-CODE-647188
|
|
|
|
#
|
|
|
|
# For details, see https://github.com/llnl/spack
|
|
|
|
# Please also see the LICENSE file for our notice and the LGPL.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License (as
|
|
|
|
# published by the Free Software Foundation) version 2.1, February 1999.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
|
|
|
|
# conditions of the GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
##############################################################################
|
2015-01-11 11:37:01 +08:00
|
|
|
import os
|
2015-01-21 07:07:53 +08:00
|
|
|
import re
|
2015-02-02 22:09:35 +08:00
|
|
|
from contextlib import closing
|
|
|
|
|
2015-02-09 18:54:49 +08:00
|
|
|
import spack
|
2016-03-18 21:40:53 +08:00
|
|
|
from llnl.util.lang import match_predicate
|
|
|
|
from spack import *
|
|
|
|
from spack.util.environment import *
|
2015-02-09 18:54:49 +08:00
|
|
|
|
2015-01-08 03:48:21 +08:00
|
|
|
|
2014-10-31 06:02:06 +08:00
|
|
|
class Python(Package):
|
|
|
|
"""The Python programming language."""
|
2016-06-18 02:33:09 +08:00
|
|
|
|
2014-10-31 06:02:06 +08:00
|
|
|
homepage = "http://www.python.org"
|
2016-01-09 06:16:30 +08:00
|
|
|
url = "http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz"
|
2014-10-31 06:02:06 +08:00
|
|
|
|
2016-07-07 20:09:08 +08:00
|
|
|
version('3.5.2', '3fe8434643a78630c61c6464fe2e7e72')
|
2016-01-09 06:16:30 +08:00
|
|
|
version('3.5.1', 'be78e48cdfc1a7ad90efff146dce6cfe')
|
|
|
|
version('3.5.0', 'a56c0c0b45d75a0ec9c6dee933c41c36')
|
2016-07-07 20:09:08 +08:00
|
|
|
version('3.4.3', '4281ff86778db65892c05151d5de738d')
|
|
|
|
version('3.3.6', 'cdb3cd08f96f074b3f3994ccb51063e9')
|
|
|
|
version('3.2.6', '23815d82ae706e9b781ca65865353d39')
|
|
|
|
version('3.1.5', '02196d3fc7bc76bdda68aa36b0dd16ab')
|
|
|
|
version('2.7.12', '88d61f82e3616a4be952828b3694109d', preferred=True)
|
|
|
|
version('2.7.11', '6b6076ec9e93f05dd63e47eb9c15728b')
|
2016-01-09 06:16:30 +08:00
|
|
|
version('2.7.10', 'd7547558fd673bd9d38e2108c6b42521')
|
|
|
|
version('2.7.9', '5eebcaa0030dc4061156d3429657fb83')
|
|
|
|
version('2.7.8', 'd4bca0159acb0b44a781292b5231936f')
|
2014-10-31 06:02:06 +08:00
|
|
|
|
2016-06-18 02:33:09 +08:00
|
|
|
extendable = True
|
|
|
|
|
2016-07-07 20:12:43 +08:00
|
|
|
variant('ucs4', default=False, description='Enable UCS4 (wide) unicode strings')
|
2016-07-07 01:29:54 +08:00
|
|
|
|
2014-10-31 06:02:06 +08:00
|
|
|
depends_on("openssl")
|
2014-11-03 16:15:05 +08:00
|
|
|
depends_on("bzip2")
|
|
|
|
depends_on("readline")
|
|
|
|
depends_on("ncurses")
|
2014-10-31 06:02:06 +08:00
|
|
|
depends_on("sqlite")
|
2015-12-02 22:20:11 +08:00
|
|
|
depends_on("zlib")
|
2014-10-31 06:02:06 +08:00
|
|
|
|
|
|
|
def install(self, spec, prefix):
|
2014-11-03 16:15:05 +08:00
|
|
|
# Need this to allow python build to find the Python installation.
|
|
|
|
env['PYTHONHOME'] = prefix
|
2015-11-20 06:52:22 +08:00
|
|
|
env['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
|
2014-11-03 16:15:05 +08:00
|
|
|
|
2016-03-03 14:38:21 +08:00
|
|
|
# Rest of install is pretty standard except setup.py needs to
|
|
|
|
# be able to read the CPPFLAGS and LDFLAGS as it scans for the
|
|
|
|
# library and headers to build
|
2016-06-18 02:33:09 +08:00
|
|
|
cppflags = ' -I'.join([
|
|
|
|
spec['openssl'].prefix.include, spec['bzip2'].prefix.include,
|
|
|
|
spec['readline'].prefix.include, spec['ncurses'].prefix.include,
|
|
|
|
spec['sqlite'].prefix.include, spec['zlib'].prefix.include
|
|
|
|
])
|
|
|
|
|
|
|
|
ldflags = ' -L'.join([
|
|
|
|
spec['openssl'].prefix.lib, spec['bzip2'].prefix.lib,
|
|
|
|
spec['readline'].prefix.lib, spec['ncurses'].prefix.lib,
|
|
|
|
spec['sqlite'].prefix.lib, spec['zlib'].prefix.lib
|
|
|
|
])
|
|
|
|
|
|
|
|
config_args = [
|
|
|
|
"--prefix={0}".format(prefix),
|
|
|
|
"--with-threads",
|
|
|
|
"--enable-shared",
|
|
|
|
"CPPFLAGS=-I{0}".format(cppflags),
|
|
|
|
"LDFLAGS=-L{0}".format(ldflags)
|
|
|
|
]
|
|
|
|
|
2016-07-07 01:29:54 +08:00
|
|
|
if '+ucs4' in spec:
|
2016-07-07 20:18:40 +08:00
|
|
|
if spec.satisfies('@:2.7'):
|
2016-07-07 20:12:43 +08:00
|
|
|
config_args.append('--enable-unicode=ucs4')
|
|
|
|
elif spec.satisfies('@3.0:3.2'):
|
|
|
|
config_args.append('--with-wide-unicode')
|
2016-07-07 01:29:54 +08:00
|
|
|
|
2015-12-22 22:50:18 +08:00
|
|
|
if spec.satisfies('@3:'):
|
2016-06-18 02:33:09 +08:00
|
|
|
config_args.append('--without-ensurepip')
|
|
|
|
|
|
|
|
configure(*config_args)
|
|
|
|
|
2014-10-31 06:02:06 +08:00
|
|
|
make()
|
|
|
|
make("install")
|
2015-01-11 11:37:01 +08:00
|
|
|
|
2016-06-18 02:33:09 +08:00
|
|
|
self.filter_compilers(spec, prefix)
|
|
|
|
|
|
|
|
def filter_compilers(self, spec, prefix):
|
|
|
|
"""Run after install to tell the configuration files and Makefiles
|
|
|
|
to use the compilers that Spack built the package with.
|
|
|
|
|
|
|
|
If this isn't done, they'll have CC and CXX set to Spack's generic
|
|
|
|
cc and c++. We want them to be bound to whatever compiler
|
|
|
|
they were built with."""
|
|
|
|
|
|
|
|
kwargs = {'ignore_absent': True, 'backup': False, 'string': True}
|
2016-02-19 07:45:29 +08:00
|
|
|
|
2016-06-18 02:33:09 +08:00
|
|
|
dirname = join_path(prefix.lib,
|
|
|
|
'python{0}'.format(self.version.up_to(2)))
|
|
|
|
|
|
|
|
config = 'config'
|
2016-02-19 07:45:29 +08:00
|
|
|
if spec.satisfies('@3:'):
|
2016-06-18 02:33:09 +08:00
|
|
|
config = 'config-{0}m'.format(self.version.up_to(2))
|
|
|
|
|
|
|
|
files = [
|
|
|
|
'_sysconfigdata.py',
|
|
|
|
join_path(config, 'Makefile')
|
|
|
|
]
|
2016-02-19 07:45:29 +08:00
|
|
|
|
2016-06-18 02:33:09 +08:00
|
|
|
for filename in files:
|
|
|
|
filter_file(env['CC'], self.compiler.cc,
|
|
|
|
join_path(dirname, filename), **kwargs)
|
|
|
|
filter_file(env['CXX'], self.compiler.cxx,
|
|
|
|
join_path(dirname, filename), **kwargs)
|
2015-01-11 11:37:01 +08:00
|
|
|
|
2015-02-02 22:09:35 +08:00
|
|
|
# ========================================================================
|
|
|
|
# Set up environment to make install easy for python extensions.
|
|
|
|
# ========================================================================
|
|
|
|
|
2015-01-20 16:23:16 +08:00
|
|
|
@property
|
|
|
|
def python_lib_dir(self):
|
2016-06-18 02:33:09 +08:00
|
|
|
return join_path('lib', 'python{0}'.format(self.version.up_to(2)))
|
2015-01-20 16:23:16 +08:00
|
|
|
|
2015-02-15 17:59:36 +08:00
|
|
|
@property
|
|
|
|
def python_include_dir(self):
|
2016-06-18 02:33:09 +08:00
|
|
|
return join_path('include', 'python{0}'.format(self.version.up_to(2)))
|
2015-02-15 17:59:36 +08:00
|
|
|
|
2015-01-20 16:23:16 +08:00
|
|
|
@property
|
|
|
|
def site_packages_dir(self):
|
2016-06-18 02:33:09 +08:00
|
|
|
return join_path(self.python_lib_dir, 'site-packages')
|
2016-03-21 16:48:18 +08:00
|
|
|
|
|
|
|
def setup_dependent_environment(self, spack_env, run_env, extension_spec):
|
2016-06-18 02:33:09 +08:00
|
|
|
"""Set PYTHONPATH to include site-packages dir for the
|
|
|
|
extension and any other python extensions it depends on."""
|
2016-03-21 16:48:18 +08:00
|
|
|
|
2016-03-17 22:11:39 +08:00
|
|
|
python_paths = []
|
|
|
|
for d in extension_spec.traverse():
|
|
|
|
if d.package.extends(self.spec):
|
2016-06-18 02:33:09 +08:00
|
|
|
python_paths.append(join_path(d.prefix,
|
|
|
|
self.site_packages_dir))
|
2016-03-21 16:48:18 +08:00
|
|
|
|
|
|
|
pythonpath = ':'.join(python_paths)
|
2016-03-21 17:21:31 +08:00
|
|
|
spack_env.set('PYTHONPATH', pythonpath)
|
2016-03-23 18:18:11 +08:00
|
|
|
|
2016-06-18 02:33:09 +08:00
|
|
|
# For run time environment set only the path for
|
|
|
|
# extension_spec and prepend it to PYTHONPATH
|
2016-03-23 18:18:11 +08:00
|
|
|
if extension_spec.package.extends(self.spec):
|
2016-06-18 02:33:09 +08:00
|
|
|
run_env.prepend_path('PYTHONPATH', join_path(
|
|
|
|
extension_spec.prefix, self.site_packages_dir))
|
2016-03-17 22:11:39 +08:00
|
|
|
|
2016-03-23 15:36:32 +08:00
|
|
|
def setup_dependent_package(self, module, ext_spec):
|
2016-06-18 02:33:09 +08:00
|
|
|
"""Called before python modules' install() methods.
|
2015-01-11 11:37:01 +08:00
|
|
|
|
|
|
|
In most cases, extensions will only need to have one line::
|
|
|
|
|
2016-06-18 02:33:09 +08:00
|
|
|
python('setup.py', 'install', '--prefix={0}'.format(prefix))"""
|
|
|
|
|
2015-01-11 11:37:01 +08:00
|
|
|
# Python extension builds can have a global python executable function
|
2016-06-18 02:33:09 +08:00
|
|
|
if Version("3.0.0") <= self.version < Version("4.0.0"):
|
|
|
|
module.python = Executable(join_path(self.spec.prefix.bin,
|
|
|
|
'python3'))
|
2015-12-02 22:20:11 +08:00
|
|
|
else:
|
2016-06-18 02:33:09 +08:00
|
|
|
module.python = Executable(join_path(self.spec.prefix.bin,
|
|
|
|
'python'))
|
2015-01-11 11:37:01 +08:00
|
|
|
|
|
|
|
# Add variables for lib/pythonX.Y and lib/pythonX.Y/site-packages dirs.
|
2016-06-18 02:33:09 +08:00
|
|
|
module.python_lib_dir = join_path(ext_spec.prefix,
|
|
|
|
self.python_lib_dir)
|
|
|
|
module.python_include_dir = join_path(ext_spec.prefix,
|
|
|
|
self.python_include_dir)
|
|
|
|
module.site_packages_dir = join_path(ext_spec.prefix,
|
|
|
|
self.site_packages_dir)
|
|
|
|
|
|
|
|
# Make the site packages directory for extensions
|
2016-03-23 15:36:32 +08:00
|
|
|
if ext_spec.package.is_extension:
|
|
|
|
mkdirp(module.site_packages_dir)
|
2015-01-20 16:23:16 +08:00
|
|
|
|
2015-02-02 22:09:35 +08:00
|
|
|
# ========================================================================
|
|
|
|
# Handle specifics of activating and deactivating python modules.
|
|
|
|
# ========================================================================
|
|
|
|
|
|
|
|
def python_ignore(self, ext_pkg, args):
|
2015-01-20 16:23:16 +08:00
|
|
|
"""Add some ignore files to activate/deactivate args."""
|
2015-02-17 16:21:15 +08:00
|
|
|
ignore_arg = args.get('ignore', lambda f: False)
|
2015-02-02 22:09:35 +08:00
|
|
|
|
2015-02-17 16:21:15 +08:00
|
|
|
# Always ignore easy-install.pth, as it needs to be merged.
|
2016-06-16 05:42:50 +08:00
|
|
|
patterns = [r'site-packages/easy-install\.pth$']
|
2015-02-02 22:09:35 +08:00
|
|
|
|
2015-02-17 16:21:15 +08:00
|
|
|
# Ignore pieces of setuptools installed by other packages.
|
2016-06-18 02:33:09 +08:00
|
|
|
# Must include directory name or it will remove all site*.py files.
|
2015-02-17 16:21:15 +08:00
|
|
|
if ext_pkg.name != 'py-setuptools':
|
2016-06-18 02:33:09 +08:00
|
|
|
patterns.extend([
|
|
|
|
r'bin/easy_install[^/]*$',
|
|
|
|
r'site-packages/setuptools[^/]*\.egg$',
|
|
|
|
r'site-packages/setuptools\.pth$',
|
|
|
|
r'site-packages/site[^/]*\.pyc?$',
|
|
|
|
r'site-packages/__pycache__/site[^/]*\.pyc?$'
|
|
|
|
])
|
2016-06-21 07:17:07 +08:00
|
|
|
if ext_pkg.name != 'py-pygments':
|
|
|
|
patterns.append(r'bin/pygmentize$')
|
2016-04-27 01:32:14 +08:00
|
|
|
if ext_pkg.name != 'py-numpy':
|
2016-06-22 00:23:58 +08:00
|
|
|
patterns.append(r'bin/f2py3?$')
|
2015-02-02 22:09:35 +08:00
|
|
|
|
2015-02-17 16:21:15 +08:00
|
|
|
return match_predicate(ignore_arg, patterns)
|
2015-01-20 16:23:16 +08:00
|
|
|
|
2015-02-15 17:58:35 +08:00
|
|
|
def write_easy_install_pth(self, exts):
|
2015-02-02 22:09:35 +08:00
|
|
|
paths = []
|
2015-02-15 17:58:35 +08:00
|
|
|
for ext in sorted(exts.values()):
|
2016-06-18 02:33:09 +08:00
|
|
|
ext_site_packages = join_path(ext.prefix, self.site_packages_dir)
|
|
|
|
easy_pth = join_path(ext_site_packages, "easy-install.pth")
|
2015-02-02 22:09:35 +08:00
|
|
|
|
|
|
|
if not os.path.isfile(easy_pth):
|
|
|
|
continue
|
|
|
|
|
|
|
|
with closing(open(easy_pth)) as f:
|
|
|
|
for line in f:
|
|
|
|
line = line.rstrip()
|
|
|
|
|
|
|
|
# Skip lines matching these criteria
|
2016-06-18 02:33:09 +08:00
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
if re.search(r'^(import|#)', line):
|
|
|
|
continue
|
|
|
|
if ((ext.name != 'py-setuptools' and
|
|
|
|
re.search(r'setuptools.*egg$', line))):
|
|
|
|
continue
|
2015-02-02 22:09:35 +08:00
|
|
|
|
|
|
|
paths.append(line)
|
|
|
|
|
2016-06-18 02:33:09 +08:00
|
|
|
site_packages = join_path(self.prefix, self.site_packages_dir)
|
|
|
|
main_pth = join_path(site_packages, "easy-install.pth")
|
2015-02-02 22:09:35 +08:00
|
|
|
|
|
|
|
if not paths:
|
|
|
|
if os.path.isfile(main_pth):
|
|
|
|
os.remove(main_pth)
|
|
|
|
|
|
|
|
else:
|
|
|
|
with closing(open(main_pth, 'w')) as f:
|
2016-06-18 02:33:09 +08:00
|
|
|
f.write("""
|
|
|
|
import sys
|
|
|
|
sys.__plen = len(sys.path)
|
|
|
|
""")
|
2015-02-02 22:09:35 +08:00
|
|
|
for path in paths:
|
2016-06-18 02:33:09 +08:00
|
|
|
f.write("{0}\n".format(path))
|
|
|
|
f.write("""
|
|
|
|
new = sys.path[sys.__plen:]
|
|
|
|
del sys.path[sys.__plen:]
|
|
|
|
p = getattr(sys, '__egginsert', 0)
|
|
|
|
sys.path[p:p] = new
|
|
|
|
sys.__egginsert = p + len(new)
|
|
|
|
""")
|
2015-02-02 22:09:35 +08:00
|
|
|
|
2015-01-20 16:23:16 +08:00
|
|
|
def activate(self, ext_pkg, **args):
|
2016-06-18 02:33:09 +08:00
|
|
|
ignore = self.python_ignore(ext_pkg, args)
|
2015-05-11 08:56:27 +08:00
|
|
|
args.update(ignore=ignore)
|
|
|
|
|
2015-01-20 16:23:16 +08:00
|
|
|
super(Python, self).activate(ext_pkg, **args)
|
|
|
|
|
2015-02-15 17:58:35 +08:00
|
|
|
exts = spack.install_layout.extension_map(self.spec)
|
|
|
|
exts[ext_pkg.name] = ext_pkg.spec
|
|
|
|
self.write_easy_install_pth(exts)
|
2015-02-02 22:09:35 +08:00
|
|
|
|
2015-01-20 16:23:16 +08:00
|
|
|
def deactivate(self, ext_pkg, **args):
|
2015-02-02 22:09:35 +08:00
|
|
|
args.update(ignore=self.python_ignore(ext_pkg, args))
|
2015-01-20 16:23:16 +08:00
|
|
|
super(Python, self).deactivate(ext_pkg, **args)
|
2015-02-02 22:09:35 +08:00
|
|
|
|
2015-02-15 17:58:35 +08:00
|
|
|
exts = spack.install_layout.extension_map(self.spec)
|
2016-06-18 02:33:09 +08:00
|
|
|
# Make deactivate idempotent
|
|
|
|
if ext_pkg.name in exts:
|
2015-02-17 04:41:22 +08:00
|
|
|
del exts[ext_pkg.name]
|
|
|
|
self.write_easy_install_pth(exts)
|