Skip to content

Commit bb26a21

Browse files
committed
cli: add glasgow python command.
Our recommended installation method uses pipx. Pipx will create and stash a virtual environment somewhere, but there's no easy way to find out where. This hasn't been a major problem until we also started to offer examples intended to be run as standalone Python scripts. This commit addresses the problem: e.g. running: glasgow python examples/burning_tool/main.py will start that application without you having to fish for the virtual environment yourself.
1 parent cbc4bcb commit bb26a21

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎software/glasgow/cli.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import platform
1111
import unittest
1212
import logging as pylogging
13+
import subprocess
1314
from datetime import datetime
1415

1516
from amaranth import UnusedElaboratable
@@ -483,6 +484,13 @@ def factory_manufacturer(arg):
483484
"list", formatter_class=TextHelpFormatter,
484485
help="list devices connected to the system")
485486

487+
p_python = subparsers.add_parser(
488+
"python", formatter_class=TextHelpFormatter,
489+
help="run Python with Glasgow packages in the environment")
490+
p_python.add_argument(
491+
"rest", metavar="ARGS", nargs=argparse.REMAINDER,
492+
help="arguments for the Python executable")
493+
486494
return parser
487495

488496

@@ -589,6 +597,11 @@ async def main() -> int:
589597
args = get_argparser().parse_args()
590598
file_handler = configure_logger(args, term_handler)
591599

600+
if args.action == "python":
601+
if len(args.rest) > 0 and args.rest[0] == "--":
602+
del args.rest[0]
603+
return subprocess.call([sys.executable, *args.rest])
604+
592605
logger.debug(version_info()) # print version info if verbose
593606

594607
if args.action not in ("build", "test", "tool", "factory", "list"):

0 commit comments

Comments
 (0)