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

If a requirements.txt is found, only inspect those packages for dependencies #17

Open
schloerke opened this issue Oct 9, 2023 · 1 comment
Assignees

Comments

@schloerke
Copy link
Collaborator

Request:

Hmm, shinylive appears to scan every .py file in the directory to figure out what pyodide needs to install, even scripts that aren't used at runtime. Like sometimes I'll have a helper script that builds a database (in this case, using sqlalchemy) but the actual shiny app only needs built-in sqlite3.

I hacked around this by making a stripped-down branch and exporting that, but it could be nice if either the build process honored requirements.txt (in a minimalistic sense) or if somehow it only scanned app.py and what it imports? or some other solution to ignore certain files when figuring this out.

My reply:

... correct. py-shinylive currently scans every that app.json provides. (Which is every file.) Link

It seems fair to me that if a requirements.txt is found, then only those packages are inspected.

@coatless
Copy link

For anyone else who stumbles upon this, the easiest way to sidestep having shinylive attempt to load packages in a requirements.txt is to rename the file to either requirements-dev.txt or another name. You can see an example app using requirements-dev.txt working.

Screenshot showing an example of a shinylive app working by renaming the `requirements.txt` file to `requirements-dev.txt`

Alternatively, feel free to check out a demo app using requirements.txt instead of requirements-dev.txt failing if just shinylive is present due its dependency on the lzstring package, which lacks a Pyodide-compiled Python package wheel available.

ValueError: Can't find a pure Python 3 wheel for 'lzstring>=1.0.4'.
Traceback (most recent call last):
  File "<exec>", line 368, in _start_app
  File "<exec>", line 302, in _install_requirements_from_dir
  File "/lib/python3.10/site-packages/micropip/_micropip.py", line 573, in install
    await transaction.gather_requirements(requirements)
  File "/lib/python3.10/site-packages/micropip/_micropip.py", line 333, in gather_requirements
    await gather(*requirement_promises)
  File "/lib/python3.10/asyncio/futures.py", line 284, in __await__
    yield self  # This tells Task to wait for completion.
  File "/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup
    future.result()
  File "/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception
  File "/lib/python3.10/asyncio/tasks.py", line 234, in __step
    result = coro.throw(exc)
  File "/lib/python3.10/site-packages/micropip/_micropip.py", line 340, in add_requirement
    return await self.add_requirement_inner(Requirement(req))
  File "/lib/python3.10/site-packages/micropip/_micropip.py", line 448, in add_requirement_inner
    await self.add_wheel(wheel, req.extras)
  File "/lib/python3.10/site-packages/micropip/_micropip.py", line 463, in add_wheel
    await self.gather_requirements(wheel.requires(extras))
  File "/lib/python3.10/site-packages/micropip/_micropip.py", line 333, in gather_requirements
    await gather(*requirement_promises)
  File "/lib/python3.10/asyncio/futures.py", line 284, in __await__
    yield self  # This tells Task to wait for completion.
  File "/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup
    future.result()
  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/micropip/_micropip.py", line 337, in add_requirement
    return await self.add_requirement_inner(req)
  File "/lib/python3.10/site-packages/micropip/_micropip.py", line 435, in add_requirement_inner
    wheel = find_wheel(metadata, req)
  File "/lib/python3.10/site-packages/micropip/_micropip.py", line 303, in find_wheel
    raise ValueError(
ValueError: Can't find a pure Python 3 wheel for 'lzstring>=1.0.4'.
See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel
You can use `micropip.install(..., keep_going=True)`to get a list of all packages with missing wheels.
Screenshot showing an example of a shinylive app failing with a `requirements.txt` file that includes the `shinylive` package itself!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants