Repository navigation
Micropython support #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Micropython support #514
Changes from all commits
43a7621
23b2d14
e941a63
824f303
20d4b78
80222e7
3ff239d
49be32c
0e213c2
37fdbc5
96b4a08
bffd728
4423a87
68fc61f
88827c9
a1a14d5
03f1eb7
b21b204
0cacf22
06b5e6a
6bc9fc5
33b1142
92c0d6f
a278e3c
92b165f
fe8919d
cb78b8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,32 @@ | ||
| language: python | ||
| env: | ||
| - USE_MICROPYTHON=false | ||
| - USE_MICROPYTHON=true | ||
| python: | ||
| - 3.4 | ||
| cache: pip | ||
| cache: | ||
| pip: true | ||
| directories: | ||
| - ~/micropython | ||
| - ~/.micropython | ||
| sudo: false | ||
| git: | ||
| depth: 100 | ||
| install: | ||
| - pip install Pillow Sphinx sphinx_bootstrap_theme recommonmark evdev==1.0.0 | ||
| - pip install -r ./docs/requirements.txt | ||
| - if [ $USE_MICROPYTHON = false ]; then pip install Pillow Sphinx sphinx_bootstrap_theme recommonmark evdev==1.0.0 && pip install -r ./docs/requirements.txt; fi | ||
| - if [ $USE_MICROPYTHON = true ]; then ./.travis/install-micropython.sh && PYTHON=~/micropython/ports/unix/micropython; else PYTHON=python3; fi | ||
| script: | ||
| - chmod -R g+rw ./tests/fake-sys/devices/**/* | ||
| - ./tests/api_tests.py | ||
| - sphinx-build -nW -b html ./docs/ ./docs/_build/html | ||
| - $PYTHON tests/api_tests.py | ||
| - if [ $USE_MICROPYTHON = false ]; then sphinx-build -nW -b html ./docs/ ./docs/_build/html; fi | ||
| deploy: | ||
| provider: pypi | ||
| user: Denis.Demidov | ||
| password: | ||
| secure: cTDN4WMJEjxZ0zwFwkLPpOIOSG/1JlHbQsHzd/tV9LfjBMR0nJR5HrmyiIO1TE5Wo6AFSFd7S3JmKdEnFO1ByvN/EFtsKGRUR9L6Yst4KfFi4nHwdZ7vgPTV0nNdvgC1YM/3bx8W8PcjFSm/k8awx7aicwXj09yDA8ENTf5XedaX22Z+9OKhb1mKola1cqEoc0GwaYzd8UX0Ruwh9/6RRbvTt7zn8BCZc9vIVqNd6mZgBWY9zAU40ZZsjYORbiZmDNCygEI+RViZ51M58WYkPPhoivzcG9em8DMRS7SC3CjWGapiOaXUHa3Fhnn+IQ+Q8Xv9YU5+qmj65MWQy3SSnMnvuxmrLf4aLoOlSJUMhDarjni4tdBOTX5PdOkdmhskyQt1DqDrw0+WhPItYfGe5zQfQwqW+YOpGbOipAeU+844arPo5jvZG/IOBX2qVUwdSxo8Y/98ocjqoZOq8b5xkWtJef0Kh1RCkp1bR2XELQVe76qeWqQxWz3OPqq+wK3xeNvj5kMQmytl3dCEB//D6UcES7Qr8YxD+LWoaIf32JIj/4LaCXXuxMVH+PJ68Oc72/ox0qLmXK0qhbea2QvaqXyGDrO+a2X6VbMdH32D2xHzH4Mg75xLnXnSaFvGovhYl1zEVcYUDioxrXZEuDmymGf9nH2mivJ24Fon6u+C3QQ= | ||
| on: | ||
| tags: true | ||
| condition: $TRAVIS_TAG != ev3dev-stretch/* | ||
| condition: | ||
| - $TRAVIS_TAG != ev3dev-stretch/* | ||
| - $USE_MICROPYTHON = false | ||
| repo: ev3dev/ev3dev-lang-python | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/bin/sh | ||
| set -ex | ||
|
|
||
| if [ -e ~/micropython/ports/unix/micropython ]; then | ||
| # the micropython binary already exists, which means that the cached folder was restored | ||
| exit 0 | ||
| fi | ||
|
|
||
| cd ~/ | ||
|
|
||
| # Build micropython from source | ||
| # TODO: cache micropython build output | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is how I did it: Adding a path to travis cache: https://github.com/ddemidov/amgcl/blob/master/.travis.yml#L39-L42 Checking if path exists (that is, if cache was unpacked successfully): https://github.com/ddemidov/amgcl/blob/master/.travis/install_boost.sh#L5
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thanks for the reference! |
||
| git clone --recurse-submodules https://github.com/micropython/micropython.git --depth 1 --branch v1.9.4 --quiet | ||
| cd ./micropython/ports/unix | ||
| make axtls | ||
| make | ||
|
|
||
| # Install upip | ||
| ~/micropython/tools/bootstrap_upip.sh | ||
|
|
||
| # Install micropython library modules | ||
| ~/micropython/ports/unix/micropython -m upip install micropython-unittest micropython-os micropython-os.path micropython-shutil micropython-io micropython-fnmatch micropython-numbers micropython-struct micropython-time micropython-logging micropython-select | ||
| # Make unittest module show error output; will run until failure then print first error | ||
| # See https://github.com/micropython/micropython-lib/blob/f20d89c6aad9443a696561ca2a01f7ef0c8fb302/unittest/unittest.py#L203 | ||
| sed -i 's/#raise/raise/g' ~/.micropython/lib/unittest.py | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,15 @@ | |
| if sys.version_info < (3,4): | ||
| raise SystemError('Must be using Python 3.4 or higher') | ||
|
|
||
| def is_micropython(): | ||
| return sys.implementation.name == "micropython" | ||
|
|
||
| def chain_exception(exception, cause): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I like how I did this... Micropython doesn't support exception chaining, so we have to suppress the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we could implement our own Exception subclass, that would carry its parent exception around, but I am not sure if that would be any better than what you did. |
||
| if is_micropython(): | ||
| raise exception | ||
| else: | ||
| raise exception from cause | ||
|
|
||
| import os | ||
| import io | ||
| import fnmatch | ||
|
|
@@ -188,7 +197,8 @@ def get_index(file): | |
| except StopIteration: | ||
| self._path = None | ||
| self._device_index = None | ||
| raise DeviceNotFound("%s is not connected." % self) from None | ||
|
|
||
| chain_exception(DeviceNotFound("%s is not connected." % self), None) | ||
|
|
||
| def __str__(self): | ||
| if 'address' in self.kwargs: | ||
|
|
@@ -206,13 +216,13 @@ def _attribute_file_open(self, name): | |
| w_ok = mode & stat.S_IWGRP | ||
|
|
||
| if r_ok and w_ok: | ||
| mode = 'r+' | ||
| mode_str = 'r+' | ||
| elif w_ok: | ||
| mode = 'w' | ||
| mode_str = 'w' | ||
| else: | ||
| mode = 'r' | ||
| mode_str = 'r' | ||
|
|
||
| return io.FileIO(path, mode) | ||
| return io.FileIO(path, mode_str) | ||
|
|
||
| def _get_attribute(self, attribute, name): | ||
| """Device attribute getter""" | ||
|
|
@@ -245,20 +255,22 @@ def _raise_friendly_access_error(self, driver_error, attribute): | |
| if not isinstance(driver_error, OSError): | ||
| raise driver_error | ||
|
|
||
| if driver_error.errno == errno.EINVAL: | ||
| driver_errorno = driver_error.args[0] if is_micropython() else driver_error.errno | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would feel nicer if this would be implemented as a function ( |
||
|
|
||
| if driver_errorno == errno.EINVAL: | ||
| if attribute == "speed_sp": | ||
| try: | ||
| max_speed = self.max_speed | ||
| except (AttributeError, Exception): | ||
| raise ValueError("The given speed value was out of range") from driver_error | ||
| chain_exception(ValueError("The given speed value was out of range"), driver_error) | ||
| else: | ||
| raise ValueError("The given speed value was out of range. Max speed: +/-" + str(max_speed)) from driver_error | ||
| raise ValueError("One or more arguments were out of range or invalid") from driver_error | ||
| elif driver_error.errno == errno.ENODEV or driver_error.errno == errno.ENOENT: | ||
| chain_exception(ValueError("The given speed value was out of range. Max speed: +/-" + str(max_speed)), driver_error) | ||
| chain_exception(ValueError("One or more arguments were out of range or invalid"), driver_error) | ||
| elif driver_errorno == errno.ENODEV or driver_errorno == errno.ENOENT: | ||
| # We will assume that a file-not-found error is the result of a disconnected device | ||
| # rather than a library error. If that isn't the case, at a minimum the underlying | ||
| # error info will be printed for debugging. | ||
| raise DeviceNotFound("%s is no longer connected" % self) from driver_error | ||
| chain_exception(DeviceNotFound("%s is no longer connected" % self), driver_error) | ||
| raise driver_error | ||
|
|
||
| def get_attr_int(self, attribute, name): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that this (the list for
condition) isn't right. I need to take another look and figure out how to do it correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind... although the documentation says
It emits the correct script: