From 41c87a71a8c5a5f09b486f6a79fdd52d4602a158 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Sat, 12 Aug 2017 04:18:52 +0200 Subject: patch: get correct package directory for a given package fixes #4236 fixes #5002 When a package is defined in more than one repository, RepoPath.dirname_for_package_name may return the path to either definition. This sidesteps that ambiguity by accessing the module associated with the package definition. --- lib/spack/spack/patch.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/patch.py b/lib/spack/spack/patch.py index 78bb15f41c..c970f4dfdc 100644 --- a/lib/spack/spack/patch.py +++ b/lib/spack/spack/patch.py @@ -23,16 +23,28 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import os +import os.path +import inspect import spack import spack.error -import spack.stage import spack.fetch_strategy as fs - +import spack.stage from llnl.util.filesystem import join_path from spack.util.executable import which +def absolute_path_for_package(pkg): + """Returns the absolute path to the ``package.py`` file implementing + the recipe for the package passed as argument. + + Args: + pkg: a valid package object + """ + m = inspect.getmodule(pkg) + return os.path.abspath(m.__file__) + + class Patch(object): """Base class to describe a patch that needs to be applied to some expanded source code. @@ -90,7 +102,7 @@ class FilePatch(Patch): def __init__(self, pkg, path_or_url, level): super(FilePatch, self).__init__(pkg, path_or_url, level) - pkg_dir = spack.repo.dirname_for_package_name(pkg.name) + pkg_dir = os.path.dirname(absolute_path_for_package(pkg)) self.path = join_path(pkg_dir, path_or_url) if not os.path.isfile(self.path): raise NoSuchPatchFileError(pkg.name, self.path) -- cgit v1.2.3-60-g2f50