summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@googlemail.com>2017-08-12 04:18:52 +0200
committerscheibelp <scheibel1@llnl.gov>2017-08-11 19:18:52 -0700
commit41c87a71a8c5a5f09b486f6a79fdd52d4602a158 (patch)
tree2e18c7e50b64c69a92cd93d59c6d7fdecca85caf /lib
parent64a32ea1f97da21a146f14f084bcc7d72de37c18 (diff)
downloadspack-41c87a71a8c5a5f09b486f6a79fdd52d4602a158.tar.gz
spack-41c87a71a8c5a5f09b486f6a79fdd52d4602a158.tar.bz2
spack-41c87a71a8c5a5f09b486f6a79fdd52d4602a158.tar.xz
spack-41c87a71a8c5a5f09b486f6a79fdd52d4602a158.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/patch.py18
1 files 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)