Replies: 2 comments 2 replies
-
I converted this issue to a discussion because it doesn't appear to be a bug report or feature request. What are you trying to accomplish here? Your example of how to load a Python module from a string seems like a very elaborate way to get what will ultimately be pretty similar to a SimpleNamespace. Unless your actual need is very arcane, there's probably a simple way to fulfill it in Hy, too. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First, a bare-bones example from regular Python. Given a very simple Python program,
…, we load this if it is in a file named
hello.py
by,…, or we can feed it as a string to
importlib
and load the result withexec
:I am not terribly familiar with Python, so afaik
exec' accepts both a GLOBALS and LOCALS dict, so I wonder, might there any significance to doing the above with
exec(module_source, None, module.dict)or would that not make sense? Would
globals()[module_name] = module` need to be changed? Anyway, that was but an aside; the actual problem comes next.Given a very simple Hy program,
…, we load this if it is in a file named
hello.hy
by,…, however, there is no obvious way to infer how to modify
importlib.util.spec_from_loader
'sloader
parameter to tellimportlib
that the provided source code should use something likehy/importer.py
's modification ofimportlib.machinery.SOURCE_SUFFIXES.insert(0, ".hy")
or the like.Beta Was this translation helpful? Give feedback.
All reactions