Move default implementation of pkg.command
to PackageBase (#49580)
This commit is contained in:
parent
5a04e84097
commit
5016084213
@ -48,6 +48,7 @@
|
|||||||
import spack.store
|
import spack.store
|
||||||
import spack.url
|
import spack.url
|
||||||
import spack.util.environment
|
import spack.util.environment
|
||||||
|
import spack.util.executable
|
||||||
import spack.util.path
|
import spack.util.path
|
||||||
import spack.util.web
|
import spack.util.web
|
||||||
import spack.variant
|
import spack.variant
|
||||||
@ -1369,6 +1370,14 @@ def prefix(self):
|
|||||||
def home(self):
|
def home(self):
|
||||||
return self.prefix
|
return self.prefix
|
||||||
|
|
||||||
|
@property
|
||||||
|
def command(self) -> spack.util.executable.Executable:
|
||||||
|
"""Returns the main executable for this package."""
|
||||||
|
path = os.path.join(self.home.bin, self.spec.name)
|
||||||
|
if fsys.is_exe(path):
|
||||||
|
return spack.util.executable.Executable(path)
|
||||||
|
raise RuntimeError(f"Unable to locate {self.spec.name} command in {self.home.bin}")
|
||||||
|
|
||||||
@property # type: ignore[misc]
|
@property # type: ignore[misc]
|
||||||
@memoized
|
@memoized
|
||||||
def compiler(self):
|
def compiler(self):
|
||||||
|
@ -97,7 +97,6 @@
|
|||||||
import spack.spec_parser
|
import spack.spec_parser
|
||||||
import spack.store
|
import spack.store
|
||||||
import spack.traverse
|
import spack.traverse
|
||||||
import spack.util.executable
|
|
||||||
import spack.util.hash
|
import spack.util.hash
|
||||||
import spack.util.prefix
|
import spack.util.prefix
|
||||||
import spack.util.spack_json as sjson
|
import spack.util.spack_json as sjson
|
||||||
@ -1110,28 +1109,6 @@ def clear(self):
|
|||||||
self.edges.clear()
|
self.edges.clear()
|
||||||
|
|
||||||
|
|
||||||
def _command_default_handler(spec: "Spec"):
|
|
||||||
"""Default handler when looking for the 'command' attribute.
|
|
||||||
|
|
||||||
Tries to search for ``spec.name`` in the ``spec.home.bin`` directory.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
spec: spec that is being queried
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Executable: An executable of the command
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: If the command is not found
|
|
||||||
"""
|
|
||||||
home = getattr(spec.package, "home")
|
|
||||||
path = os.path.join(home.bin, spec.name)
|
|
||||||
|
|
||||||
if fs.is_exe(path):
|
|
||||||
return spack.util.executable.Executable(path)
|
|
||||||
raise RuntimeError(f"Unable to locate {spec.name} command in {home.bin}")
|
|
||||||
|
|
||||||
|
|
||||||
def _headers_default_handler(spec: "Spec"):
|
def _headers_default_handler(spec: "Spec"):
|
||||||
"""Default handler when looking for the 'headers' attribute.
|
"""Default handler when looking for the 'headers' attribute.
|
||||||
|
|
||||||
@ -1335,9 +1312,7 @@ class SpecBuildInterface(lang.ObjectWrapper):
|
|||||||
home = ForwardQueryToPackage("home", default_handler=None)
|
home = ForwardQueryToPackage("home", default_handler=None)
|
||||||
headers = ForwardQueryToPackage("headers", default_handler=_headers_default_handler)
|
headers = ForwardQueryToPackage("headers", default_handler=_headers_default_handler)
|
||||||
libs = ForwardQueryToPackage("libs", default_handler=_libs_default_handler)
|
libs = ForwardQueryToPackage("libs", default_handler=_libs_default_handler)
|
||||||
command = ForwardQueryToPackage(
|
command = ForwardQueryToPackage("command", default_handler=None, _indirect=True)
|
||||||
"command", default_handler=_command_default_handler, _indirect=True
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
Loading…
Reference in New Issue
Block a user