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

PyOdide test failure #2351

Closed
simonw opened this issue Jun 11, 2024 · 7 comments
Closed

PyOdide test failure #2351

simonw opened this issue Jun 11, 2024 · 7 comments

Comments

@simonw
Copy link
Owner

simonw commented Jun 11, 2024

https://github.com/simonw/datasette/actions/runs/9469427870/job/26088069712

CleanShot 2024-06-11 at 09 39 03@2x

    from typing_extensions import deprecated  # noqa
ImportError: cannot import name 'deprecated' from 'typing_extensions' (/lib/python3.10/site-packages/typing_extensions.py)
@simonw
Copy link
Owner Author

simonw commented Jun 11, 2024

Full stacktrace:

Error: Page.evaluate: PythonError: Traceback (most recent call last):
  File "/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception
  File "/lib/python3.10/asyncio/tasks.py", line 232, in __step
    result = coro.send(None)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 500, in eval_code_async
    await CodeRunner(
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 353, in run_async
    await coroutine
  File "<exec>", line 8, in <module>
  File "/lib/python3.10/site-packages/datasette/app.py", line 39, in <module>
    from .views.base import ureg
  File "/lib/python3.10/site-packages/datasette/views/base.py", line 11, in <module>
    import pint
  File "/lib/python3.10/site-packages/pint/__init__.py", line 18, in <module>
    from .delegates.formatter._format_helpers import formatter
  File "/lib/python3.10/site-packages/pint/delegates/__init__.py", line 12, in <module>
    from . import txt_defparser
  File "/lib/python3.10/site-packages/pint/delegates/txt_defparser/__init__.py", line 12, in <module>
    from .defparser import DefParser
  File "/lib/python3.10/site-packages/pint/delegates/txt_defparser/defparser.py", line 9, in <module>
    from ..base_defparser import ParserConfig
  File "/lib/python3.10/site-packages/pint/delegates/base_defparser.py", line 24, in <module>
    from pint.facets.plain.definitions import NotNumeric
  File "/lib/python3.10/site-packages/pint/facets/__init__.py", line 72, in <module>
    from .context import ContextRegistry, GenericContextRegistry
  File "/lib/python3.10/site-packages/pint/facets/context/__init__.py", line 14, in <module>
    from .definitions import ContextDefinition
  File "/lib/python3.10/site-packages/pint/facets/context/definitions.py", line 19, in <module>
    from ..plain import UnitDefinition
  File "/lib/python3.10/site-packages/pint/facets/plain/__init__.py", line 13, in <module>
    from .definitions import (
  File "/lib/python3.10/site-packages/pint/facets/plain/definitions.py", line 19, in <module>
    from ..._typing import Magnitude
  File "/lib/python3.10/site-packages/pint/_typing.py", line 8, in <module>
    from .compat import Never, TypeAlias
  File "/lib/python3.10/site-packages/pint/compat.py", line 46, in <module>
    from typing_extensions import deprecated  # noqa
ImportError: cannot import name 'deprecated' from 'typing_extensions' (/lib/python3.10/site-packages/typing_extensions.py)

@simonw
Copy link
Owner Author

simonw commented Jun 11, 2024

Here's the PyOdide test runner: https://github.com/simonw/datasette/blob/main/.github/workflows/test-pyodide.yml

Attempting to replicate in https://pyodide.org/en/stable/console.html failed:

Welcome to the Pyodide 0.26.1 terminal emulator 🐍
Python 3.12.1 (main, Jun  7 2024 22:40:30) on WebAssembly/Emscripten
Type "help", "copyright", "credits" or "license" for more information.
>>> import micropip
>>> await micropip.install("Pint")
>>> import pint
>>> 

I was hoping it would raise the same error.

@simonw
Copy link
Owner Author

simonw commented Jun 11, 2024

This is the actual test code:

shot-scraper javascript http://localhost:8529/ "
async () => {
let pyodide = await loadPyodide();
await pyodide.loadPackage(['micropip', 'ssl', 'setuptools']);
let output = await pyodide.runPythonAsync(\`
import micropip
await micropip.install('h11==0.12.0')
await micropip.install('httpx==0.23')
await micropip.install('http://localhost:8529/$wheel')
import ssl
import setuptools
from datasette.app import Datasette
ds = Datasette(memory=True, settings={'num_sql_threads': 0})
(await ds.client.get('/_memory.json?sql=select+55+as+itworks&_shape=array')).text
\`);
if (JSON.parse(output)[0].itworks != 55) {
throw 'Got ' + output + ', expected itworks: 55';
}
return 'Test passed!';
}
"

@simonw
Copy link
Owner Author

simonw commented Jun 11, 2024

Running this runs tests locally:

./test-in-pyodide-with-shot-scraper.sh 

Got a surprising different error:

::1 - - [11/Jun/2024 09:43:46] "GET / HTTP/1.1" 200 -
Error: PythonError: Traceback (most recent call last):
  File "/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception
  File "/lib/python3.10/asyncio/tasks.py", line 232, in __step
    result = coro.send(None)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 500, in eval_code_async
    await CodeRunner(
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 237, in __init__
    self.ast = next(self._gen)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 141, in _parse_and_compile_gen
    mod = compile(source, filename, mode, flags | ast.PyCF_ONLY_AST)
  File "<exec>", line 2
    import micropip
IndentationError: unexpected indent

@simonw
Copy link
Owner Author

simonw commented Jun 11, 2024

That error was fixed by doing this:

wheel=$(basename $(ls dist/*.whl) | head -n 1)

@simonw
Copy link
Owner Author

simonw commented Jun 11, 2024

... and now I can replicate that CI bug locally.

simonw added a commit that referenced this issue Jun 11, 2024
@simonw
Copy link
Owner Author

simonw commented Jun 11, 2024

Fix was to force it to install a modern version of typing-extensions:

# To avoid 'from typing_extensions import deprecated' error:
await micropip.install('typing-extensions>=4.12.2')

@simonw simonw closed this as completed Jun 11, 2024
simonw added a commit to simonw/datasette-lite that referenced this issue Jun 11, 2024
simonw added a commit that referenced this issue Jun 12, 2024
@simonw simonw mentioned this issue Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant