gargoyle
gargoyle copied to clipboard
Condition rename: myapp/gargoyle.py shadows gargoyle package
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.
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?
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?
Just preface your file with:
from __future__ import absolute_import
This has worked for me
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