upip my drivers

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

upip my drivers

Post by mcauser » Fri Jun 23, 2017 7:52 am

I have made a few drivers for my various micropython projects.
To reduce code duplication, I'd like to remove drivers from the projects and use upip to install them instead.

Trying to figure out how to get from here:
https://github.com/mcauser/micropython-am2320

To here:

Code: Select all

upip.install('micropython-am2320')
With a goal of building a tutorial for users new to pip/upip, with steps on publishing packages. eg.

1. Build an awesome driver
2. Create a setup.py
3. ???
4. PROFIT

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

Re: upip my drivers

Post by pythoncoder » Fri Jun 23, 2017 9:05 am

I've yet to figure that out. I look forward to reading it ;)
Peter Hinch
Index to my micropython libraries.

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: upip my drivers

Post by mcauser » Fri Jun 23, 2017 11:06 pm

So far I have:

* Publish your project on Github. eg. https://github.com/mcauser/micropython-am2320
* Add setup.py to your project. eg. https://github.com/mcauser/micropython- ... r/setup.py
* Tag with a version, eg 1.0.0. eg. https://github.com/mcauser/micropython- ... tag/v1.0.0
* Use x.x.x. for version numbers - see. http://semver.org/
* Read instructions https://packaging.python.org/tutorials/ ... ct-to-pypi
* Create login on https://pypi.python.org/pypi/
* Create ~/.pypirc to store pypi auth (in plaintext!)
* In your project dir, create a Source Distribution. This creates /dist/*.tar.gz

Code: Select all

$ python setup.py sdist
* Upload to pypi using twine. Twine will handle registering the project

Code: Select all

$ pip install twine
$ twine upload dist/*
* You should now see your package on https://pypi.python.org/pypi eg. https://pypi.python.org/pypi/micropython-am2320/1.0.0
* Connect to your MicroPython device. eg. WeMos D1 Mini

Code: Select all

$ screen /dev/tty.wchusbserial1420 115200

Code: Select all

MicroPython v1.9-1-ge5e49be-dirty on 2017-06-09; ESP module with ESP8266
>>> import network
>>> sta_if = network.WLAN(network.STA_IF)
>>> sta_if.active(True)
(upip needs access to the internet)

>>> import os
>>> os.listdir('lib')
[]

>>> import upip
>>> upip.install('micropython-am2320')
Installing to: /lib/
Warning: pypi.python.org SSL certificate is not validated
Installing micropython-am2320 1.0.0 from https://pypi.python.org/packages/52/7a/7002dadbc77ed0ea437331d038a5d69f169f4f450da03f96c01d7cce1919/micropython-am2320-1.0.0.tar.gz
Error installing 'micropython-am2320': [Errno 22] EINVAL, packages may be partially installed

>>> os.listdir('lib')
['am2320.py']
(library is there)

>>> import am2320
>>> from machine import I2C, Pin
>>> i2c = I2C(scl=Pin(5), sda=Pin(4))
>>> sensor = am2320.AM2320(i2c)
>>> sensor.measure()
(and it works)

>>> os.remove('/lib/am2320.py')
(delete it)
It works, but I'm still trying to figure out that [Errno 22] EINVAL, packages may be partially installed error.

You can find my drivers by using the Programming Language :: Python :: Implementation :: MicroPython classifier.
https://pypi.python.org/pypi?:action=browse&c=639

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

Re: upip my drivers

Post by pfalcon » Mon Jun 26, 2017 3:00 pm

The best way to learn how to make package installable on esp8266 is to look how such existing packages are made. micropython-lib is a source of uncountable number of such packages, plus few more "standalone" packages were announced on esp8266 forum (hint: notes-pico, which has half-dozen of other packages in dependencies).
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/

Post Reply