From 113afe860ecea247c5ed343b814a633565c2033b Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 10 Jul 2014 15:52:24 -0700 Subject: More robust symbol inclusion for 'from spack import *' - avoid errors where some symbols aren't exported to packages. - reduce the number of places each symbol needs to be mentioned in an __all__ list --- lib/spack/spack/__init__.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py index 9eae4342e3..a3f00a11b1 100644 --- a/lib/spack/spack/__init__.py +++ b/lib/spack/spack/__init__.py @@ -22,20 +22,6 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## - -# -# When packages call 'from spack import *', this is what is brought in. -# -# Spack internal code calls 'import spack' and accesses other -# variables (spack.db, paths, etc.) directly. -# -# TODO: maybe this should be separated out and should go in build_environment.py? -# TODO: it's not clear where all the stuff that needs to be included in packages -# should live. This file is overloaded for spack core vs. for packages. -__all__ = ['Package', 'when', 'provides', 'depends_on', 'version', - 'patch', 'Version', 'working_dir', 'which', 'Executable', - 'filter_file', 'change_sed_delimiter'] - import os import tempfile from llnl.util.filesystem import * @@ -141,11 +127,30 @@ do_checksum = True # sys_type = None + +# +# When packages call 'from spack import *', this extra stuff is brought in. +# +# Spack internal code should call 'import spack' and accesses other +# variables (spack.db, paths, etc.) directly. # -# Extra imports that should be generally usable from package.py files. +# TODO: maybe this should be separated out and should go in build_environment.py? +# TODO: it's not clear where all the stuff that needs to be included in packages +# should live. This file is overloaded for spack core vs. for packages. # -from llnl.util.filesystem import working_dir +__all__ = ['Package', 'Version', 'when'] from spack.package import Package -from spack.relations import * -from spack.multimethod import when from spack.version import Version +from spack.multimethod import when + +import llnl.util.filesystem +from llnl.util.filesystem import * +__all__ += llnl.util.filesystem.__all__ + +import spack.relations +from spack.relations import * +__all__ += spack.relations.__all__ + +import spack.util.executable +from spack.util.executable import * +__all__ += spack.util.executable.__all__ -- cgit v1.2.3-70-g09d2 From 0bba101ff90f317c81385306c8beaaacbaa62759 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 10 Jul 2014 15:53:31 -0700 Subject: Allow packages to add a dotkit() method and write custom parts of dotkits. --- lib/spack/spack/hooks/dotkit.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/hooks/dotkit.py b/lib/spack/spack/hooks/dotkit.py index 10b7732353..524145e6c1 100644 --- a/lib/spack/spack/hooks/dotkit.py +++ b/lib/spack/spack/hooks/dotkit.py @@ -33,6 +33,23 @@ from llnl.util.filesystem import join_path, mkdirp import spack +class DotkitFile(object): + def __init__(self, path): + self.dk_file = open(path, 'w') + + def close(self): + self.dk_file.close() + + def write(self, *args): + self.dk_file.write(*args) + + def alter(self, var, path): + self.dk_file.write("dk_alter %s %s\n" % (var, path)) + + def setenv(self, var, value): + self.dk_file.write("dk_setenv %s %s\n" % (var, value)) + + def dotkit_file(pkg): dk_file_name = pkg.spec.format('$_$@$%@$+$=$#') + ".dk" return join_path(spack.dotkit_path, dk_file_name) @@ -51,15 +68,15 @@ def post_install(pkg): ('LD_LIBRARY_PATH', pkg.prefix.lib64)]: if os.path.isdir(path): - alterations.append("dk_alter %s %s\n" % (var, path)) + alterations.append((var, path)) if not alterations: return - alterations.append("dk_alter CMAKE_PREFIX_PATH %s\n" % pkg.prefix) + alterations.append(("CMAKE_PREFIX_PATH", pkg.prefix)) dk_file = dotkit_file(pkg) - with closing(open(dk_file, 'w')) as dk: + with closing(DotkitFile(dk_file)) as dk: # Put everything in the spack category. dk.write('#c spack\n') @@ -72,8 +89,13 @@ def post_install(pkg): dk.write("#h %s\n" % line) # Write alterations - for alter in alterations: - dk.write(alter) + for alt in alterations: + dk.alter(*alt) + + # callback in case package has extensions. + dotkit_fun = getattr(pkg, 'dotkit', None) + if dotkit_fun and hasattr(dotkit_fun, '__call__'): + dotkit_fun(dk) def post_uninstall(pkg): -- cgit v1.2.3-70-g09d2 From 5a3803de39a67a42a70b4048039c77c4831633b2 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 25 Jul 2014 19:38:48 -0700 Subject: Add options to stage to make it just print out stage dir. --- lib/spack/spack/cmd/stage.py | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/stage.py b/lib/spack/spack/cmd/stage.py index 1bf1f93c2f..7b21faa721 100644 --- a/lib/spack/spack/cmd/stage.py +++ b/lib/spack/spack/cmd/stage.py @@ -23,6 +23,9 @@ # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import argparse +import os + +import llnl.util.tty as tty import spack import spack.cmd @@ -33,18 +36,45 @@ def setup_parser(subparser): subparser.add_argument( '-n', '--no-checksum', action='store_true', dest='no_checksum', help="Do not check downloaded packages against checksum") + + dir_parser = subparser.add_mutually_exclusive_group() + dir_parser.add_argument( + '-d', '--stage-dir', action='store_const', dest='print_dir', + const='stage', help="Prints out the stage directory for a spec.") + dir_parser.add_argument( + '-b', '--build-dir', action='store_const', dest='print_dir', + const='build', help="Prints out the expanded archive path for a spec.") + subparser.add_argument( - 'packages', nargs=argparse.REMAINDER, help="specs of packages to stage") + 'specs', nargs=argparse.REMAINDER, help="specs of packages to stage") def stage(parser, args): - if not args.packages: + if not args.specs: tty.die("stage requires at least one package argument") if args.no_checksum: spack.do_checksum = False - specs = spack.cmd.parse_specs(args.packages, concretize=True) - for spec in specs: - package = spack.db.get(spec) - package.do_stage() + specs = spack.cmd.parse_specs(args.specs, concretize=True) + + if args.print_dir: + if len(specs) != 1: + tty.die("--stage-dir and --build-dir options only take one spec.") + + spec = specs[0] + pkg = spack.db.get(spec) + + if args.print_dir == 'stage': + print pkg.stage.path + elif args.print_dir == 'build': + if not os.listdir(pkg.stage.path): + tty.die("Stage directory is empty. Run this first:", + "spack stage " + " ".join(args.specs)) + print pkg.stage.expanded_archive_path + + else: + for spec in specs: + package = spack.db.get(spec) + package.do_stage() + -- cgit v1.2.3-70-g09d2