diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/create.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/environment.py | 10 | ||||
-rw-r--r-- | lib/spack/spack/modules.py | 25 | ||||
-rw-r--r-- | lib/spack/spack/platforms/cray.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/preferred_packages.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/stage.py | 3 | ||||
-rw-r--r-- | lib/spack/spack/test/__init__.py | 6 | ||||
-rw-r--r-- | lib/spack/spack/test/concretize_preferences.py | 106 | ||||
-rw-r--r-- | lib/spack/spack/test/modules.py | 9 |
9 files changed, 153 insertions, 14 deletions
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py index da74ceb2f6..51bf17a44b 100644 --- a/lib/spack/spack/cmd/create.py +++ b/lib/spack/spack/cmd/create.py @@ -165,7 +165,7 @@ install_dict = { 'python': """\ # FIXME: Add logic to build and install here. - python('setup.py', 'install', '--prefix={0}'.format(prefix))""", + setup_py('install', '--prefix={0}'.format(prefix))""", 'R': """\ # FIXME: Add logic to build and install here. diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 30c6228ca4..41136ab2eb 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -37,6 +37,10 @@ class NameModifier(object): self.args = {'name': name} self.args.update(kwargs) + def update_args(self, **kwargs): + self.__dict__.update(kwargs) + self.args.update(kwargs) + class NameValueModifier(object): @@ -44,7 +48,11 @@ class NameValueModifier(object): self.name = name self.value = value self.separator = kwargs.get('separator', ':') - self.args = {'name': name, 'value': value, 'delim': self.separator} + self.args = {'name': name, 'value': value, 'separator': self.separator} + self.args.update(kwargs) + + def update_args(self, **kwargs): + self.__dict__.update(kwargs) self.args.update(kwargs) diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index db8b20ae42..8701a31c49 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -272,14 +272,26 @@ class EnvModule(object): @property def tokens(self): + """Tokens that can be substituted in environment variable values + and naming schemes + """ tokens = { 'name': self.spec.name, 'version': self.spec.version, - 'compiler': self.spec.compiler + 'compiler': self.spec.compiler, + 'prefix': self.spec.package.prefix } return tokens @property + def upper_tokens(self): + """Tokens that can be substituted in environment variable names""" + upper_tokens = { + 'name': self.spec.name.replace('-', '_').upper() + } + return upper_tokens + + @property def use_name(self): """ Subclasses should implement this to return the name the module command @@ -438,6 +450,11 @@ class EnvModule(object): def process_environment_command(self, env): for command in env: + # Token expansion from configuration file + name = command.args.get('name', '').format(**self.upper_tokens) + value = str(command.args.get('value', '')).format(**self.tokens) + command.update_args(name=name, value=value) + # Format the line int the module file try: yield self.environment_modifications_formats[type( command)].format(**command.args) @@ -511,9 +528,9 @@ class TclModule(EnvModule): name = 'tcl' path = join_path(spack.share_path, "modules") environment_modifications_formats = { - PrependPath: 'prepend-path --delim "{delim}" {name} \"{value}\"\n', - AppendPath: 'append-path --delim "{delim}" {name} \"{value}\"\n', - RemovePath: 'remove-path --delim "{delim}" {name} \"{value}\"\n', + PrependPath: 'prepend-path --delim "{separator}" {name} \"{value}\"\n', + AppendPath: 'append-path --delim "{separator}" {name} \"{value}\"\n', + RemovePath: 'remove-path --delim "{separator}" {name} \"{value}\"\n', SetEnv: 'setenv {name} \"{value}\"\n', UnsetEnv: 'unsetenv {name}\n' } diff --git a/lib/spack/spack/platforms/cray.py b/lib/spack/spack/platforms/cray.py index 2a3b81cf9c..0059b49ff1 100644 --- a/lib/spack/spack/platforms/cray.py +++ b/lib/spack/spack/platforms/cray.py @@ -98,7 +98,7 @@ class Cray(Platform): cray_wrapper_names = join_path(spack.build_env_path, 'cray') if os.path.isdir(cray_wrapper_names): env.prepend_path('PATH', cray_wrapper_names) - env.prepend_path('SPACK_ENV_PATHS', cray_wrapper_names) + env.prepend_path('SPACK_ENV_PATH', cray_wrapper_names) @classmethod def detect(self): diff --git a/lib/spack/spack/preferred_packages.py b/lib/spack/spack/preferred_packages.py index 5f18e212b6..f079c1ef8b 100644 --- a/lib/spack/spack/preferred_packages.py +++ b/lib/spack/spack/preferred_packages.py @@ -162,8 +162,8 @@ class PreferredPackages(object): """Return a VariantMap of preferred variants and their values""" variants = self.preferred.get(pkgname, {}).get('variants', '') if not isinstance(variants, basestring): - variants = "".join(variants) - return spack.spec.Spec(pkgname + variants).variants + variants = " ".join(variants) + return spack.spec.Spec("%s %s" % (pkgname, variants)).variants def version_compare(self, pkgname, a, b): """Return less-than-0, 0, or greater than 0 if version a of pkgname is diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 1a8b1a169a..553c4ad05f 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -318,10 +318,11 @@ class Stage(object): fetchers.insert(0, spack.cache.fetcher(self.mirror_path, digest)) # Look for the archive in list_url - archive_version = spack.url.parse_version(self.default_fetcher.url) package_name = os.path.dirname(self.mirror_path) pkg = spack.repo.get(package_name) if pkg.list_url is not None and pkg.url is not None: + archive_version = spack.url.parse_version( + self.default_fetcher.url) versions = pkg.fetch_remote_versions() try: url_from_list = versions[Version(archive_version)] diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index a849d5f350..3439764ee6 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -39,9 +39,9 @@ test_names = [ 'pattern', 'python_version', 'git_fetch', 'svn_fetch', 'hg_fetch', 'mirror', 'modules', 'url_extrapolate', 'cc', 'link_tree', 'spec_yaml', 'optional_deps', 'make_executable', 'build_system_guess', 'lock', - 'database', 'namespace_trie', 'yaml', 'sbang', 'environment', 'cmd.find', - 'cmd.uninstall', 'cmd.test_install', 'cmd.test_compiler_cmd', - 'cmd.module' + 'database', 'namespace_trie', 'yaml', 'sbang', 'environment', + 'concretize_preferences', 'cmd.find', 'cmd.uninstall', 'cmd.test_install', + 'cmd.test_compiler_cmd', 'cmd.module' ] diff --git a/lib/spack/spack/test/concretize_preferences.py b/lib/spack/spack/test/concretize_preferences.py new file mode 100644 index 0000000000..2c8bedc33f --- /dev/null +++ b/lib/spack/spack/test/concretize_preferences.py @@ -0,0 +1,106 @@ +############################################################################## +# 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 +############################################################################## +import spack +import spack.architecture +from spack.test.mock_packages_test import * +from tempfile import mkdtemp + + +class ConcretizePreferencesTest(MockPackagesTest): + """Test concretization preferences are being applied correctly. + """ + + def setUp(self): + """Create config section to store concretization preferences + """ + super(ConcretizePreferencesTest, self).setUp() + self.tmp_dir = mkdtemp('.tmp', 'spack-config-test-') + spack.config.ConfigScope('concretize', + os.path.join(self.tmp_dir, 'concretize')) + + def tearDown(self): + super(ConcretizePreferencesTest, self).tearDown() + shutil.rmtree(self.tmp_dir, True) + spack.pkgsort = spack.PreferredPackages() + + def concretize(self, abstract_spec): + return Spec(abstract_spec).concretized() + + def update_packages(self, pkgname, section, value): + """Update config and reread package list""" + conf = {pkgname: {section: value}} + spack.config.update_config('packages', conf, 'concretize') + spack.pkgsort = spack.PreferredPackages() + + def assert_variant_values(self, spec, **variants): + concrete = self.concretize(spec) + for variant, value in variants.items(): + self.assertEqual(concrete.variants[variant].value, value) + + def test_preferred_variants(self): + """Test preferred variants are applied correctly + """ + self.update_packages('mpileaks', 'variants', + '~debug~opt+shared+static') + self.assert_variant_values('mpileaks', debug=False, opt=False, + shared=True, static=True) + + self.update_packages('mpileaks', 'variants', + ['+debug', '+opt', '~shared', '-static']) + self.assert_variant_values('mpileaks', debug=True, opt=True, + shared=False, static=False) + + def test_preferred_compilers(self): + """Test preferred compilers are applied correctly + """ + self.update_packages('mpileaks', 'compiler', ['clang@3.3']) + spec = self.concretize('mpileaks') + self.assertEqual(spec.compiler, spack.spec.CompilerSpec('clang@3.3')) + + self.update_packages('mpileaks', 'compiler', ['gcc@4.5.0']) + spec = self.concretize('mpileaks') + self.assertEqual(spec.compiler, spack.spec.CompilerSpec('gcc@4.5.0')) + + def test_preferred_versions(self): + """Test preferred package versions are applied correctly + """ + self.update_packages('mpileaks', 'version', ['2.3']) + spec = self.concretize('mpileaks') + self.assertEqual(spec.version, spack.spec.Version('2.3')) + + self.update_packages('mpileaks', 'version', ['2.2']) + spec = self.concretize('mpileaks') + self.assertEqual(spec.version, spack.spec.Version('2.2')) + + def test_preferred_providers(self): + """Test preferred providers of virtual packages are applied correctly + """ + self.update_packages('all', 'providers', {'mpi': ['mpich']}) + spec = self.concretize('mpileaks') + self.assertTrue('mpich' in spec) + + self.update_packages('all', 'providers', {'mpi': ['zmpi']}) + spec = self.concretize('mpileaks') + self.assertTrue('zmpi', spec) diff --git a/lib/spack/spack/test/modules.py b/lib/spack/spack/test/modules.py index 135cd028e3..5e280d8e43 100644 --- a/lib/spack/spack/test/modules.py +++ b/lib/spack/spack/test/modules.py @@ -89,7 +89,10 @@ configuration_alter_environment = { 'enable': ['tcl'], 'tcl': { 'all': { - 'filter': {'environment_blacklist': ['CMAKE_PREFIX_PATH']} + 'filter': {'environment_blacklist': ['CMAKE_PREFIX_PATH']}, + 'environment': { + 'set': {'{name}_ROOT': '{prefix}'} + } }, 'platform=test target=x86_64': { 'environment': { @@ -248,6 +251,8 @@ class TclTests(MockPackagesTest): self.assertEqual( len([x for x in content if 'setenv FOO "foo"' in x]), 1) self.assertEqual(len([x for x in content if 'unsetenv BAR' in x]), 1) + self.assertEqual( + len([x for x in content if 'setenv MPILEAKS_ROOT' in x]), 1) spec = spack.spec.Spec('libdwarf %clang platform=test target=x86_32') content = self.get_modulefile_content(spec) @@ -262,6 +267,8 @@ class TclTests(MockPackagesTest): len([x for x in content if 'is-loaded foo/bar' in x]), 1) self.assertEqual( len([x for x in content if 'module load foo/bar' in x]), 1) + self.assertEqual( + len([x for x in content if 'setenv LIBDWARF_ROOT' in x]), 1) def test_blacklist(self): spack.modules.CONFIGURATION = configuration_blacklist |