Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: organizing many python scripts, in a large corporate environment.

Reply
Thread Tools

Re: organizing many python scripts, in a large corporate environment.

 
 
eryksun ()
Guest
Posts: n/a
 
      03-14-2011
On Monday, March 14, 2011 3:56:15 PM UTC-4, eryksun () wrote:
> To be clear on the file structure, I'm picturing that 'base' is a
> path on each user's shell path where all the accessible scripts
> are linked, and that this is also the package directory.


Wait, this won't work when the script is linked to from somewhere else, which means the code still has to be based on __file__ or sys.argv[0] or sys.path[0], and have to get the absolute/real path in case it's a link.

Along those lines, you (bukzor) wrote that

> What I do right now is to symlink this library to all script
> directories to allow them to bootstrap and gain access to
> libraries not in the local directory.


Won't this also fail if it's running from a link? The link to the library won't necessarily be in the current directory.
 
Reply With Quote
 
 
 
 
bukzor
Guest
Posts: n/a
 
      03-15-2011
On Mar 14, 1:30*pm, "eryksun ()" <(E-Mail Removed)> wrote:
> On Monday, March 14, 2011 3:56:15 PM UTC-4, eryksun () wrote:
> > To be clear on the file structure, I'm picturing that 'base' is a
> > path on each user's shell path where all the accessible scripts
> > are linked, and that this is also the package directory.

>
> Wait, this won't work when the script is linked to from somewhere else, which means the code still has to be based on __file__ or sys.argv[0] or sys..path[0], and have to get the absolute/real path in case it's a link.
>
> Along those lines, you (bukzor) wrote that
>
> > What I do right now is to symlink this library to all script
> > directories to allow them to bootstrap and gain access to
> > libraries not in the local directory.

>
> Won't this also fail if it's running from a link? The link to the librarywon't necessarily be in the current directory.


You're right! QQ
Currently it requires either: 1) no symlinks to scripts or 2)
installation of the pathtools to site-packages.

Mostly I came here because I felt this was a real pain with no good
solution, and felt that I must be missing something essential if
nobody else is thinking or talking about it. When looking at google
code search, this kind of code is rampant (below). Is everyone really
happy with this?

sys.path.insert(0,
os.path.dirname(os.path.dirname(os.path.dirname(os .path.abspath(__file__)))))

see: http://www.google.com/codesearch?hl=...path.*__file__
 
Reply With Quote
 
 
 
 
booklover
Guest
Posts: n/a
 
      03-15-2011
> Is everyone really happy with this?

I'm not happy with this. In fact, if Python 3.3 came out with a
solution for this problem, it would be a major motivation for me to
migrate.

I don't think that it would take much to fix either. Perhaps if Python
looked in the current directory for ".pth" files? Instead of having
some boiler-plate at the top of every file, you could specify your
paths there. I haven't thought about it enough to know that this idea
specifically is the best way to go, but it would be nice if there were
some way of solving this cleanly.
 
Reply With Quote
 
bukzor
Guest
Posts: n/a
 
      03-16-2011
On Mar 15, 12:24*pm, booklover <(E-Mail Removed)> wrote:
> > Is everyone really happy with this?

>
> I'm not happy with this. In fact, if Python 3.3 came out with a
> solution for this problem, it would be a major motivation for me to
> migrate.
>
> I don't think that it would take much to fix either. Perhaps if Python
> looked in the current directory for ".pth" files? Instead of having
> some boiler-plate at the top of every file, you could specify your
> paths there. I haven't thought about it enough to know that this idea
> specifically is the best way to go, but it would be nice if there were
> some way of solving this cleanly.


I'm going to try to get our solution open-sourced, then I'll get your
feedback on it.
 
Reply With Quote
 
booklover
Guest
Posts: n/a
 
      03-16-2011
> I'm going to try to get our solution open-sourced, then I'll get your
> feedback on it.


Thanks bukzor! I think that it would be very helpful to have a library
like this available.

In the longer term, what do people think about the possibility of
writing up a PEP to fix this problem in the core language? Anyone have
any ideas on the cleanest way to achieve this goal?
 
Reply With Quote
 
bukzor
Guest
Posts: n/a
 
      03-16-2011
On Mar 16, 7:42*am, booklover <(E-Mail Removed)> wrote:
> > I'm going to try to get our solution open-sourced, then I'll get your
> > feedback on it.

>
> Thanks bukzor! I think that it would be very helpful to have a library
> like this available.
>
> In the longer term, what do people think about the possibility of
> writing up a PEP to fix this problem in the core language? Anyone have
> any ideas on the cleanest way to achieve this goal?


If we had relative imports for scripts as well as package modules,
that would be the end of it.
When the relative import escapes the current package (or module) start
using filesystem semantics, where another dot means a parent
directory, and something that looks like a package is just a
directory. This replaces the "relative import from non-package" error,
so backward-compatibility is a non-issue.

bin/parrot/speak.py:
def say(text):
print text

bin/parrot/mccaw.py
#this is a script, not a module!
from ..speak import say

bin/guy/__init__.py
from ..parrot.speak import say


 
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
organizing many python scripts, in a large corporate environment. bukzor Python 1 03-14-2011 10:32 AM
Re: organizing many python scripts, in a large corporate environment. eryksun () Python 4 03-14-2011 06:40 AM
organizing many python scripts, in a large corporate environment. Phat Fly Alanna Python 4 03-14-2011 12:10 AM
Organizing and converting large number of XML files Donald Firesmith XML 1 01-08-2005 10:57 PM
help organizing large photo collection on Mac Charlotte DeMott Digital Photography 3 11-28-2003 03:10 PM



Advertisments