Skip to content

Conversation

ecerulm
Copy link
Member

@ecerulm ecerulm commented Feb 1, 2024

This adds a nox session called pyodineconsole.

nox -rs pyodineconsole
nox > Running session pyodineconsole
nox > Re-using existing virtual environment at .nox/pyodineconsole.
nox > python -m pip install build
nox > python -m build
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling>=1.6.0,<2)
* Getting build dependencies for sdist...
* Building sdist...
* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling>=1.6.0,<2)
* Getting build dependencies for wheel...
* Building wheel...
Successfully built urllib3-2.2.0.tar.gz and urllib3-2.2.0-py3-none-any.whl
nox > cp templates/pyodide-console.html dist/index.html
nox > cd dist
nox > python -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...

This nox session

  • builds the wheel for urllib into dist/
  • creates a index.html file in dist/, with a pyodine terminal taken
    from pyodine src/templates/console.html
  • autoruns a series of commands on this terminal
    • import micropip
    • await micropip.install("http://localhost:8000/urllib3-2.2.0-py3-none-any.whl")
    • import urllib3
    • urllib3.__version__

Then you open http://localhost:8000 and you will be presented with

image

Closes #3330

@ecerulm ecerulm added the Skip Changelog Pull requests that don't require a changelog entry label Feb 1, 2024
@ecerulm
Copy link
Member Author

ecerulm commented Feb 1, 2024

@sethmlarson , please try this pyodide console approach and tell me if that's what you were looking for when you wrote #3330

@ecerulm ecerulm marked this pull request as ready for review February 5, 2024 10:04
@ecerulm ecerulm requested a review from pquentin February 5, 2024 10:04
Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

Thanks for opening this! I put some early comments below:

noxfile.py Outdated
@@ -200,6 +200,18 @@ def lint(session: nox.Session) -> None:
mypy(session)


@nox.session(python="3.11")
def pyodineconsole(session: nox.Session) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

typo: pyodide*

@@ -200,6 +200,18 @@ def lint(session: nox.Session) -> None:
mypy(session)


@nox.session(python="3.11")
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be a specific Python version, or can we use any 3.x?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we don't specify a version then nox will run the same python interpreter used to run nox itself.

I mean, the alternative skip nox (which is for test automation, not for this).

I can create a python script to create virtualenv , install dependencies, etc instead. then we are not bound by the nox rules.

@@ -0,0 +1,267 @@
<!doctype html>
Copy link
Member

Choose a reason for hiding this comment

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

Can we find a new home for this file? Maybe under test/ for Emscripten?

Did you write this file yourself or is it from somewhere, I don't see license information.

What is the expected maintenance requirements for this file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we find a new home for this file? Maybe under test/ for Emscripten?

Sure, I can do that.

Did you write this file yourself or is it from somewhere, I don't see license information.

I mentioned in the PR description

creates a index.html file in dist/, with a pyodine terminal taken
from pyodide src/templates/console.html

The LICENSE is https://github.com/pyodide/pyodide/blob/main/LICENSE. (Mozilla Public License Version 2.0)

I can add a comment on the top of the file with the original source url, not sure , should I add a "copyright" comment although the original does not have it? The closest copyright notice that I can find in their repo is "2019-2022, Pyodide contributors and Mozilla", I can add that?

What is the expected maintenance requirements for this file?

I guess we won't maintain this file. It's the same jQuery REPL that is used in https://pyodide.org/en/stable/console.html, if it stops working we can always copy the latest from pyodide src/templates/console.html. And then add the lines

        await term.ready;
        await term.exec("import micropip\n");
        await term.exec("micropip.list()\n");
        await term.exec('await micropip.install("http://localhost:8000/urllib3-2.2.0-py3-none-any.whl")')
        await term.exec("micropip.list()");
        await term.exec("import urllib3");
        await term.exec("urllib3.__version__");

Copy link
Member

Choose a reason for hiding this comment

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

Thank you, apologies for not reading the description closely enough

Comment on lines 256 to 262
await term.ready;
await term.exec("import micropip\n");
await term.exec("micropip.list()\n");
await term.exec('await micropip.install("http://localhost:8000/urllib3-2.2.0-py3-none-any.whl")')
await term.exec("micropip.list()");
await term.exec("import urllib3");
await term.exec("urllib3.__version__");
Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines +1 to +4
<!-- taken from https://github.com/pyodide/pyodide/blob/main/src/templates/console.html -->
<!-- Copyright (C) 2019-2022, Pyodide contributors and Mozilla -->
<!-- SPDX-FileCopyrightText: 2019-2022, Pyodide contributors and Mozilla -->
<!-- SPDX-License-Identifier: MPL-2.0 -->
Copy link
Member Author

Choose a reason for hiding this comment

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

@sethmlarson , I added mention of the source, copyright and license here.

Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

This is awesome and perfectly recreates the issue w/ InsecureRequestWarning, thank you @ecerulm!

@sethmlarson sethmlarson merged commit 9929d3c into urllib3:main Feb 5, 2024
@sethmlarson
Copy link
Member

@ecerulm The linked issue was a bounty issue for $100, so if you're able to please submit an expense to our Open Collective linking back to this PR.

@ecerulm ecerulm deleted the pyodine_console branch February 5, 2024 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog Pull requests that don't require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a workflow (nox?) for testing Emscripten support locally
2 participants