hy
hy copied to clipboard
Import from zip files
It would be handy to be able to import .hy files from .zip archives (for those of us who like to deploy stuff in single file bundles).
Right now I'm working around this by doing:
BUNDLE=sushy.zip
clean:
rm *.zip
bundle:
hyc sushy/*.hy
zip -r9 $(BUNDLE) . -i *.py *.pyc
test-bundle:
PYTHONPATH=$(BUNDLE) python -m sushy
Not a bad idea -- we should likely implement this as a second PEP302 loader -- after all, it is what they were designed for :)
bump
I'm also getting trouble with Hy under PyPy. hy -m foo isn't working for some reason, will investigate that on other issues...
@allison-casey What do you think needs to be documented yet? It seems to just plain not work at the moment.
I believe this was documenting that, because Hy is a python dependency you can only make zip apps via shiv
which packages the dependencies with the module unlike Python zipapp
I think that's about the distinct issue #1774. This issue is about import from a ZIP archive, not about self-contained executables. shiv shouldn't be necessary in this case.
ahhh i misread. then we can remove the doc me and leave the feature.
Adapting the example from the documentation of zipimport
:
$ echo '(print "zawinski")' >jwzthreading.hy
$ zip example.zip jwzthreading.hy
adding: jwzthreading.hy (stored 0%)
$ rm jwzthreading.hy
$ unzip -l example.zip
Archive: example.zip
Length Date Time Name
--------- ---------- ----- ----
19 2022-11-05 16:25 jwzthreading.hy
--------- -------
19 1 file
$ python3
Python 3.11.0 (main, Nov 5 2022, 14:58:16) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hy, sys
>>> sys.path.insert(0, 'example.zip')
>>> import jwzthreading
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'jwzthreading'