8000 mpremote/mip: Add test for installing a package from local files. · micropython/micropython@7cc10a8 · GitHub
[go: up one dir, main page]

Skip to content < 8000 script type="application/json" data-target="react-partial.embeddedData">{"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit 7cc10a8

Browse files
committed
mpremote/mip: Add test for installing a package from local files.
Add tools/mpremote/tests/test_mip_local_install.sh to test the installation of a package from local files using relative URLs in the package.json. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
1 parent 4bb9cda commit 7cc10a8

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# This test the "mpremote mip install" from local files. It creates a package
4+
# and "mip installs" it into a ramdisk. The package is then imported and
5+
# executed. The package is a simple "Hello, world!" example.
6+
7+
set -e
8+
9+
PACKAGE=mip_example
10+
PACKAGE_DIR=${TMP}/example
11+
MODULE_DIR=${PACKAGE_DIR}/${PACKAGE}
12+
13+
target=/__ramdisk
14+
block_size=512
15+
num_blocks=50
16+
17+
# Create the smallest permissible ramdisk.
18+
cat << EOF > "${TMP}/ramdisk.py"
19+
class RAMBlockDev:
20+
def __init__(self, block_size, num_blocks):
21+
self.block_size = block_size
22+
self.data = bytearray(block_size * num_blocks)
23+
24+
def readblocks(self, block_num, buf):
25+
for i in range(len(buf)):
26+
buf[i] = self.data[block_num * self.block_size + i]
27+
28+
def writeblocks(self, block_num, buf):
29+
for i in range(len(buf)):
30+
self.data[block_num * self.block_size + i] = buf[i]
31+
32+
def ioctl(self, op, arg):
33+
if op == 4: # get number of blocks
34+
return len(self.data) // self.block_size
35+
if op == 5: # get block size
36+
return self.block_size
37+
38+
import os
39+
40+
bdev = RAMBlockDev(${block_size}, ${num_blocks})
41+
os.VfsFat.mkfs(bdev)
42+
os.mount(bdev, '${target}')
43+
EOF
44+
45+
echo ----- Setup
46+
mkdir -p ${MODULE_DIR}
47+
echo "def hello(): print('Hello, world!')" > ${MODULE_DIR}/hello.py
48+
echo "from .hello import hello" > ${MODULE_DIR}/__init__.py
49+
cat > ${PACKAGE_DIR}/package.json <<EOF
50+
{
51+
"urls": [
52+
["${PACKAGE}/__init__.py", "${PACKAGE}/__init__.py"],
53+
["${PACKAGE}/hello.py", "${PACKAGE}/hello.py"]
54+
],
55+
"version": "0.2"
56+
}
57+
EOF
58+
59+
$MPREMOTE run "${TMP}/ramdisk.py"
60+
$MPREMOTE resume mkdir ${target}/lib
61+
echo
62+
echo ---- Install package
63+
$MPREMOTE resume mip install --target=${target}/lib ${PACKAGE_DIR}/package.json
64+
echo
65+
echo ---- Test package
66+
$MPREMOTE resume exec "import sys; sys.path.append(\"${target}/lib\")"
67+
$MPREMOTE resume exec "import ${PACKAGE}; ${PACKAGE}.hello()"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
----- Setup
2+
mkdir :/__ramdisk/lib
3+
4+
---- Install package
5+
Install ${TMP}/example/package.json
6+
Installing: /__ramdisk/lib/mip_example/__init__.py
7+
Installing: /__ramdisk/lib/mip_example/hello.py
8+
Done
9+
10+
---- Test package
11+
Hello, world!

0 commit comments

Comments
 (0)
0