organizing your scripts, with plenty of re-use

Buck workitharder at gmail.com
Sat Oct 10 01:37:28 CEST 2009


On Oct 5, 2:15 pm, "Rami Chowdhury" <rami.chowdh... at gmail.com> wrote:
> On Mon, 05 Oct 2009 13:46:09 -0700, Buck <workithar... at gmail.com> wrote:
> > Thanks. I think we're getting closer to the core of this.
>
> > To restate my problem more simply:
>
> > My core goal is to have my scripts in some sort of organization better
> > than a single directory, and still have plenty of re-use between them.
> > The only way I can see to implement this is to have 10+ lines of
> > unintelligible hard-coded boilerplate in every runnable script.
> > That doesn't seem reasonable or pythonic.
>
> Perhaps I've simply not followed this thread closely enough but could you  
> let us know a little bit more about how you intend / expect the scripts to  
> be used?
>
> If there's a standard directory you expect them to be dropped into by your  
> users (e.g. $HOME/scripts) ...
We don't have any such convention. The production code is at a well-
known path, but I need the code to be fully relocatable (cp -r /known/
path ~/mydir) for testing purposes.

Here's a scenario. A user does a cvs checkout into some arbitrary
directory and sees this:

project/
+-- python/
    +-- animals.py
    +-- mammals/
        +-- horse.py
        +-- otter.py
    +-- reptiles/
        +-- gator.py
        +-- newt.py
    +-- misc/
        +-- lungs.py
        +-- swimming.py

These are all runnable scripts that "just work" with no extra effort
or knowlege, both in the testing scenario above, and for normal users
that run it from some central location (maybe "/tools/mycompany/bin/
mammals").

The frustrating thing, for me, is that all these requirements are met
if you leave the scripts in jumbled into a flat directory. As soon as
you start organizing things, you need a good amount of boilerplate in
each script to make things work anything like they did with the flat
directory.

I wouldn't mind having to write 'from mammals.horse import Horse' or
'from .animals import Animal' but it's not that simple.



More information about the Python-list mailing list