-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hy will treat a Hy file as Python if it doesn't have a ".hy" file extension #1677
Comments
Ah, yes, all the Hy-specific loader logic from #1672 is based on file extensions and falls back to Python builtins otherwise. In other words, it only enforces a choice between files recognized as Hy and Python. Do we want to assume that extension-less files and/or unrecognized extensions are Hy? Should we raise an exception (from the cmdline tool) when we don't find/recognize an extension? Should we fail silently in those cases? We can make some fairly straightforward changes to produce most of those conditions, but we probably want to be more laissez-faire than not. Python's choice to interpret every file as Python source seems sorta reasonable if only because it handles the entire import process — in which we are simply injecting Hy parsing capabilities. If we attempt to take over default behaviours, we might need to do a lot more just to preserve expected functionality elsewhere (e.g. make sure we don't block other |
I think anything passed via the command line should be automatically assumed to be a Hy module. Other than that, the import rules could probably stay intact. |
Yeah, I think it's reasonable to expect a |
We also presumably want shebang lines to work:
|
@kirbyfan64, that's the approach I was initially leaning toward, and it would require us to either stop using @Kodiologist, handling a shebang is much more in-line with the approach I'm currently leaning toward, which attempts to determine whether or not a file is Hy source through extension and (simple) non-extension means. Such a change could be introduced in the way described above, or more generally through changes to the importer/finder. Since we implement the Python 2.7 importer/finder, it's clear where/how we should do this, but, with our minimally-invasive Python 3.x patch, we might need to do some research if a simple change to this line in Also, it's quite possible I'm over-thinking this, and that simply changing the extension conditions in the 2.7 loader, importer/finder and 3.x loader patch will work just fine. Still, I think it's safer to define a clear and constrained — albeit potentially non-standard (e.g. exclusively extension, shebang, and perhaps light syntax inference) — means of determining when a file is Hy source. |
Well IMO if someone's using Hy to run a non-Hy file, they're doing something very wrong... |
Even so, we don't want to break valid Hy code that triggers imports or |
We should probably avoid trying to interpret shebang lines (that's the shell's job) or detect Hy syntax. I think that |
All right, I'll start a PR for changes to that effect. |
Adds a Hy-parsing fallback to `runpy`, for files with unrecognized source extensions. Closes hylang#1677.
This change a Hy-preferring `runhy` that is used by cmdline Hy. Standard `runpy` is still patched so that it can run `.hy` files, but the default behaviour for unknown filetypes is preserved (i.e. assume they are Python source). Closes hylang#1677.
@brandonwillard, you might want to take a look at this one.
The text was updated successfully, but these errors were encountered: