From 8a0f07439ef77f035202b161d9998dca381677b9 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Thu, 21 Nov 2024 12:07:07 +0100 Subject: [PATCH] Allow specifying version in URL --- .vscode/launch.json | 3 ++- README.md | 2 +- logic/package-manager.js | 11 +++++++++-- main.js | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d0bcec6..aab87ff 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,7 +19,8 @@ // "args": ["install", "github:arduino/arduino-modulino-mpy"] // Test github: URL // "args": ["install", "arduino-iot-cloud-py"] // Test regular library // "args": ["install", "micropython-my9221"] // Test library with custom package.json - "args": ["install", "github:peterhinch/micropython_ir/ir_tx"] // Test library with subfolder + // "args": ["install", "github:peterhinch/micropython_ir/ir_tx"] // Test library with subfolder + "args": ["install", "github:arduino/arduino-iot-cloud-py@v1.3.3"] // Test library with version // "args": ["list", "micropython-rotary"] // "args": ["find", "cloud"] diff --git a/README.md b/README.md index c8d4dd6..4ac9a4f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ upy-package [options] [command] - `list`: Lists packages available from registries. - `info `: Retrieves detailed information about a specific package. - `find `: Searches for packages using the supplied pattern. -- `install [options] `: Installs MicroPython packages onto a connected Arduino board. When installing multiple packages, they should be separated by a space. +- `install [options] `: Installs MicroPython packages onto a connected Arduino board. When installing multiple packages, they should be separated by a space. It supports installing packages by name or URL. In the latter case you can specify the version using an @version suffix (e.g. github:arduino/arduino-iot-cloud-py@v1.3.3). - `--debug`: Enable debug output - `help [command]`: Displays help information for a specific command. diff --git a/logic/package-manager.js b/logic/package-manager.js index 923472f..edc33fb 100644 --- a/logic/package-manager.js +++ b/logic/package-manager.js @@ -143,10 +143,16 @@ export class PackageManager { /** * Function to install a package from a URL * @param {string} packageURL The URL of the package to install. + * Supported formats: 'github:owner/repo' or 'gitlab:owner/repo' + * or https://github.com/owner/repo or https://gitlab.com/owner/repo. + * It's also possible to indicate a specific package.json file or even single .py files. + * Supports versioning with the by appending @version e.g. 'arduino/arduino-iot-cloud-py@v1.3.3'. * @param {SerialDevice} device The board to install the package on. */ async installPackageFromURL(packageURL, device) { - await this.installPackage({ "url" : packageURL }, device); + const packageVersion = packageURL.split("@")[1]; + const packageURLWithoutVersion = packageURL.split("@")[0]; + await this.installPackage({ "url" : packageURLWithoutVersion, "version" : packageVersion }, device); } /** @@ -163,9 +169,10 @@ export class PackageManager { // so they are installed by supplying the name as the URL const packageURL = aPackage.url ? aPackage.url : aPackage.name; const customPackageJson = aPackage.package_descriptor; + const packageVersion = aPackage.version; const packager = new Packager(device.serialPort, this.compileFiles, this.overwriteExisting); - await packager.packageAndInstall(packageURL, null, customPackageJson); + await packager.packageAndInstall(packageURL, packageVersion, customPackageJson); console.debug(`✅ Package installed: ${packageURL}`); } } \ No newline at end of file diff --git a/main.js b/main.js index eedb026..7c2d271 100755 --- a/main.js +++ b/main.js @@ -114,7 +114,7 @@ export async function main() { program .command('install') - .argument('', 'Package names to install') + .argument('', 'Package names or URLs to install') // .option('--path ', 'Target path to install the package(s) to') .option('--debug', 'Enable debug output') .description('Install MicroPython packages on a connected Arduino board')