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

Add index_urls option to install() #1146

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion packages/kernel/src/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,15 @@ export class StliteKernel {
});
}

public install(requirements: string[]): Promise<void> {
public install(
requirements: string[],
options?: { indexUrls?: string[] },
): Promise<void> {
return this._asyncPostMessage({
type: "install",
data: {
requirements,
indexUrls: options?.indexUrls,
},
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/kernel/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
data: {
path: string;
data: string | ArrayBufferView;
opts?: Record<string, any>;

Check warning on line 102 in packages/kernel/src/types.ts

View workflow job for this annotation

GitHub Actions / test-kernel

Unexpected any. Specify a different type
};
}
export interface InMessageFileRename extends InMessageBase {
Expand All @@ -119,6 +119,7 @@
type: "install";
data: {
requirements: string[];
indexUrls?: string[];
};
}
export type InMessage =
Expand Down Expand Up @@ -203,7 +204,7 @@
interface ReplyMessageBase {
type: string;
error?: Error;
data?: any;

Check warning on line 207 in packages/kernel/src/types.ts

View workflow job for this annotation

GitHub Actions / test-kernel

Unexpected any. Specify a different type
}
export interface ReplyMessageHttpResponse extends ReplyMessageBase {
type: "http:response";
Expand Down
12 changes: 9 additions & 3 deletions packages/kernel/src/worker-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,20 @@ prepare(main_script_path, args)
break;
}
case "install": {
const { requirements: unvalidatedRequirements } = msg.data;
const { requirements: unvalidatedRequirements, indexUrls = null } =
msg.data;

const micropip = pyodide.pyimport("micropip");

const requirements = validateRequirements(unvalidatedRequirements); // Blocks the not allowed wheel URL schemes.
console.debug("Install the requirements:", requirements);
console.debug("Install the requirements:", requirements, {
indexUrls,
});
await micropip.install
.callKwargs(requirements, { keep_going: true })
.callKwargs(requirements, {
keep_going: true,
index_urls: indexUrls,
})
.then(() => {
console.debug("Successfully installed");
reply({
Expand Down
4 changes: 2 additions & 2 deletions packages/mountable/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function mount(
kernel.dispose();
ReactDOM.unmountComponentAtNode(container);
},
install: (requirements: string[]) => {
return kernelWithToast.install(requirements);
install: (requirements: string[], options?: { indexUrls?: string[] }) => {
return kernelWithToast.install(requirements, options);
},
writeFile: (
path: string,
Expand Down
Loading