Skip to content

Commit

Permalink
Allow specifying version in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
sebromero committed Nov 21, 2024
1 parent 5846d4d commit 8a0f074
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]"] // Test library with version

// "args": ["list", "micropython-rotary"]
// "args": ["find", "cloud"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ upy-package [options] [command]
- `list`: Lists packages available from registries.
- `info <package>`: Retrieves detailed information about a specific package.
- `find <pattern>`: Searches for packages using the supplied pattern.
- `install [options] <package-names...>`: Installs MicroPython packages onto a connected Arduino board. When installing multiple packages, they should be separated by a space.
- `install [options] <package-names...>`: 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/[email protected]).
- `--debug`: Enable debug output
- `help [command]`: Displays help information for a specific command.

Expand Down
11 changes: 9 additions & 2 deletions logic/package-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]'.
* @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);
}

/**
Expand All @@ -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}`);
}
}
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function main() {

program
.command('install')
.argument('<package-names...>', 'Package names to install')
.argument('<package-names...>', 'Package names or URLs to install')
// .option('--path <target-path>', 'Target path to install the package(s) to')
.option('--debug', 'Enable debug output')
.description('Install MicroPython packages on a connected Arduino board')
Expand Down

0 comments on commit 8a0f074

Please sign in to comment.