From fc9896ed45afe1b5ec228ed3ceb2b27ea2a1854c Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Tue, 25 Apr 2017 21:54:53 +0200 Subject: hooks take spec as an argument (instead of pkg) (#3967) --- lib/spack/spack/hooks/__init__.py | 9 +++++---- lib/spack/spack/hooks/extensions.py | 5 +++-- lib/spack/spack/hooks/licensing.py | 9 ++++++--- lib/spack/spack/hooks/module_file_generation.py | 8 ++++---- lib/spack/spack/hooks/sbang.py | 6 +++--- lib/spack/spack/package.py | 13 ++++++------- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/lib/spack/spack/hooks/__init__.py b/lib/spack/spack/hooks/__init__.py index 6454a865b6..9ed04a4768 100644 --- a/lib/spack/spack/hooks/__init__.py +++ b/lib/spack/spack/hooks/__init__.py @@ -31,10 +31,11 @@ Currently the following hooks are supported: - * pre_install() - * post_install() - * pre_uninstall() - * post_uninstall() + * pre_run() + * pre_install(spec) + * post_install(spec) + * pre_uninstall(spec) + * post_uninstall(spec) This can be used to implement support for things like module systems (e.g. modules, dotkit, etc.) or to add other custom diff --git a/lib/spack/spack/hooks/extensions.py b/lib/spack/spack/hooks/extensions.py index 070b309a43..7d2a39e24f 100644 --- a/lib/spack/spack/hooks/extensions.py +++ b/lib/spack/spack/hooks/extensions.py @@ -24,8 +24,9 @@ ############################################################################## -def pre_uninstall(pkg): - assert(pkg.spec.concrete) +def pre_uninstall(spec): + pkg = spec.package + assert spec.concrete if pkg.is_extension: if pkg.activated: diff --git a/lib/spack/spack/hooks/licensing.py b/lib/spack/spack/hooks/licensing.py index 9a244dbdef..85f7a96c31 100644 --- a/lib/spack/spack/hooks/licensing.py +++ b/lib/spack/spack/hooks/licensing.py @@ -29,8 +29,9 @@ import llnl.util.tty as tty from llnl.util.filesystem import join_path, mkdirp -def pre_install(pkg): +def pre_install(spec): """This hook handles global license setup for licensed software.""" + pkg = spec.package if pkg.license_required and not pkg.spec.external: set_up_license(pkg) @@ -142,9 +143,11 @@ def write_license_file(pkg, license_path): license.close() -def post_install(pkg): +def post_install(spec): """This hook symlinks local licenses to the global license for - licensed software.""" + licensed software. + """ + pkg = spec.package if pkg.license_required and not pkg.spec.external: symlink_license(pkg) diff --git a/lib/spack/spack/hooks/module_file_generation.py b/lib/spack/spack/hooks/module_file_generation.py index ff9617ff1c..b02c2e871d 100644 --- a/lib/spack/spack/hooks/module_file_generation.py +++ b/lib/spack/spack/hooks/module_file_generation.py @@ -26,13 +26,13 @@ import spack.modules from six import iteritems -def post_install(pkg): +def post_install(spec): for item, cls in iteritems(spack.modules.module_types): - generator = cls(pkg.spec) + generator = cls(spec) generator.write() -def post_uninstall(pkg): +def post_uninstall(spec): for item, cls in iteritems(spack.modules.module_types): - generator = cls(pkg.spec) + generator = cls(spec) generator.remove() diff --git a/lib/spack/spack/hooks/sbang.py b/lib/spack/spack/hooks/sbang.py index fb824470e2..17f6ac2528 100644 --- a/lib/spack/spack/hooks/sbang.py +++ b/lib/spack/spack/hooks/sbang.py @@ -102,14 +102,14 @@ def filter_shebangs_in_directory(directory, filenames=None): filter_shebang(path) -def post_install(pkg): +def post_install(spec): """This hook edits scripts so that they call /bin/bash $spack_prefix/bin/sbang instead of something longer than the shebang limit. """ - if pkg.spec.external: + if spec.external: tty.debug('SKIP: shebang filtering [external package]') return - for directory, _, filenames in os.walk(pkg.prefix): + for directory, _, filenames in os.walk(spec.prefix): filter_shebangs_in_directory(directory, filenames) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 4a42fef337..506e44ec45 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1112,7 +1112,7 @@ class PackageBase(with_metaclass(PackageMeta, object)): # post-install hooks to generate module files message = '{s.name}@{s.version} : generating module file' tty.msg(message.format(s=self)) - spack.hooks.post_install(self) + spack.hooks.post_install(self.spec) # Add to the DB message = '{s.name}@{s.version} : registering into DB' tty.msg(message.format(s=self)) @@ -1248,7 +1248,7 @@ class PackageBase(with_metaclass(PackageMeta, object)): with self._stage_and_write_lock(): # Run the pre-install hook in the child process after # the directory is created. - spack.hooks.pre_install(self) + spack.hooks.pre_install(self.spec) if fake: self.do_fake_install() else: @@ -1288,7 +1288,7 @@ class PackageBase(with_metaclass(PackageMeta, object)): self.spec, self.prefix) self.log() # Run post install hooks before build stage is removed. - spack.hooks.post_install(self) + spack.hooks.post_install(self.spec) # Stop timer. self._total_time = time.time() - start_time @@ -1526,9 +1526,9 @@ class PackageBase(with_metaclass(PackageMeta, object)): # Pre-uninstall hook runs first. with spack.store.db.prefix_write_lock(spec): - # TODO: hooks should take specs, not packages. + if pkg is not None: - spack.hooks.pre_uninstall(pkg) + spack.hooks.pre_uninstall(spec) # Uninstalling in Spack only requires removing the prefix. if not spec.external: @@ -1541,9 +1541,8 @@ class PackageBase(with_metaclass(PackageMeta, object)): spack.store.db.remove(spec) tty.msg("Successfully uninstalled %s" % spec.short_spec) - # TODO: refactor hooks to use specs, not packages. if pkg is not None: - spack.hooks.post_uninstall(pkg) + spack.hooks.post_uninstall(spec) tty.msg("Successfully uninstalled %s" % spec.short_spec) -- cgit v1.2.3-70-g09d2