forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/mpremote: Add support for relative urls in package.json files.
URLs in `package.json` may now be specified relative to the base URL of the `package.json` file. Relative URLs wil work for `package.json` files installed from the web as well as local file paths. Docs: update `docs/reference/packages.rst` to add documentation for: - Installing packages from local filesystems (PR micropython#12476); and - Using relative URLs in the `package.json` file (PR micropython#12477); - Update the packaging example to encourage relative URLs as the default in `package.json`. 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 <[email protected]>
- Loading branch information
Showing
4 changed files
with
149 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
|
||
# This test the "mpremote mip install" from local files. It creates a package | ||
# and "mip installs" it into a ramdisk. The package is then imported and | ||
# executed. The package is a simple "Hello, world!" example. | ||
|
||
set -e | ||
|
||
PACKAGE=mip_example | ||
PACKAGE_DIR=${TMP}/example | ||
MODULE_DIR=${PACKAGE_DIR}/${PACKAGE} | ||
|
||
target=/__ramdisk | ||
block_size=512 | ||
num_blocks=50 | ||
|
||
# Create the smallest permissible ramdisk. | ||
cat << EOF > "${TMP}/ramdisk.py" | ||
class RAMBlockDev: | ||
def __init__(self, block_size, num_blocks): | ||
self.block_size = block_size | ||
self.data = bytearray(block_size * num_blocks) | ||
def readblocks(self, block_num, buf): | ||
for i in range(len(buf)): | ||
buf[i] = self.data[block_num * self.block_size + i] | ||
def writeblocks(self, block_num, buf): | ||
for i in range(len(buf)): | ||
self.data[block_num * self.block_size + i] = buf[i] | ||
def ioctl(self, op, arg): | ||
if op == 4: # get number of blocks | ||
return len(self.data) // self.block_size | ||
if op == 5: # get block size | ||
return self.block_size | ||
import os | ||
bdev = RAMBlockDev(${block_size}, ${num_blocks}) | ||
os.VfsFat.mkfs(bdev) | ||
os.mount(bdev, '${target}') | ||
EOF | ||
|
||
echo ----- Setup | ||
mkdir -p ${MODULE_DIR} | ||
echo "def hello(): print('Hello, world!')" > ${MODULE_DIR}/hello.py | ||
echo "from .hello import hello" > ${MODULE_DIR}/__init__.py | ||
cat > ${PACKAGE_DIR}/package.json <<EOF | ||
{ | ||
"urls": [ | ||
["${PACKAGE}/__init__.py", "${PACKAGE}/__init__.py"], | ||
["${PACKAGE}/hello.py", "${PACKAGE}/hello.py"] | ||
], | ||
"version": "0.2" | ||
} | ||
EOF | ||
|
||
$MPREMOTE run "${TMP}/ramdisk.py" | ||
$MPREMOTE resume mkdir ${target}/lib | ||
echo | ||
echo ---- Install package | ||
$MPREMOTE resume mip install --target=${target}/lib ${PACKAGE_DIR}/package.json | ||
echo | ||
echo ---- Test package | ||
$MPREMOTE resume exec "import sys; sys.path.append(\"${target}/lib\")" | ||
$MPREMOTE resume exec "import ${PACKAGE}; ${PACKAGE}.hello()" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
----- Setup | ||
mkdir :/__ramdisk/lib | ||
|
||
---- Install package | ||
Install ${TMP}/example/package.json | ||
Installing: /__ramdisk/lib/mip_example/__init__.py | ||
Installing: /__ramdisk/lib/mip_example/hello.py | ||
Done | ||
|
||
---- Test package | ||
Hello, world! |