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
For Python packages with hy modules, users have to know whether the module is .py or .hy when using Python's module-as-script feature.
If package/module.py:
python -m package.module
If package/module.hy:
hy -m package.module
Can hy support python -m package.module regardless of .py or .hy? In Python 3, it could.
$ mkdir foo
$ echo 'import hy' > foo/__init__.py
$ touch foo/bar.hy
$ cat > foo/bar.hy
(defmain [prog &rest args]
(print "Hello, world!"))
$ hy -m foo.bar
Hello, world!
$ python -m foo.bar
Traceback (most recent call last):
File ".../lib/python3.5/runpy.py", line 151, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name)
File ".../lib/python3.5/runpy.py", line 126, in _get_module_details
code = loader.get_code(mod_name)
AttributeError: 'MetaLoader' object has no attribute 'get_code'
Python 2.7 does not even try to load it:
$ python -m foo.bar
.../bin/python: No module named foo.bar
This patch against hy/importer.py fixes it on Python 3 (whereas there's no change on Python 2):
--- a/hy/importer.py+++ b/hy/importer.py@@ -202,6 +202,10 @@ class MetaLoader(object):
sys.modules[fullname] = mod
return mod
+ def get_code(self, fullname):+ _ast = import_file_to_ast(self.path, fullname)+ return ast_compile(_ast, self.path, "exec")+
$ python -m foo.bar
Hello, world!
I'm creating this issue in case others run into it. We can either close it if there's no interest in supporting this or fix it for Python 3.x, in which case I can create a pull request.
The text was updated successfully, but these errors were encountered:
This actually can't be made to work in general. The strategy described above, where you have an __init__.py or some other Python code (even an empty Python file) as an entry point, now works, and is probably the smartest thing to do. But in the general case of pure Hy code, none of which has been byte-compiled yet, python3 -m foo.bar gives us no chance to run our own code to convince the importer to import Hy files.
For Python packages with hy modules, users have to know whether the module is .py or .hy when using Python's module-as-script feature.
If
package/module.py
:If
package/module.hy
:Can hy support
python -m package.module
regardless of .py or .hy? In Python 3, it could.Python 2.7 does not even try to load it:
This patch against
hy/importer.py
fixes it on Python 3 (whereas there's no change on Python 2):I'm creating this issue in case others run into it. We can either close it if there's no interest in supporting this or fix it for Python 3.x, in which case I can create a pull request.
The text was updated successfully, but these errors were encountered: