Merge pull request #950 from xjrc/packages/python

Enhancement Proposal: Make Python Spack Installs Ignore User Configuration
This commit is contained in:
Todd Gamblin 2016-07-22 13:56:19 -07:00 committed by GitHub
commit 395c616a48
3 changed files with 48 additions and 38 deletions

View File

@ -0,0 +1,5 @@
#!/bin/bash --noprofile
PYEXT_REGEX=".*/.*/package.py"
find var/spack/repos/builtin/packages/ -type f -regextype sed -regex ${PYEXT_REGEX} -exec \
sed -i 's/python('\''setup.py'\'', /setup_py(/' {} \;

View File

@ -24,8 +24,11 @@
##############################################################################
from spack import *
class PySetuptools(Package):
"""Easily download, build, install, upgrade, and uninstall Python packages."""
"""A Python utility that aids in the process of downloading, building,
upgrading, installing, and uninstalling Python packages."""
homepage = "https://pypi.python.org/pypi/setuptools"
url = "https://pypi.python.org/packages/source/s/setuptools/setuptools-11.3.tar.gz"
@ -40,4 +43,4 @@ class PySetuptools(Package):
extends('python')
def install(self, spec, prefix):
python('setup.py', 'install', '--prefix=%s' % prefix)
setup_py('install', '--prefix=%s' % prefix)

View File

@ -27,6 +27,7 @@
from contextlib import closing
import spack
import llnl.util.tty as tty
from llnl.util.lang import match_predicate
from spack import *
from spack.util.environment import *
@ -72,40 +73,41 @@ class Python(Package):
depends_on("tk", when="+tk")
depends_on("tcl", when="+tk")
@when('@2.7,3.4:')
def patch(self):
# NOTE: Python's default installation procedure makes it possible for a
# user's local configurations to change the Spack installation. In
# order to prevent this behavior for a full installation, we must
# modify the installation script so that it ignores user files.
ff = FileFilter('Makefile.pre.in')
ff.filter(
r'^(.*)setup\.py(.*)((build)|(install))(.*)$',
r'\1setup.py\2 --no-user-cfg \3\6'
)
def install(self, spec, prefix):
# TODO: The '--no-user-cfg' option for Python installation is only in
# Python v2.7 and v3.4+ (see https://bugs.python.org/issue1180) and
# adding support for ignoring user configuration will require
# significant changes to this package for other Python versions.
if not spec.satisfies('@2.7,3.4:'):
tty.warn(('Python v{0} may not install properly if Python '
'user configurations are present.').format(self.version))
# Need this to allow python build to find the Python installation.
env['PYTHONHOME'] = prefix
env['PYTHONHOME'], env['PYTHONPATH'] = prefix, prefix
env['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
# 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
include_dirs = [
spec['openssl'].prefix.include, spec['bzip2'].prefix.include,
spec['readline'].prefix.include, spec['ncurses'].prefix.include,
spec['sqlite'].prefix.include, spec['zlib'].prefix.include
]
library_dirs = [
spec['openssl'].prefix.lib, spec['bzip2'].prefix.lib,
spec['readline'].prefix.lib, spec['ncurses'].prefix.lib,
spec['sqlite'].prefix.lib, spec['zlib'].prefix.lib
]
if '+tk' in spec:
include_dirs.extend([
spec['tk'].prefix.include, spec['tcl'].prefix.include
])
library_dirs.extend([
spec['tk'].prefix.lib, spec['tcl'].prefix.lib
])
dep_pfxs = [dspec.prefix for dspec in spec.dependencies('link')]
config_args = [
"--prefix={0}".format(prefix),
"--with-threads",
"--enable-shared",
"CPPFLAGS=-I{0}".format(" -I".join(include_dirs)),
"LDFLAGS=-L{0}".format(" -L".join(library_dirs))
'--prefix={0}'.format(prefix),
'--with-threads',
'--enable-shared',
'CPPFLAGS=-I{0}'.format(' -I'.join(dp.include for dp in dep_pfxs)),
'LDFLAGS=-L{0}'.format(' -L'.join(dp.lib for dp in dep_pfxs)),
]
if '+ucs4' in spec:
@ -121,9 +123,8 @@ def install(self, spec, prefix):
config_args.append('--without-ensurepip')
configure(*config_args)
make()
make("install")
make('install')
self.filter_compilers(spec, prefix)
@ -193,6 +194,8 @@ def site_packages_dir(self):
def setup_dependent_environment(self, spack_env, run_env, extension_spec):
"""Set PYTHONPATH to include site-packages dir for the
extension and any other python extensions it depends on."""
pythonhome = self.prefix
spack_env.set('PYTHONHOME', pythonhome)
python_paths = []
for d in extension_spec.traverse(deptype=nolink, deptype_query='run'):
@ -214,15 +217,14 @@ def setup_dependent_package(self, module, ext_spec):
In most cases, extensions will only need to have one line::
python('setup.py', 'install', '--prefix={0}'.format(prefix))"""
setup_py('install', '--prefix={0}'.format(prefix))"""
python_path = join_path(
self.spec.prefix.bin,
'python{0}'.format('3' if self.spec.satisfies('@3') else '')
)
# Python extension builds can have a global python executable function
if Version("3.0.0") <= self.version < Version("4.0.0"):
module.python = Executable(join_path(self.spec.prefix.bin,
'python3'))
else:
module.python = Executable(join_path(self.spec.prefix.bin,
'python'))
module.python = Executable(python_path)
module.setup_py = Executable(python_path + ' setup.py --no-user-cfg')
# Add variables for lib/pythonX.Y and lib/pythonX.Y/site-packages dirs.
module.python_lib_dir = join_path(ext_spec.prefix,