disqus / gargoyle

Feature switches in Django
http://engineering.disqus.com
Apache License 2.0
748 stars 112 forks source link

Condition rename: myapp/gargoyle.py shadows gargoyle package #3

Open winhamwr opened 13 years ago

winhamwr commented 13 years ago

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.

dcramer commented 13 years ago

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?

jakul commented 13 years ago

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?

dcramer commented 13 years ago

Just preface your file with:

from __future__ import absolute_import

jakul commented 13 years ago

This has worked for me

bjinwright commented 12 years ago

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