Skip to content

Allow starting REPL #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Allow starting REPL #114

wants to merge 3 commits into from

Conversation

laurensvalk
Copy link
Member

This makes it possible to start the REPL with pybricksdev.

 pybricksdev run usb repl

It isn't very useful though since stdin isn't forwarded to the hub yet.

Instead of converting a path to an open file, getting the file name, closing it again, and then opening it again, just use the given name. Sometimes simplicity is better.

And it will let us use run repl in a future commit.
This allows starting slots and other builtins like the REPL.
with _get_script_path(args.file) as script_path:
mpy = await compile_multi_file(script_path, args.abi)
if args.file == "-":
with NamedTemporaryFile(suffix=".py", delete=False) as temp:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be best to eventually delete the temporary file. A contextlib.ExitStack would be the simplest way to do this.

else:
# If using stdin, save to temporary file first.
if args.file == "-":
with NamedTemporaryFile(suffix=".py", delete=False) as temp:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -134,8 +98,8 @@ def add_parser(self, subparsers: argparse._SubParsersAction):
parser.add_argument(
"file",
metavar="<file>",
help="path to a MicroPython script or `-` for stdin",
type=argparse.FileType(),
help="path to a MicroPython script, `-` for stdin, or `repl` for interactive prompt",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well allow this to take a number to run programs in an existing slot as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants