REPL improvement

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
User avatar
pythoncoder
Posts: 3599
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

REPL improvement

Post by pythoncoder » Mon Sep 08, 2014 12:23 pm

It would be handy if there were a way to make the REPL command history survive a soft reboot. Either automagically or with a control key. Is this feasible?

Regards, Pete
Peter Hinch

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: REPL improvement

Post by pfalcon » Mon Sep 08, 2014 3:20 pm

It's on my todo to enable this (optionally) for unix version.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
pythoncoder
Posts: 3599
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: REPL improvement

Post by pythoncoder » Mon Sep 08, 2014 3:31 pm

A thought occurred to me after I posted this. Can the same effect can be achieved at the terminal emulator level? IOW one which retains a list of its own history and enables you to re-send previous lines. I don't think screen has this facility but maybe one of the numerous alternatives does? It would save a lot of time testing code on the Micropython board.

I'm after a Linux solution but others used closed source OS's. Or so I'm told ;)

Regards, Pete
Peter Hinch

User avatar
dhylands
Posts: 3227
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: REPL improvement

Post by dhylands » Mon Sep 08, 2014 6:20 pm

I put together a python script I called usb-ser-mon.py https://github.com/dhylands/usb-ser-mon

Under linux, it has the advantage that it detects when USB connected devices go away and it auto-reconnects when it comes back.

It could definitely be modified to provide infinite history (and perhaps even record it to a file). It already records the entire session in the form of a log file.

I think that adding support for readline (probably as an option) would give you what you're looking for. I guess I need to think about adding support for some type of .rc file to support customizable options is in order here as well.

I've also been investigating what's available in the form of remote-editors, and it looks like gedit supports writing plugins in python, and supports remote editing. So I was thinking it would be cool to write a plug which allowed files to be edited from the python flash (but through the serial/USB interface, not the mass storage interface), and you could also create a terminal style plugin as well. gedit is also cross-plaform, so it may be possible to get something that works on linux/windows/mac.

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: REPL improvement

Post by Turbinenreiter » Mon Sep 08, 2014 6:54 pm

@dhylands
I'm using the External Tools plugin to copy scripts to the pyboard. That way I can work on them on the computers filesystem (and use git) and send them to the pyboard wit ctrl-alt-d. Uses the mass storage interface tough and is not cross-platform.

Code: Select all

#!/bin/sh
rsync $GEDIT_CURRENT_DOCUMENT_PATH "/media/plam/4421-0000/$GEDIT_CURRENT_DOCUMENT_NAME"
echo deployed $GEDIT_CURRENT_DOCUMENT_NAME to '/media/plam/4421-0000/'$GEDIT_CURRENT_DOCUMENT_NAME
Having a cross platform 'IDE' would be a pretty big deal and make it way easier to help people with their problems. It would also make it easier for people to start.
I'd imagine something that:
[*] provides a REPL on the bottom (in the picture it's the *nix interpreter instead of the REPL)
[*] provides sort of an upload button to copy the script to the board, but you are actually working in a local dir
[*] provides a view of the pyboards filesystem and the local one

All this would be possible to do with gedit.
Attachments
gedit.png
gedit.png (212.36 KiB) Viewed 3671 times

stijn
Posts: 362
Joined: Thu Apr 24, 2014 9:13 am

Re: REPL improvement

Post by stijn » Tue Sep 09, 2014 7:35 am

re: REPL: Just having the history is useful, but often history is flooded with me trying to figure out the correct syntax and other statements which have no real use for a history. So ideally it would be editable (just a file as backend) and have bash-like Ctrl-R functionality to make it somewhat easier to work with history. Anyway, personally I still find a bunch of seperate files with all things I ever tried much more useful and organized than REPL history.

re: IDE: SublimeText can do all that as well, plugins are also in Python. Closed source though so gedit seems a better choice.. Pretty much all plugins are open source. The only thing to do from you whishlist would be to write the plugin for the upload, but that's probably just a couple of lines. The seperate filesys views is covered already and the REPL plugin works pretty well with uPy, I've been using it since I started with uPy. And it has history as well. And syntax highlighting.

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: REPL improvement

Post by Turbinenreiter » Tue Sep 09, 2014 10:33 am

Sublime Text costs two pyboards.
However, having plugins for that would also be nice and we could probably share code.

Another feature:
[*] flash a new micropython version to the board. maybe even compiled from source, with an easy way to enable options by just ticking boxes.

I'll dive into gedit plugins this evening and see what I can come up with.

stijn
Posts: 362
Joined: Thu Apr 24, 2014 9:13 am

Re: REPL improvement

Post by stijn » Sun Sep 21, 2014 8:34 am

Any news on this? Does the REPL/file view/... work in GEdit?

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: REPL improvement

Post by Turbinenreiter » Sun Sep 21, 2014 9:18 am

@stjin
Yes. Terminal and file view already exist and can be used.

I also tried to build a little toolbox, but I got stuck quickly, because I couldn't figure out how to get the current files name.


This is what I got so far:
upydev.py

Code: Select all

from gi.repository import GObject, GLib, Gio, Gtk, Gedit

class MicropythonToolbox(Gtk.Box):

    def __init__(self):
        Gtk.Box.__init__(self)

        grid = Gtk.Grid()
        self.add(grid)

        button1 = Gtk.Button(label='Deploy')
        button1.connect('clicked', self.on_button1_clicked)
        grid.add(button1)

        button2 = Gtk.Button(label='Flash new Firmware')
        #button1.connect('clicked', self.on_button1_clicked)
        grid.add(button2)

        grid.show_all()

    def on_button1_clicked(self, widget):
        print('deploy'))

class MicropythonDeveloperTools(GObject.Object, Gedit.WindowActivatable):
    __gtype_name__ = 'MicropythonDeveloperTools'

    window = GObject.property(type=Gedit.Window)

    def __init__(self):
        GObject.Object.__init__(self)

    def do_activate(self):

        self._panel = MicropythonToolbox()
        self._panel.show()

        bottom = self.window.get_bottom_panel()
        bottom.add_titled(self._panel, 'MicropythonToolbox', _('MicropythonToolbox'))

    def do_deactivate(self):
        bottom = self.window.get_bottom_panel()
        bottom.remove(self._panel)
upydev.plugin

Code: Select all

[Plugin]
Loader=python3
Module=upydev
IAge=3
Name=Micropython Developer Tools
Description=A set of tools to work with micropython and the pyboard
Authors=Sebastian Plamauer
Copyright=Copyright 2014 Sebastian Plamauer
Website=http://www.github.com/turbinenreiter
Version=0.1

Post Reply