Page 1 of 1

Raw mode and help missing from the Unix port?

Posted: Thu Oct 10, 2019 7:58 pm
by aivarannamaa
I installed Unix port from Snapcraft (https://snapcraft.io/micropython). It looks like it is built by just invoking `make` in official source tarball (https://github.com/hjiawei/micropython- ... t.yaml#L23)

Its REPL does not advertise raw mode and Ctrl+A / Ctrl+B seem to be equal to an empty command.

Is this expected behavior in Unix port? If yes, then why?

I also tried `help('modules')`, but help was not defined. How can I list available modules in Unix port?

Re: Raw mode and help missing from the Unix port?

Posted: Sun Oct 13, 2019 11:14 pm
by jimmo
The unix port is a bit of an odd combination of enabled and disabled features.

There's a bit of history here -- https://github.com/micropython/micropython/pull/4309

For the raw REPL specifically, I think this is possibly just an oversight and unix/main.c could be updated to use pyexec_friendly_repl from pyexec.c rather than its own custom REPL loop.

I have no idea why help is disabled... this is configured with MICROPY_PY_BUILTINS_HELP (and MICROPY_PY_BUILTINS_HELP_MODULES for the specific use case you want) in mpconfigport.h. It seems obvious to me that they should be enabled on Unix, but I don't know why they aren't.

There are a few other weird things in the unix port -- unlike most other ports, it doesn't "weak link" the standard modules to their "micro" equivalent. e.g. on the unix port you must "import ustruct", whereas on other ports you can write "import struct" and it forwards automatically to ustruct.

All this is on my ever-expanding list of things to work on... :)

Re: Raw mode and help missing from the Unix port?

Posted: Mon Oct 14, 2019 4:25 am
by aivarannamaa
Thank you for comprehensive answer!

Should I create GitHub issues for help and raw REPL?

For the background -- I'm interested in these topics because of MicroPython for EV3. They seem to be using Unix variant of MicroPython in a Linux and I'm considering adding support for it in my IDE. Current MicroPython support in my IDE depends both on raw REPL (for invoking management commands) and on help("modules") for filtering code completion proposals.

Re: Raw mode and help missing from the Unix port?

Posted: Tue Oct 15, 2019 6:55 am
by jimmo
Oh, interesting!

I guess it is worth raising these issues, at least to open the discussion. Would be great if you can get in touch with someone from Lego too just to make sure they are willing to pick up the changes.

Re: Raw mode and help missing from the Unix port?

Posted: Tue Oct 15, 2019 9:23 am
by Roberthh
@jimmo Thing are more messed up than I expected. Adding help is easy, like you told. Raw repl maybe is urely also straightforward..
The weak links stuff may be left off by intention, to load the modules from micropython-lib, which offer a larger API. But on my first test, importing os, I stumbled over an inconsistency. the os module tries to import uarray. That does not exist, because tha module in called array in the micropython port. There may be more stumbling blocks like this, but at least this topic requires a clean intention and tidying up.

Re: Raw mode and help missing from the Unix port?

Posted: Wed Oct 16, 2019 10:31 am
by Damien
For enabling help on the unix port, there was already a PR submitted for this, see https://github.com/micropython/micropython/pull/3436 for the discussion. I'd be in favour of enabling it, at least so that help('modules') works.

As for the raw repl, I don't think that's as easy to enable on unix, partly because soft-reset is also not something the unix port supports (the usual ctrl-D will exit the unix MicroPython). How exactly would you use raw REPL on the unix port?

Re: Raw mode and help missing from the Unix port?

Posted: Wed Oct 16, 2019 10:51 am
by aivarannamaa
Damien wrote:
Wed Oct 16, 2019 10:31 am
How exactly would you use raw REPL on the unix port?
Thonny actually does all communication via raw REPL, even evaluation of single expressions. To the user everything looks like regular REPL, though.

Thonny's shell would run MicroPython over SSH (or as subprocess when using it in local machine) detecting prompts and forwarding user (and management) commands. With serial connection I preferred raw REPL because it separates regular and exception output and because it disables echo.

It now occurred to me that over SSH or subprocess there won't be any echo (at least I hope so). And I forgot to worry whether the repl (be it regular or raw) works at all if the input is just piped to it (ie. without tty).

Re: Raw mode and help missing from the Unix port?

Posted: Wed Oct 16, 2019 10:55 am
by Damien
Some of the unix command-line test do run the unix port through a piped connection to a subprocess with redirected input, so that is certainly possible. In such a case raw REPL would be useful.