-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: master
Are you sure you want to change the base?
Allow starting REPL #114
Conversation
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
This makes it possible to start the REPL with pybricksdev.
It isn't very useful though since
stdin
isn't forwarded to the hub yet.