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

Dev/remove http patch #689

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./requirements";
export * from "./requirements-txt";
export * from "./promise-delegate";
4 changes: 4 additions & 0 deletions packages/common/src/requirements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// stlite-specific requirements
export const STLITE_REQUIREMENTS = [
"urllib3==2.2.0", // `urllib3` supports Pyodide since 2.2.0. https://urllib3.readthedocs.io/en/stable/reference/contrib/emscripten.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we do >=2.2.0 here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops correct!

];
7 changes: 5 additions & 2 deletions packages/desktop/bin/dump_artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type PyodideInterface,
version as pyodideVersion,
} from "pyodide";
import { parseRequirementsTxt } from "@stlite/common";
import { parseRequirementsTxt, STLITE_REQUIREMENTS } from "@stlite/common";
import type { DesktopAppManifest } from "../electron/main";

// @ts-ignore
Expand Down Expand Up @@ -132,7 +132,10 @@ async function installPackages(
await pyodide.loadPackage(["micropip"]);
const micropip = pyodide.pyimport("micropip");

const requirements: string[] = [...options.requirements];
const requirements: string[] = [
...options.requirements,
...STLITE_REQUIREMENTS,
];
if (options.useLocalKernelWheels) {
const stliteKernelDir = path.dirname(require.resolve("@stlite/kernel")); // -> /path/to/kernel/dist
const stliteKernelPyDir = path.resolve(stliteKernelDir, "../py"); // -> /path/to/kernel/py
Expand Down
11 changes: 0 additions & 11 deletions packages/kernel/py/stlite-server/stlite_server/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@ def _import_pyarrow_interchange():
logger.error("Failed to fix Altair", exc_info=e)


def _fix_requests():
try:
import pyodide_http # type: ignore[import]

pyodide_http.patch_all() # Patch all libraries
except ImportError:
# pyodide_http is not installed. No need to do anything.
pass


def prepare(
main_script_path: str,
args: List[str],
Expand All @@ -166,7 +156,6 @@ def prepare(
_fix_sys_path(main_script_path)
_fix_matplotlib_crash()
_fix_altair()
_fix_requests()
_fix_sys_argv(main_script_path, args)
_fix_pydeck_mapbox_api_warning()
_install_pages_watcher(main_script_path)
9 changes: 7 additions & 2 deletions packages/kernel/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Pyodide from "pyodide";
import { PromiseDelegate } from "@stlite/common";
import { PromiseDelegate, STLITE_REQUIREMENTS } from "@stlite/common";
import { writeFileWithParents, renameWithParents } from "./file";
import { verifyRequirements } from "./requirements";
import { mockPyArrow } from "./mock";
Expand All @@ -12,7 +12,7 @@

let pyodide: Pyodide.PyodideInterface;

let httpServer: any;

Check warning on line 15 in packages/kernel/src/worker.ts

View workflow job for this annotation

GitHub Actions / test-kernel

Unexpected any. Specify a different type

interface StliteWorkerContext extends DedicatedWorkerGlobalScope {
postMessage(message: OutMessage, transfer: Transferable[]): void;
Expand Down Expand Up @@ -50,7 +50,7 @@
loadPyodide = pyodideModule.loadPyodide;
} else {
importScripts(pyodideUrl);
loadPyodide = (self as any).loadPyodide;

Check warning on line 53 in packages/kernel/src/worker.ts

View workflow job for this annotation

GitHub Actions / test-kernel

Unexpected any. Specify a different type
}
return loadPyodide({ ...loadPyodideOptions, indexURL: indexUrl });
}
Expand Down Expand Up @@ -180,7 +180,12 @@
requirements
);
await micropip.install.callKwargs(
[wheels.stliteServer, wheels.streamlit, ...requirements],
[
wheels.stliteServer,
wheels.streamlit,
...requirements,
...STLITE_REQUIREMENTS,
],
{ keep_going: true }
);
console.debug("Installed the wheels and the requirements");
Expand Down Expand Up @@ -356,7 +361,7 @@

httpServer.start_websocket(
path,
(messageProxy: any, binary: boolean) => {

Check warning on line 364 in packages/kernel/src/worker.ts

View workflow job for this annotation

GitHub Actions / test-kernel

Unexpected any. Specify a different type
// XXX: Now there is no session mechanism

if (binary) {
Expand Down Expand Up @@ -402,7 +407,7 @@

const { request } = msg.data;

const onResponse = (statusCode: number, _headers: any, _body: any) => {

Check warning on line 410 in packages/kernel/src/worker.ts

View workflow job for this annotation

GitHub Actions / test-kernel

Unexpected any. Specify a different type

Check warning on line 410 in packages/kernel/src/worker.ts

View workflow job for this annotation

GitHub Actions / test-kernel

Unexpected any. Specify a different type
const headers = _headers.toJs();
const body = _body.toJs();
console.debug({ statusCode, headers, body });
Expand Down
2 changes: 1 addition & 1 deletion streamlit
Submodule streamlit updated 1 files
+1 −1 lib/setup.py
Loading