Alternative to upip - comments and help sought

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

Alternative to upip - comments and help sought

Post by pythoncoder » Sun Jan 07, 2018 11:43 am

upip is primarily targeted at network-enabled hardware. Users of hardware without a network connection have to jump through several hoops to use upip to install a library. The following steps are required, some of which may be problematic for beginners:
  • Ensure the presence of a Linux installation or VM.
    Clone the source.
    Build the Unix build.
    Put micropython on the path
I have written micropip.py which aims to simplify this. It runs under CPython 3.2 or greater, and enables installation to a directory on the PC for subsequent copying to the target. It is intended to be cross-platform.

I have tested under Linux, also under Windows XP (I don't have a newer version). I have no access to Apple hardware. So I'd appreciate it if someone could test under Windows 10 and OSX, and if necessary submit PR's.

I'd appreciate the view of @Damien: is there any interest in a PR to put this in tools?
Peter Hinch
Index to my micropython libraries.

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: Alternative to upip - comments and help sought

Post by SpotlightKid » Sun Jan 07, 2018 6:04 pm

pythoncoder wrote:
Sun Jan 07, 2018 11:43 am
I'd appreciate the view of @Damien: is there any interest in a PR to put this in tools?
I would put in it's own repo. The same as the standard pip is its own project, separate from CPython (though there's some integration now). You could ask Damien whether he can create a repo under the micropython Github organization.

In its own repo the tool could have some documentation and could be made installable with (CPython) pip.

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

Re: Alternative to upip - comments and help sought

Post by stijn » Sun Jan 07, 2018 7:42 pm

Quickly tested this on Win 7 and seems ok. Doesn't give a message if package already installed but that's minor. PEP8 warnings:
- E115 on line 125 for the comment
- F841 on line 176 for unused variable name
- E126 on line 216 for over-indenting

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

Re: Alternative to upip - comments and help sought

Post by pythoncoder » Mon Jan 08, 2018 5:33 am

Thanks for the comments and testing. Any OSX users out there?
@SpotlightKid Good suggestion. Damien seems to be off-grid at the moment but I'll suggest it.
@stijn The module was derived from upip with changes to use standard Python libraries rather than the optimised MicroPython specific replacements - bear in mind that upip was written to run on resource-constrained platforms like ESP8266. Note that the archive format is nonstandard for the same reason, which is why we can't use pip. So some of its issues are inherited from upip notably the lack of an upgrade command and the lack of a message if the package is already installed. I'll look at this if there are reports of problems in actual use.

I've now run the notoriously picky pylint against it and made it more PEP8 compliant. Many of the warnings - notably the choice of variable names - originated in upip and I can't summon the enthusiasm for a big refactor on a small utility. I've pushed some tidier code.
Peter Hinch
Index to my micropython libraries.

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

Re: Alternative to upip - comments and help sought

Post by stijn » Mon Jan 08, 2018 8:29 am

Thanks for the clarification.
And a possible feature request: the way I use micropython-lib now is having a local clone and running a script against it which, given package names, copies the appropriate .py files to a destination directory. This is similar to what micropython-lib's Makefile does, but filtered. And in essence what pip does but from a local uncompressed 'package repository', I think that's pip -e path/to/dir? How about putting this functionality in micopip.py? I'm not 100% sure if it belongs into this file, but it would be convenient to have a single go-to pip-like module.

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

Re: Alternative to upip - comments and help sought

Post by pythoncoder » Tue Jan 09, 2018 6:48 am

I'm loath to add features unless there is significant interest from the community or the maintainers. Although I have a local clone PyPi works well for me.
Peter Hinch
Index to my micropython libraries.

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

Re: Alternative to upip - comments and help sought

Post by stijn » Tue Jan 09, 2018 10:04 am

PyPi is fine for most cases but has obvious disadvantages (needs network, doesn't work or not easy with custom fork).
Anyway: let's see what Damien says but I think this definitely should go forward: it just works, is independent of compiler toolset which is a huge bonus, and does so likely on all host platforms where Python runs which is a prerequisite for uPy anyway.

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

Re: Alternative to upip - comments and help sought

Post by Roberthh » Sun Jan 14, 2018 11:44 am

I gave it a try with OS X 10.11.6 (El Capitan), and it worked fine.

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

Re: Alternative to upip - comments and help sought

Post by pythoncoder » Sun Jan 14, 2018 11:50 am

Thanks for testing, Robert.
Peter Hinch
Index to my micropython libraries.

boneskull
Posts: 1
Joined: Tue Jan 23, 2018 11:49 pm

Re: Alternative to upip - comments and help sought

Post by boneskull » Tue Jan 23, 2018 11:54 pm

Thanks for this, nice work.

One thing to note is that python3 is not always installed in /usr/bin/python3. I think you probably want:

#!/usr/bin/env python3

Post Reply