-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
fix: use alternate scheme for importing multipart #168
Conversation
Signed-off-by: Henry Schreiner <[email protected]>
@defnull you good with the last point on the cons? |
I have no plans to turn |
A quick test looks promising: $ python3 -mvenv venv
$ venv/bin/pip install git+https://github.com/henryiii/python-multipart.git@henryiii/fix/importer
[...] Successfully installed python-multipart-0.0.13
$ venv/bin/python -c "import multipart; print(multipart.__file__)"
<string>:1: FutureWarning: Please use `import python_multipart` instead.
/home/.../venv/lib/python3.12/site-packages/multipart/__init__.py
$ venv/bin/python -c "import python_multipart as multipart; print(multipart.__file__)"
/home/.../venv/lib/python3.12/site-packages/python_multipart/__init__.py
$ venv/bin/pip install multipart
[...] Successfully installed multipart-1.1.0
$ venv/bin/python -c "import python_multipart as multipart; print(multipart.__file__)"
/home/.../venv/lib/python3.12/site-packages/python_multipart/__init__.py
$ venv/bin/python -c "import multipart; print(multipart.__file__)"
/home/.../venv/lib/python3.12/site-packages/multipart.py |
I'll get a release with this when I have time. |
Is this rework needed? The original problem came from installing a new module and trying to import it in the same process without invalidating importlib caches |
Colab users don't know they need to invalidate importlib caches, and the help in colab doesn't tell them they need to. And invalidating the import caches doesn't work, since the problem is the !pip install python-multipart==0.0.13
import multipart The FWIW, this works, because it does exactly what the !pip install python-multipart==0.0.13
import _python_multipart_loader
import multipart But no one would know to do that. |
If you restart the session, Colab does keep the environment so it works the second time. Also, this works: !pip install python-multipart==0.0.13
import site
site.main()
import multipart But again, no one would know they need to do that. |
Thanks. Let's try this. |
I am using |
Yeah... I also can't import... 🤔 |
The build artefacts uploaded to pypi do not contain the second package for some reason. Installing directly from git also does not work, but installing from |
I'm yanking python-multipart 0.0.14 and Starlette 0.41.1. |
Ahh, found the issue. Installing from source (via |
Ah, forgot to rerun |
This is an alternate attempt at #166 that allows a user to install the package and import it in a single Python process (not recommended, but Google Colab basically requires this to install anything).
This has the following pro's:
.pth
file, meaning it can be hot swapped.pth
and custom loader that the original attempt did, but Google Colab users don't do editable installs!)import multipart
if multipart is not installed.And the following con's:
multipart
, specifically requiring that package not be moved to a module structure while this workaround is in place.I also added a wrapper script for nox like the other scripts in
/scripts
.