Re: Django app and a submodule name conflict

2014-06-06 Thread Vahe Evoyan
Thanks Tom,

Did something similar: added app/ directory as a module, so now all my 
imports look like app.A.

On Thursday, June 5, 2014 5:12:53 PM UTC+4, Tom Evans wrote:
>
> On Wed, Jun 4, 2014 at 8:51 AM, Vahe Evoyan  > wrote: 
> > I have modules in the project with the same names, all placed in 
> different 
> > applications. 
> > 
> > Particularly there are two apps that conflict and result an ImportError. 
> The 
> > project structure approximately is as follows. 
> > 
> > project 
> >  |_ project 
> >|_ settings.py 
> >|_ ... 
> >  |_ apps 
> >|_ A 
> >  |_ handlers 
> >|_ B.py 
> >|_ C.py 
> >|_ B 
> >  |_ models.py 
> > 
> > The settings file adds apps directory to the system path. 
> > 
> > BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 
> > sys.path.insert(0, os.path.join(BASE_DIR, "apps")) 
> > 
> > This configuration assumes that when I import the B.models it will use 
> > apps/B/models.py. Although the following line in the C.py file raise an 
> > import error as it imports the A/handlers/B.pywhich does not have models 
> > module. 
> > 
> > A/handlers/C.py: 
> > from B.models import BModel 
> > 
> > The sys.path variable has a correct items, i.e. the first one in the 
> list is 
> > /path/to/project/appsand sys.modules['B.models'] is referenced to the 
> > correct file. 
> > 
> > BTW, when I use Django's import_by_path function, everything works fine. 
> > 
> > Any ideas how I can solve the problem without renaming the modules? 
> > 
> > Posted sample sources on GitHub. 
> > 
> > Thanks in advance! 
> > 
>
> The simplest solution is to simply rename either app or component that 
> conflicts. 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab6d0baf-1a1e-45e3-ad22-aa5d9f5e8424%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django app and a submodule name conflict

2014-06-05 Thread Tom Evans
On Wed, Jun 4, 2014 at 8:51 AM, Vahe Evoyan  wrote:
> I have modules in the project with the same names, all placed in different
> applications.
>
> Particularly there are two apps that conflict and result an ImportError. The
> project structure approximately is as follows.
>
> project
>  |_ project
>|_ settings.py
>|_ ...
>  |_ apps
>|_ A
>  |_ handlers
>|_ B.py
>|_ C.py
>|_ B
>  |_ models.py
>
> The settings file adds apps directory to the system path.
>
> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
> sys.path.insert(0, os.path.join(BASE_DIR, "apps"))
>
> This configuration assumes that when I import the B.models it will use
> apps/B/models.py. Although the following line in the C.py file raise an
> import error as it imports the A/handlers/B.pywhich does not have models
> module.
>
> A/handlers/C.py:
> from B.models import BModel
>
> The sys.path variable has a correct items, i.e. the first one in the list is
> /path/to/project/appsand sys.modules['B.models'] is referenced to the
> correct file.
>
> BTW, when I use Django's import_by_path function, everything works fine.
>
> Any ideas how I can solve the problem without renaming the modules?
>
> Posted sample sources on GitHub.
>
> Thanks in advance!
>

The simplest solution is to simply rename either app or component that
conflicts.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1KE-WunyPZuZZN79skNtA_MUsShNeHyGzwywNVx64fJxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django app and a submodule name conflict

2014-06-04 Thread Vahe Evoyan
It currently works as you describe: "from .B.models import BModel", but I 
need it to work like "from ...B.models import BModel" to import 
apps/B/models.py module. The problem with "..." is that apps directory is 
not a module (i.e. there is no __init__.py file). The app directory is the 
first one in the sys.path list, so the simple "from B.models import BModel" 
should look in apps/B/models.py file, but it looks into current directory 
earlier than app directory.

This structure perfectly works with a simple python scripts (without Django 
included), that's why I suspect that Django hooks something in the import 
procedure.

On Wednesday, June 4, 2014 11:19:50 PM UTC+4, Joseph Catrambone wrote:
>
> It may be worth trying a relative import, depending on which version of 
> Python you're using.  I believe you can do "from .B.models import BModel". 
>  Note the '.' full-stop/period before the module.  I can't promise that 
> will fix your problem, as the layout isn't entirely clear to me, but it 
> might get you on the right track.
>
> On Wednesday, June 4, 2014 3:51:28 AM UTC-4, Vahe Evoyan wrote:
>>
>> I have modules in the project with the same names, all placed in 
>> different applications.
>>
>> Particularly there are two apps that conflict and result an ImportError. 
>> The project structure approximately is as follows.
>>
>> project
>>  |_ project   
>>|_ settings.py
>>|_ ...
>>  |_ apps
>>|_ A
>>  |_ handlers
>>|_ B.py
>>|_ C.py
>>|_ B
>>  |_ models.py
>>
>> The settings file adds apps directory to the system path.
>>
>> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
>> sys.path.insert(0, os.path.join(BASE_DIR, "apps"))
>>
>> This configuration assumes that when I import the B.models it will use 
>> apps/B/models.py. Although the following line in the C.py file raise an 
>> import error as it imports the A/handlers/B.pywhich does not have models
>>  module.
>>
>> A/handlers/C.py:
>> from B.models import BModel
>>
>> The sys.path variable has a correct items, i.e. the first one in the 
>> list is /path/to/project/appsand sys.modules['B.models'] is referenced 
>> to the correct file.
>>
>> BTW, when I use Django's import_by_path function, everything works fine.
>>
>> Any ideas how I can solve the problem without renaming the modules?
>>
>> Posted sample sources 
>>  on GitHub.
>>
>> Thanks in advance!
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/192777eb-9476-4db4-9973-f7587eb003ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django app and a submodule name conflict

2014-06-04 Thread Joseph Catrambone
It may be worth trying a relative import, depending on which version of 
Python you're using.  I believe you can do "from .B.models import BModel". 
 Note the '.' full-stop/period before the module.  I can't promise that 
will fix your problem, as the layout isn't entirely clear to me, but it 
might get you on the right track.

On Wednesday, June 4, 2014 3:51:28 AM UTC-4, Vahe Evoyan wrote:
>
> I have modules in the project with the same names, all placed in different 
> applications.
>
> Particularly there are two apps that conflict and result an ImportError. 
> The project structure approximately is as follows.
>
> project
>  |_ project   
>|_ settings.py
>|_ ...
>  |_ apps
>|_ A
>  |_ handlers
>|_ B.py
>|_ C.py
>|_ B
>  |_ models.py
>
> The settings file adds apps directory to the system path.
>
> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
> sys.path.insert(0, os.path.join(BASE_DIR, "apps"))
>
> This configuration assumes that when I import the B.models it will use 
> apps/B/models.py. Although the following line in the C.py file raise an 
> import error as it imports the A/handlers/B.pywhich does not have models
>  module.
>
> A/handlers/C.py:
> from B.models import BModel
>
> The sys.path variable has a correct items, i.e. the first one in the list 
> is /path/to/project/appsand sys.modules['B.models'] is referenced to the 
> correct file.
>
> BTW, when I use Django's import_by_path function, everything works fine.
>
> Any ideas how I can solve the problem without renaming the modules?
>
> Posted sample sources 
>  on GitHub.
>
> Thanks in advance!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0e09ff68-d4a7-4353-afd3-0932205a7823%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.