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

Discussion in 'Python' started by eryksun (), Mar 14, 2011.

  1. eryksun ()

    eryksun () Guest

    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.
     
    eryksun (), Mar 14, 2011
    #1
    1. Advertising

  2. eryksun ()

    bukzor Guest

    On Mar 14, 1:30 pm, "eryksun ()" <> 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=en&lr=&q=sys\.path.*__file__
     
    bukzor, Mar 15, 2011
    #2
    1. Advertising

  3. eryksun ()

    booklover Guest

    > 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.
     
    booklover, Mar 15, 2011
    #3
  4. eryksun ()

    bukzor Guest

    On Mar 15, 12:24 pm, booklover <> 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.
     
    bukzor, Mar 16, 2011
    #4
  5. eryksun ()

    booklover Guest

    > 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?
     
    booklover, Mar 16, 2011
    #5
  6. eryksun ()

    bukzor Guest

    On Mar 16, 7:42 am, booklover <> 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
     
    bukzor, Mar 16, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phat Fly Alanna
    Replies:
    4
    Views:
    284
    Tim Johnson
    Mar 14, 2011
  2. bukzor
    Replies:
    1
    Views:
    214
    Jean-Michel Pichavant
    Mar 14, 2011
  3. eryksun ()
    Replies:
    4
    Views:
    228
    bukzor
    Mar 14, 2011
  4. Nicholas Van Weerdenburg

    RuWiki in a Corporate Environment

    Nicholas Van Weerdenburg, Jan 25, 2005, in forum: Ruby
    Replies:
    4
    Views:
    86
    Raphael Bauduin
    Jan 25, 2005
  5. Steve Molitor

    Using Ruby in a Corporate Environment

    Steve Molitor, Apr 26, 2007, in forum: Ruby
    Replies:
    6
    Views:
    123
    Alexey Verkhovsky
    Apr 28, 2007
Loading...

Share This Page