gargoyle icon indicating copy to clipboard operation
gargoyle copied to clipboard

Condition rename: myapp/gargoyle.py shadows gargoyle package

Open winhamwr opened this issue 14 years ago • 5 comments

With the current setup of using a myapp/gargoyle.py file for adding custom ConditionSet objects, I'm running in to an import problem. Since the file and the package are both named gargoyle, one of them shadows the other, and in this case, from myapp/gargoyle.py "import gargoyle" actually seems to be importing myapp.gargoyle. This obviously causes problems.

I'm not sure if this is something specific to the way I have my path configured. Either way, changing the file name from gargoyle.py to gargoyle_conditions.py eliminates the issue.

winhamwr avatar Jan 19 '11 21:01 winhamwr

I haven't decided on whether I like the idea of renaming the module yet. I'm also 5 months behind on dealing with this issue :)

Are there any objections to just requiring absolute imports?

dcramer avatar Jun 17 '11 05:06 dcramer

The following code in myapp/gargoyle.py:

from gargoyle import gargoyle
from gargoyle.conditions import ModelConditionSet
from auth.models import User

class ImpersonationConditionSet(ModelConditionSet):
    pass

gargoyle.register(ImpersonationConditionSet(User))

causes ImportError at /nexus/gargoyle/ cannot import name gargoyle

DCramer, can you indicate what my imports should be?

jakul avatar Jun 29 '11 14:06 jakul

Just preface your file with:

from __future__ import absolute_import

dcramer avatar Jun 30 '11 12:06 dcramer

This has worked for me

jakul avatar Jul 04 '11 13:07 jakul

This still causes import errors when you want to import things from gargoyle proper from other modules inside this app.

Example: #Inside models.py from gargoyle.models import Switch #This raises an ImportError

bjinwright avatar Apr 23 '12 19:04 bjinwright