Skip to content

Commit e1b2f2e

Browse files
vshymanskyydpgeorge
authored andcommitted
tools/mpy-tool.py: Add support for self-hosting of mpy-tool.
This allows running mpy-tool using MicroPython itself. An appropriate test is added to CI to make sure it continues to work. Signed-off-by: Volodymyr Shymanskyy <[email protected]> Signed-off-by: Angus Gratton <[email protected]>
1 parent fc71f78 commit e1b2f2e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

tools/ci.sh

+10
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,19 @@ function ci_mpy_format_test {
118118
python2.7 ./tools/mpy-tool.py -xd tests/frozen/frozentest.mpy
119119
python3 ./tools/mpy-tool.py -xd tests/frozen/frozentest.mpy
120120

121+
# Build MicroPython
122+
ci_unix_standard_build
123+
micropython=./ports/unix/build-standard/micropython
124+
$micropython -m mip install --target . argparse __future__
125+
export MICROPYPATH=.
126+
127+
# Test mpy-tool.py running under MicroPython
128+
$micropython ./tools/mpy-tool.py -x -d tests/frozen/frozentest.mpy
129+
121130
# Test mpy-tool.py dump feature on native code
122131
make -C examples/natmod/features1
123132
./tools/mpy-tool.py -xd examples/natmod/features1/features1.mpy
133+
$micropython ./tools/mpy-tool.py -x -d examples/natmod/features1/features1.mpy
124134
}
125135

126136
########################################################################################

tools/mpy-tool.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525
# THE SOFTWARE.
2626

27-
# Python 2/3 compatibility code
27+
# Python 2/3/MicroPython compatibility code
2828
from __future__ import print_function
29-
import platform
29+
import sys
3030

31-
if platform.python_version_tuple()[0] == "2":
31+
if sys.version_info[0] == 2:
3232
from binascii import hexlify as hexlify_py2
3333

3434
str_cons = lambda val, enc=None: str(val)
@@ -41,7 +41,7 @@ def hexlify_to_str(b):
4141
x = hexlify_py2(b)
4242
return ":".join(x[i : i + 2] for i in range(0, len(x), 2))
4343

44-
else:
44+
elif sys.version_info[0] == 3: # Also handles MicroPython
4545
from binascii import hexlify
4646

4747
str_cons = str

0 commit comments

Comments
 (0)