Raw mode and help missing from the Unix port?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
aivarannamaa
Posts: 25
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Raw mode and help missing from the Unix port?

Post by aivarannamaa » Thu Oct 10, 2019 7:58 pm

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?

User avatar
jimmo
Posts: 892
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

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

Post by jimmo » Sun Oct 13, 2019 11:14 pm

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... :)

User avatar
aivarannamaa
Posts: 25
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

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

Post by aivarannamaa » Mon Oct 14, 2019 4:25 am

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.

User avatar
jimmo
Posts: 892
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

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

Post by jimmo » Tue Oct 15, 2019 6:55 am

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.

User avatar
Roberthh
Posts: 1744
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

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

Post by Roberthh » Tue Oct 15, 2019 9:23 am

@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.

Damien
Site Admin
Posts: 623
Joined: Mon Dec 09, 2013 5:02 pm

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

Post by Damien » Wed Oct 16, 2019 10:31 am

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?

User avatar
aivarannamaa
Posts: 25
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

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

Post by aivarannamaa » Wed Oct 16, 2019 10:51 am

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).

Damien
Site Admin
Posts: 623
Joined: Mon Dec 09, 2013 5:02 pm

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

Post by Damien » Wed Oct 16, 2019 10:55 am

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.

Post Reply