Giter Club home page Giter Club logo

Comments (8)

daltonmatos avatar daltonmatos commented on August 26, 2024

Could you create a branch or publish this code somewhere? I would like to take a look. Thanks.

from plugnplay.

hugosenari avatar hugosenari commented on August 26, 2024

https://github.com/hugosenari/pig

download pig rename pig/modules/maemo/notify_maemo.NotifyMaemo to pig/modules/maemo/notify.Notify

To run program (require linux)

python pig/__init__.py

This app, isn't done ;)

from plugnplay.

daltonmatos avatar daltonmatos commented on August 26, 2024

Sure I will do! And thanks for using plugnplay in one of your projects!

from plugnplay.

daltonmatos avatar daltonmatos commented on August 26, 2024

The problem here is that the python interpreter does not import two modules of the same name, twice.

My debug session told me that before importing any modules from pig.core.modules.maemo all modules from pig.core.modules are imported. So when comes the time to import pig.core.modules.maemo.notify there is already a notify entry in sys.modules['notify'] and this points to the previuos imported module, see:

ipdb> sys.modules['notify']
<module 'notify' from './pig/modules/notify.py'>

When this code runs:

> /usr/lib/python2.7/site-packages/plugnplay-0.3-py2.7.egg/plugnplay/__init__.py(64)load_plugins()
 63         for mod_name in modules:
---> 64             try:
 65                 imported_module = __import__(mod_name, globals=globals(), \

ipdb> mod_name
'notify'

The value of the imported_module variable does not change, that is, __import__ does not import the notify module (from modules.maemo) again.

Here is the value of the variables at the time of the second import:

ipdb> mod_name
'notify'
ipdb> print d
./pig/modules/maemo
ipdb> print imported_module
<module 'notify' from './pig/modules/notify.py'>
ipdb> 

So even trying to import pig.core.modules.maemo.notify it will not be imported because pig.core.modules.notify already has its place on sys.modules and __import__ knows about this.

In fact, I don't know if there is anything plugnplay can do to fix this, since it depends on the python loader __import__.

from plugnplay.

hugosenari avatar hugosenari commented on August 26, 2024

maybe you can try (I don't know if is possible) import using "as dirName_Module"

Something like this:
https://github.com/hugosenari/plugnplay/commit/78dcd0f448e481def8e6184c38eb1f69a7856d7a

from plugnplay.

daltonmatos avatar daltonmatos commented on August 26, 2024

Yeah! Based on your commit I had an idea. The problem is that plugnplay imports using only the module name, this makes the python interpreter look for an entry in sys.modules with this name. Since the two (or more) modules share the same name, the interpreter does not perform the second import.

The idea is to save the imported module under a unique sys.modules key. For example:

If we need to import pig.core.modules.notify and pig.core.modules.maemo.notify plugnplay will save them on different places inside sys.modules. Currently both are saved on sys.modules['notify'] and that's why the second module is never imported. I will try to chage plugnplay to save these two modules, respectivelly, in sys.modules['pig.core.modules.notify'] and sys.modules['pig.core.modules.maemo.notify'].

I think this will do the trick. Let's see.

from plugnplay.

daltonmatos avatar daltonmatos commented on August 26, 2024

It's done @hugosenari. If you can, please take a look and check if this solves the problems you were having. Thanks.

from plugnplay.

hugosenari avatar hugosenari commented on August 26, 2024

"Worked"

But to me (at windows :( ):

Program send key error when remove _ init _

Solved adding one checker:
if mod_name in sys.modules:
del sys.modules[mod_name]

from plugnplay.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.