You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just realized adding a .pth file to site-packages allows execution of arbitrary code (as long as the line starts with import). That could be used to hook up the encoding without requiring the user to do it explicitly (this is impossible with the main file anyway).
Unfortunately this does not work for the current directory, only the system and user site-packages directories.
Instead of directly registering the codec (from the .pth file), it might be possible to set a custom __path__ element in encodings, that should enable autodiscovery.
The text was updated successfully, but these errors were encountered:
Note, I also looked at sitecustomize.py and usercustomize.py, but those only works if you export PYTHONPATH=., i.e. not in the implicit path from the script which is apparently only set later.
Having the encoding available implicitly would be handy, though only if it doesn't significantly slow down the start up of programs that don't use the encoding (i.e., I'd like to import the implementation of the encoding lazily).
I wonder what the best practice for doing this would be? At least we can document how to do this manually. Or maybe we could have a separate package for the codec that would do this automatically.
I just realized adding a
.pth
file to site-packages allows execution of arbitrary code (as long as the line starts withimport
). That could be used to hook up the encoding without requiring the user to do it explicitly (this is impossible with the main file anyway).Unfortunately this does not work for the current directory, only the system and user site-packages directories.
Instead of directly registering the codec (from the
.pth
file), it might be possible to set a custom__path__
element inencodings
, that should enable autodiscovery.The text was updated successfully, but these errors were encountered: