Skip to content

Commit 94bf44a

Browse files
committed
Add help entry for 'exec'
1 parent ede6b4d commit 94bf44a

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

_msbuild.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ def get_commands():
215215
# Check if a subclass of BaseCommand
216216
if not any(b.id in command_bases for b in cls.bases):
217217
continue
218+
# Ignore exec command - it gets handled separately.
219+
if cls.name == "ExecCommand":
220+
continue
218221
command_bases.add(cls.name)
219222
for a in filter(lambda s: isinstance(s, ast.Assign), cls.body):
220223
if not any(t.id == "CMD" for t in a.targets):

src/manage/commands.py

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
"with the digit 3, platform overrides are permitted, and regular Python " +
5656
"options may follow. " +
5757
"!G!py -3!W! is the equivalent of the !G!python3!W! command."),
58+
(f"{EXE_NAME} exec !B!<any of the above>!W!\n",
59+
"Equivalent to any of the above launch options, and the requested runtime " +
60+
"will be installed if needed."),
5861
]
5962

6063

@@ -519,14 +522,19 @@ def show_usage(cls):
519522
else:
520523
usage_docs = PYMANAGER_USAGE_DOCS
521524

522-
usage_docs = usage_docs + [
523-
(
524-
f"{EXE_NAME} " + getattr(COMMANDS[cmd], "USAGE_LINE", cmd),
525-
getattr(COMMANDS[cmd], "HELP_LINE", "")
526-
)
527-
for cmd in sorted(COMMANDS)
528-
if cmd[:1].isalpha()
529-
]
525+
usage_docs = list(usage_docs)
526+
for cmd in sorted(COMMANDS):
527+
if not cmd[:1].isalpha():
528+
continue
529+
try:
530+
usage_docs.append(
531+
(
532+
f"{EXE_NAME} " + getattr(COMMANDS[cmd], "USAGE_LINE", cmd),
533+
COMMANDS[cmd].HELP_LINE
534+
)
535+
)
536+
except AttributeError:
537+
pass
530538

531539
usage_docs = [(f" {x.lstrip()}", y) for x, y in usage_docs]
532540

@@ -637,10 +645,12 @@ def get_install_to_run(self, tag=None, script=None, *, windowed=False):
637645

638646
class ListCommand(BaseCommand):
639647
CMD = "list"
640-
HELP_LINE = ("Shows installed Python runtimes, optionally filtering by " +
648+
HELP_LINE = ("Show installed Python runtimes, optionally filtering by " +
641649
"!B!<FILTER>!W!.")
642650
USAGE_LINE = "list !B![<FILTER>]!W!"
643651
HELP_TEXT = r"""!G!List command!W!
652+
Shows installed Python runtimes, optionally filtered or formatted.
653+
644654
> py list !B![options] [<FILTER> ...]!W!
645655
646656
!G!Options:!W!
@@ -718,6 +728,8 @@ class InstallCommand(BaseCommand):
718728
"update existing installs.")
719729
USAGE_LINE = "install !B!<TAG>!W!"
720730
HELP_TEXT = r"""!G!Install command!W!
731+
Downloads new Python runtimes and sets up shortcuts and other registration.
732+
721733
> py install !B![options] <TAG> [<TAG>] ...!W!
722734
723735
!G!Options:!W!
@@ -797,12 +809,16 @@ class UninstallCommand(BaseCommand):
797809
"!B!--purge!W! to clean up all runtimes and cached files.")
798810
USAGE_LINE = "uninstall !B!<TAG>!W!"
799811
HELP_TEXT = r"""!G!Uninstall command!W!
812+
Removes one or more runtimes from your machine.
813+
800814
> py uninstall !B![options] <TAG> [<TAG>] ...!W!
801815
802816
!G!Options:!W!
803-
--purge Remove all runtimes, shortcuts, and cached files. Ignores tags.
804-
--by-id Require TAG to exactly match the install ID. (For advanced use.)
805-
!B!<TAG> <TAG>!W! ... One or more runtimes to uninstall (Company\Tag format)
817+
--purge Remove all runtimes, shortcuts, and cached files. Ignores tags.
818+
--by-id Require TAG to exactly match the install ID. (For advanced use.)
819+
!B!<TAG> <TAG>!W! ... One or more runtimes to uninstall (Company\Tag format)
820+
Each tag will only remove a single runtime, even if it matches
821+
more than one.
806822
807823
!B!EXAMPLE:!W! Uninstall Python 3.12 32-bit
808824
> py uninstall 3.12-32
@@ -838,6 +854,8 @@ class HelpCommand(BaseCommand):
838854
HELP_LINE = "Show help for Python installation manager commands"
839855
USAGE_LINE = "help !B![<CMD>]!W!"
840856
HELP_TEXT = r"""!G!Help command!W!
857+
Shows help for specific commands.
858+
841859
> py help !B![<CMD>] ...!W!
842860
843861
!G!Options:!W!
@@ -882,6 +900,36 @@ def execute(self):
882900
LOGGER.print(f"The command !R!{' '.join(args)}!W! was not recognized.")
883901

884902

903+
# This command exists solely to provide help.
904+
# When it is specified, it gets handled in main.cpp
905+
class ExecCommand(BaseCommand):
906+
CMD = "exec"
907+
HELP_TEXT = f"""!G!Execute command!W!
908+
Launches the specified (or default) runtime. This command is optional when
909+
launching through !G!py!W!, as the default behaviour is to launch a runtime.
910+
When used explicitly, this command will automatically install the requested
911+
runtime if it is not available.
912+
913+
> {EXE_NAME} exec -V:!B!<TAG>!W! ...
914+
> {EXE_NAME} exec -3!B!<VERSION>!W! ...
915+
> {EXE_NAME} exec ...
916+
> py [ -V:!B!<TAG>!W! | -3!B!<VERSION>!W! ] ...
917+
918+
!G!Options:!W!
919+
-V:!B!<TAG>!W! Launch runtime identified by !B!<TAG>!W!, which should include
920+
the company name if not !B!PythonCore!W!. Regular Python options
921+
may follow this option. The runtime will be installed if needed.
922+
-3!B!<VERSION>!W! Equivalent to -V:PythonCore\3!B!<VERSION>!W!. The version must
923+
begin with a '3', platform overrides are permitted, and regular
924+
Python options may follow. The runtime will be installed if needed.
925+
"""
926+
927+
def __init__(self, args, root=None):
928+
# Essentially disable argument processing for this command
929+
super().__init__(args[:1], root)
930+
self.args = args[1:]
931+
932+
885933
class DefaultConfig(BaseCommand):
886934
CMD = "__no_command"
887935
_create_log_file = False

0 commit comments

Comments
 (0)