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.
This commit is contained in:
parent
64a32ea1f9
commit
41c87a71a8
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user