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

Tolerate failures while accessing wand.api #220

Merged
merged 2 commits into from Nov 16, 2018

Conversation

@musically-ut
Copy link
Contributor

@musically-ut musically-ut commented Mar 4, 2015

While developing an addon for Anki (for which, one needs to bundle all the dependencies), I ran into the problem that if I fetched and kept a checkout of wand in a sub-folder, it failed to import complaining that the key wand.api was not present in sys.modules.

Upon further investigation, it appears that wand._api is only used as a hack to allow wand to work with ReadTheDocs (?). This pull-request presents one way of averting that failure.

It ensures that if wand is bundled as a local package within another package, then importing wand_local_name.wand.api will not balk at not finding the module wand.api.

Feedback, comments and alternate fixes welcome.

This ensures that if wand is bundled as a local package within another
package, then importing wand_local_name.wand.api will not balk at not
finding the module wand.api.
@emcconville
Copy link
Owner

@emcconville emcconville commented Nov 7, 2018

This seems straight forward, but could you provided a little "bundling" example to demonstrate the failure? Nothing fancy -- just terminal log or something that shows module error message.

I've got a feeling that other folks that run into this issue would google-search the error-message, and not your resolution.

@musically-ut
Copy link
Contributor Author

@musically-ut musically-ut commented Nov 16, 2018

If I have checked out the wand module into a local folder named wand_local, then I see the following error while trying to import it (or any other sub-module, e.g. want_local.image):

>>> import wand_local.api as A
-----------------------------------------------------------
KeyError                  Traceback (most recent call last)
<ipython-input-3-003321ba1a6a> in <module>()
----> 1 import wand_local.api as A

~/PATH/wand-test/wand_local/api.py in <module>()
    163
    164
--> 165 sys.modules['wand._api'] = sys.modules['wand.api']
    166

KeyError: 'wand.api'

This is the error which was resolved, as no other part of the code depends on the name of the module being wand. I had kept the name of the folder separate from wand to avoid conflicts with the system installed version of wand, to make testing easier.

PS: I have rebased the PR to the current master.

@emcconville
Copy link
Owner

@emcconville emcconville commented Nov 16, 2018

Awesome. Thanks for the demonstration. I'll include this with the next release.

@emcconville emcconville added this to the 0.5.0 milestone Nov 16, 2018
@@ -126,8 +126,48 @@ def load_library():
raise IOError('cannot find library; tried paths: ' + repr(tried_paths))


This comment has been minimized.

@emcconville

emcconville Nov 16, 2018
Owner

Artifacts left-over from a rebase/conflict-resolution? All of this has been moved to wand.cdefs.structure or wand.cdefs.wandtypes

@emcconville emcconville merged commit 87e0804 into emcconville:master Nov 16, 2018
1 check failed
1 check failed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants