hy icon indicating copy to clipboard operation
hy copied to clipboard

Import from zip files

Open rcarmo opened this issue 9 years ago • 6 comments

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

rcarmo avatar Sep 17 '14 09:09 rcarmo

Not a bad idea -- we should likely implement this as a second PEP302 loader -- after all, it is what they were designed for :)

paultag avatar Oct 06 '14 04:10 paultag

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...

rcarmo avatar Jun 29 '15 10:06 rcarmo

@allison-casey What do you think needs to be documented yet? It seems to just plain not work at the moment.

Kodiologist avatar Apr 18 '22 20:04 Kodiologist

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

allison-casey avatar Apr 19 '22 03:04 allison-casey

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.

Kodiologist avatar Apr 19 '22 14:04 Kodiologist

ahhh i misread. then we can remove the doc me and leave the feature.

allison-casey avatar Apr 19 '22 16:04 allison-casey

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'

Kodiologist avatar Nov 05 '22 20:11 Kodiologist