Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to install extra packages from extra indexes from jupyter-lite.json #158

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/pyodide-kernel-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const kernel: JupyterLiteServerPlugin<void> = {
const pipliteUrls = rawPipUrls.map((pipUrl: string) => URLExt.parse(pipUrl).href);
const disablePyPIFallback = !!config.disablePyPIFallback;
const loadPyodideOptions = config.loadPyodideOptions || {};
const extraPackagesAndIndexes = config.extraPackagesAndIndexes || [];

for (const [key, value] of Object.entries(loadPyodideOptions)) {
if (key.endsWith('URL') && typeof value === 'string') {
Expand Down Expand Up @@ -99,6 +100,7 @@ const kernel: JupyterLiteServerPlugin<void> = {
mountDrive,
loadPyodideOptions,
contentsManager,
extraPackagesAndIndexes,
});
},
});
Expand Down
2 changes: 2 additions & 0 deletions packages/pyodide-kernel/src/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class PyodideKernel extends BaseKernel implements IKernel {
location: this.location,
mountDrive: options.mountDrive,
loadPyodideOptions: options.loadPyodideOptions || {},
extraPackagesAndIndexes: options.extraPackagesAndIndexes || [],
};
}

Expand Down Expand Up @@ -394,5 +395,6 @@ export namespace PyodideKernel {
* The Jupyterlite content manager
*/
contentsManager: Contents.IManager;
extraPackagesAndIndexes: Array<{ packages: string[]; indexes: string[] | null }>;
}
}
5 changes: 5 additions & 0 deletions packages/pyodide-kernel/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export namespace IPyodideWorkerKernel {
*/
mountDrive: boolean;

/**
* List of extra url/wheel paths to load, and extra associated indexes urls (if not a wheel url)
*/
extraPackagesAndIndexes: Array<{ packages: string[]; indexes: string[] | null }>;

/**
* additional options to provide to `loadPyodide`
* @see https://pyodide.org/en/stable/usage/api/js-api.html#globalThis.loadPyodide
Expand Down
19 changes: 19 additions & 0 deletions packages/pyodide-kernel/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@
scriptLines.push(`await piplite.install('${pkgName}', keep_going=True)`);
}
}
const { extraPackagesAndIndexes } = this._options as IPyodideWorkerKernel.IOptions;
if (extraPackagesAndIndexes.length > 0) {
// note that here pkg can be a package name or a wheel url
for (const { packages: pkgs, indexes } of extraPackagesAndIndexes) {
let installCmd: string;
if (indexes === null) {
installCmd = `await piplite.install(${JSON.stringify(pkgs)}, keep_going=True)`;
} else {
installCmd = `await piplite.install(${JSON.stringify(pkgs)}, index_urls=${JSON.stringify(indexes)}, keep_going=True)`;
}
console.info('installing via cmd:', installCmd);
try {
await this._pyodide.runPythonAsync(installCmd);
console.info(`Packages installed successfully`);

Check failure on line 118 in packages/pyodide-kernel/src/worker.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
} catch (e) {
console.error('Error installing packages', e);
}
}
}

// import the kernel
scriptLines.push('import pyodide_kernel');
Expand Down
Loading