Skip to content

pythonnet (clr) hacks the import mechanism in Python - not compatible with Kivy #547

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

Closed
den-run-ai opened this issue Sep 26, 2017 · 1 comment

Comments

@den-run-ai
Copy link
Contributor

https://groups.google.com/forum/#!search/pythonnet%7Csort:date/kivy-users/X0R7FUtysAk/IBKUJuyGBQAJ

The problem was that importing the clr module does modify the import function and this seems to be globally. 

For standard importing (i.e. import xyz  or from xyz imprt abc) this does not cause a problem, but in kivy/factory.py it calls import in a way that is not supported by the overridden import() from the clr implementation.

As a work around I now have factory.py create a reference to the import as self._local_import and then around line 140 in factory.py I replace

     module = import(name=item['module'], fromlist='.')

with

   module = self._local_import(name=item['module'], fromlist='.')

And it appears that as long as factory.py is used at least once before the clr module is imported then things seem to work out.

This seems like a hack and I would prefer to have something local to the clr importing that reverts import to what it was, but my attempts to do so only fixed the import locally to the module that did the importing and not globally like the import clr is doing.

I guess this is more of a python thing but can anyone think of a way to correct this w/o having to modify kivy/factory.py?

@filmor
Copy link
Member

filmor commented Sep 27, 2017

The long-term solution is to rewrite the import mechanism in terms of a meta_path element (https://www.python.org/dev/peps/pep-0302/).

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

No branches or pull requests

2 participants