Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > import conflict

Reply
Thread Tools

import conflict

 
 
rplzqx402@sneakemail.com
Guest
Posts: n/a
 
      05-07-2007
Hello,

I have a problem where I need to set up two separate Python projects
that each live under the same package. Once they are distributed,
they will live under the same filesystem path, but during development,
they are separated.

For example:
proj1/lib/pkg/foo/mod1.py
proj2/lib/pkg/bar/mod2.py

Furthermore, proj1 is dependent on proj2, so I want to be able to say
things like this, from within proj1:

import pkg.foo.mod1
import pkg.bar.mod2

Of course this doesn't work, even with a PYTHONPATH configured to see
both projects, because it will find 'pkg' in proj1/lib and so pkg.bar
will be hidden from view.

Any suggestions?

Thanks!

 
Reply With Quote
 
 
 
 
Stefan Sonnenberg-Carstens
Guest
Posts: n/a
 
      05-07-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) schrieb:
> Hello,
>
> I have a problem where I need to set up two separate Python projects
> that each live under the same package. Once they are distributed,
> they will live under the same filesystem path, but during development,
> they are separated.
>
> For example:
> proj1/lib/pkg/foo/mod1.py
> proj2/lib/pkg/bar/mod2.py
>
> Furthermore, proj1 is dependent on proj2, so I want to be able to say
> things like this, from within proj1:
>
> import pkg.foo.mod1
> import pkg.bar.mod2
>
> Of course this doesn't work, even with a PYTHONPATH configured to see
> both projects, because it will find 'pkg' in proj1/lib and so pkg.bar
> will be hidden from view.
>
> Any suggestions?
>
> Thanks!
>
>

Hi,
my only suggestion would be to overthink your project organization.
You can surely solve that problem with symlinks, but if they depend
on another, perhaps the structure is not optimal.
If you use python 2.5 you can try absolute imports (which I personally
find not so well):

from __future__ import absolute_import

See here: http://python.mirrors-r-us.net/dev/peps/pep-0328/

Cheers,
Stefan

 
Reply With Quote
 
 
 
 
Stefan Sonnenberg-Carstens
Guest
Posts: n/a
 
      05-07-2007
(E-Mail Removed) schrieb:
> Hello,
>
> I have a problem where I need to set up two separate Python projects
> that each live under the same package. Once they are distributed,
> they will live under the same filesystem path, but during development,
> they are separated.
>
> For example:
> proj1/lib/pkg/foo/mod1.py
> proj2/lib/pkg/bar/mod2.py
>
> Furthermore, proj1 is dependent on proj2, so I want to be able to say
> things like this, from within proj1:
>
> import pkg.foo.mod1
> import pkg.bar.mod2
>
> Of course this doesn't work, even with a PYTHONPATH configured to see
> both projects, because it will find 'pkg' in proj1/lib and so pkg.bar
> will be hidden from view.
>
> Any suggestions?
>
> Thanks!
>
>

Hi,
my only suggestion would be to overthink your project organization.
You can surely solve that problem with symlinks, but if they depend
on another, perhaps the structure is not optimal.
If you use python 2.5 you can try absolute imports (which I personally
find not so well):

from __future__ import absolute_import

See here: http://python.mirrors-r-us.net/dev/peps/pep-0328/

Cheers,
Stefan
 
Reply With Quote
 
Alex Martelli
Guest
Posts: n/a
 
      05-07-2007
<(E-Mail Removed)> wrote:

> Hello,
>
> I have a problem where I need to set up two separate Python projects
> that each live under the same package. Once they are distributed,
> they will live under the same filesystem path, but during development,
> they are separated.
>
> For example:
> proj1/lib/pkg/foo/mod1.py
> proj2/lib/pkg/bar/mod2.py
>
> Furthermore, proj1 is dependent on proj2, so I want to be able to say
> things like this, from within proj1:
>
> import pkg.foo.mod1
> import pkg.bar.mod2
>
> Of course this doesn't work, even with a PYTHONPATH configured to see
> both projects, because it will find 'pkg' in proj1/lib and so pkg.bar
> will be hidden from view.


proj1/lib/pkg/__init__.py (and its counterpart under proj2) might set
their __path__ as to "merge" the two separate directories when seen as
Python packages. A rather contorted "solution" (compared to the simple
and obvious one of NOT "separating during development" parts that appear
to be so closely entwined) but I think it would work.


Alex
 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      05-07-2007
On 6 May 2007 19:16:17 -0700, (E-Mail Removed) declaimed the
following in comp.lang.python:

> Hello,
>
> I have a problem where I need to set up two separate Python projects
> that each live under the same package. Once they are distributed,
> they will live under the same filesystem path, but during development,
> they are separated.
>
> For example:
> proj1/lib/pkg/foo/mod1.py
> proj2/lib/pkg/bar/mod2.py
>

That does not fit your text description "two separate ... under the
same package."

Your text description implies something like

lib/pkg/proj1/foo/...
lib/pkg/proj2/bar/...
--
Wulfraed Dennis Lee Bieber KD6MOG
(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
css conflict (or html conflict) charles cashion HTML 2 02-18-2009 09:41 PM
to use import java.lang.* or import java.lang.Math or none at all? JPractitioner Java 13 02-24-2006 08:48 PM
XML Schema question - does "import" import elements? Vitali Gontsharuk XML 2 08-25-2005 07:33 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
targetNamespace/import conflict Charles Fineman XML 2 02-09-2004 08:39 PM



Advertisments