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

Cleanup sys.modules after a Hy specific import failure. #1524

Closed
wants to merge 1 commit into from
Closed

Cleanup sys.modules after a Hy specific import failure. #1524

wants to merge 1 commit into from

Conversation

etanol
Copy link
Contributor

@etanol etanol commented Mar 6, 2018

When there is a HyTypeError or a LexException, the None placeholder inserted in
sys.modules is not removed. This prevents future import attempts because the
Python import machinery finds the None reference during the "fast path" of the
default importer.

This fixes #1523.

When there is a HyTypeError or a LexException, the None placeholder inserted in
sys.modules is not removed.  This prevents future import attempts because the
Python import machinery finds the None reference during the "fast path" of the
default importer.

This fixes #1523.
@Kodiologist
Copy link
Member

This is cool, but seems likely to conflict with #1518.

Does this help with #712?

Is there any reason the test uses f.close instead of a with block?

@etanol
Copy link
Contributor Author

etanol commented Mar 6, 2018

This is cool, but seems likely to conflict with #1518.

How far from completion is that?

Does this help with #712?

Not really.

Is there any reason the test uses f.close instead of a with block?

No reason, I just forgot about it. I'll change that.

@Kodiologist
Copy link
Member

This is cool, but seems likely to conflict with #1518.

How far from completion is that?

@vodik?

@vodik
Copy link
Contributor

vodik commented Mar 6, 2018

Close. The hard parts are done, the branch works. I just need to revert some of my experiments (patching run_path to support Hy might not have been the best idea), and write some documentation on it.

But I got a busy week ahead of me with renovations, so I'll probably not have too much programming time. I'd have no problem merging this in the meanwhile. No point making this painful when the fix is just a few lines.

And on that note, if you guys decide to merge this in the interim, have a look at #1513 as well, @etanol, and add that to this PR. Might as well work around two issues at once.

"Test that a failed import does not prevents from re trying"
module_name = "again"

f = open("again.hy", "wb")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kodiologist what would you think about starting to use the pytester plugin for this kind of stuff? Comes stock with pytest for this kind of stuff, just needs to be turned on:

def test_import_failure_retryable(testdir):
    testdir.makefile("hy", again="""(import sys)""")
    testdir.syspathinsert()  # magically cleans up post test too

    import again

Keeps current working directory clean and makes sure everything is fresh each pytest run. I suspect stale .pyc files could cause a false pass here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with using pytest plugins, sure; just make sure everything works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, in which case pytest_plugins = "pytester" needs to go in our conftest.py and its loaded.

f.write(b'(import "sys")')
f.flush()

assert _import_test() == "Failed"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to do:

with pytest.raises(HyTypeError):
    import again

# ...

import again

@etanol
Copy link
Contributor Author

etanol commented Mar 21, 2018

Dropping in favor of #1518

@etanol etanol closed this Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import failures prevent from re-trying
3 participants