Add completion

This commit is contained in:
psakiev
2024-11-12 15:28:34 -07:00
parent 973f59abbc
commit 4d49a658c8
7 changed files with 123 additions and 54 deletions

View File

@@ -14,7 +14,7 @@
setup_parser = env_utility.setup_parser
#TODO create a dropin/dive funciton that dev_build and build_env cmd's can use
# TODO create a dropin/dive funciton that dev_build and build_env cmd's can use
# create a default shell utility for picking the current shell to start with
def build_env(parser, args):
env_utility.emulate_env_utility("build-env", Context.BUILD, args)

View File

@@ -29,7 +29,10 @@ def setup_parser(subparser):
"--pickle", metavar="FILE", help="dump a pickled source-able environment to FILE"
)
subparser.add_argument(
"--dive", action="store_true", help="dive into the build-env in a subshell"
"-d", "--dive", action="store_true", help="dive into the build-env in a subshell"
)
subparser.add_argument(
"--status", action="store_true", help="check shell for an active build environment"
)
subparser.add_argument(
"spec",
@@ -80,7 +83,25 @@ def neighbors(self, item):
return item.edge.spec.edges_to_dependencies(depflag=depflag)
def run_command_in_subshell(
spec, context, cmd, prompt=False, dirty=False, shell=active_shell_type()
):
mods = build_environment.setup_package(spec.package, dirty, context)
if prompt:
mods.extend(spack.prompt.prompt_modifications(f"{spec.name}-{str(context)}-env", shell))
mods.apply_modifications()
os.execvp(cmd[0], cmd)
def emulate_env_utility(cmd_name, context: Context, args):
if args.status:
context_var = os.environ.get(f"SPACK_{str(context).upper()}_ENV", None)
if context_var:
tty.msg(f"In {str(context)} env {context_var}")
else:
tty.msg(f"{str(context)} environment not detected")
exit(0)
if not args.spec:
tty.die("spack %s requires a spec." % cmd_name)
@@ -97,6 +118,12 @@ def emulate_env_utility(cmd_name, context: Context, args):
spec = args.spec[0]
cmd = args.spec[1:]
if args.dive:
if cmd:
tty.die("--dive and additional commands can't be run together")
else:
cmd = [active_shell_type()]
if not spec:
tty.die("spack %s requires a spec." % cmd_name)
@@ -111,6 +138,7 @@ def emulate_env_utility(cmd_name, context: Context, args):
visitor = AreDepsInstalledVisitor(context=context)
# Mass install check needs read transaction.
# FIXME: this command is slow
with spack.store.STORE.db.read_transaction():
traverse.traverse_breadth_first_with_visitor([spec], traverse.CoverNodesVisitor(visitor))
@@ -141,14 +169,7 @@ def emulate_env_utility(cmd_name, context: Context, args):
pickle_environment(args.pickle)
if cmd:
# Execute the command with the new environment
os.execvp(cmd[0], cmd)
if args.dive:
shell = active_shell_type()
mods.extend(spack.prompt.prompt_modifications(f"{spec.name}-{str(context)}-env", shell))
mods.apply_modifications()
os.execvp(shell, [shell])
run_command_in_subshell(spec, context, cmd, prompt=args.dive, location=args.cd)
elif not bool(args.pickle or args.dump):
# If no command or dump/pickle option then act like the "env" command

View File

@@ -16,6 +16,7 @@
import spack.prompt
import spack.repo
from spack.cmd.common import arguments
from spack.cmd.common.env_utility import run_command_in_subshell
from spack.installer import PackageInstaller
description = "developer build: build from user managed code"
@@ -169,8 +170,6 @@ def dev_build(self, args):
# drop into the build environment of the package?
if args.shell is not None:
mods = spack.build_environment.setup_package(spec.package, dirty=False)
if args.prompt:
mods.extend(spack.prompt.prompt_modifications(f"{spec.name}-build-env", args.shell))
mods.apply_modifications()
os.execvp(args.shell, [args.shell])
run_command_in_subshell(
spec, context.BUILD, [args.shell], prompt=args.prompt, shell=args.shell
)

View File

@@ -16,7 +16,9 @@ def active_shell_type(env=os.environ):
return "ps1"
else:
try:
output = subprocess.run("powershell -Command \"echo $PSVersionTable\"", shell=True, check=True, text=True)
output = subprocess.run(
'powershell -Command "echo $PSVersionTable"', shell=True, check=True, text=True
)
if "PSVersion" in output:
return "ps1"
else: