Skip to content
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

__main__.hy doesn't work like __main__.py #1466

Closed
Zirak opened this issue Dec 16, 2017 · 1 comment
Closed

__main__.hy doesn't work like __main__.py #1466

Zirak opened this issue Dec 16, 2017 · 1 comment
Labels

Comments

@Zirak
Copy link

Zirak commented Dec 16, 2017

(All snippets below tested with hy master and python 3.6.3)

When running a directory with a __main__ file, hy fails while python succeeds:

% ls
__main__.hy __main__.py
% python .
hey
% hy .
hy: Can't open file '.': [Errno 21] Is a directory

Same applies to egg files, but that may be its own independent problem.

Passing the -m flag does execute the __main__, unlike python:

% hy -m .
hy
% python -m .
python: Relative module names not supported

Fixing the first block is relatively simple: In cmdline, run_module already does the correct thing when running a directory/file according to the respective function in cpython.

However, making the 2nd block fail is a breaking change, as run_module does not do the same thing as the respective function in cpython (wraps runpy._run_module_as_main)

In the end, the question may be is this worth fixing on a lower level? Does hy want to copy the behaviour of run_file and run_module as implemented in cpython, or is it good enough to be able to run a directory/zip/whatever with a __main__?

@Kodiologist
Copy link
Member

Huh, I didn't even know this Python feature existed. #459 might be related. Thanks for reporting.

@Kodiologist Kodiologist changed the title Running a directory with __main__ from hy cmdline __main__.hy doesn't work like __main__.py Dec 16, 2017
@vodik vodik mentioned this issue Feb 26, 2018
9 tasks
brandonwillard added a commit to brandonwillard/hy that referenced this issue Aug 22, 2018
brandonwillard added a commit to brandonwillard/hy that referenced this issue Aug 24, 2018
brandonwillard added a commit to brandonwillard/hy that referenced this issue Aug 24, 2018
brandonwillard added a commit to brandonwillard/hy that referenced this issue Aug 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants