[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tinkering with sketch as module

From: Bernhard Herzog
Subject: Re: Tinkering with sketch as module
Date: Sat, 31 Jul 2004 23:31:27 +0200
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (gnu/linux)

Terry Hancock <address@hidden> wrote more than a month ago:

> What the heck does this code do:
> for dir in ('Lib', 'Filter', 'Pax'):
>     dir = os.path.join(sys.path[0], dir)
>     if os.path.isdir(dir):
>         sys.path.insert(1, dir)
> ?

It adds some directories to Python's module search path.  When Skencil
is installed the script is put into the same directory as the main
package Sketch.  There's also a subdirectory, Lib, with some extra
modules that are shipped with Skencil but are conceptually independend
of Skencil.  That directory has to be added sys.path so that Skencil can
import the modules.

The other directories, Filter and Pax, are needed when you run Skencil
directly from the source directory in which case the extra modules are
in those directories and not in Lib.

> As I read it, it will generally have no effect at all -- 
> it's adding "./Lib", "./Filter", and "./Pax" to the Python 
> path if they exist?  But of course, they usually won't, 
> since we're looking for them (I think) in the current 
> directory. 

When you invoke python with the name of the file to run, python puts the
directory containing the file into sys.path[0] so that the program can
import modules specific to that program.  Skencil makes use of this

When you run python without a filename, that is in the normal
interactive mode, sys.path[0] is indeed ".".  This is considered a
feature so that you can easily play around with the modules you work on.
There's a certain security risk, though, similar to that of putting
. into the shell's PATH.

> Also, what's the prognosis on getting Sketch to work with 
> two python installations (Python 2.1 and 2.3)?  Do I need 
> to do a separate installation of sketch for each?  I'm 
> guessing so, since the .so files won't be compatible.

The pyc-files will also be different.  This will mean if you switch
python versions they will all be recompiled or if you don't have write
permissions in those directories, only one Python installation actually
benefits from the precompilation.

> Finally, can sketch be made to install like a regular python 
> module -- such as might be desireable on a server, where 
> I'm only interested in using it for conversions? 

I have never tried it, but this might work: Create a directory skencil
in your python's site-packages directory and copy Sketch/, Plugins/ and
Lib/ into it.  Then create and suitable .pth file in site-packages
> And if I 
> do this, can I trim some library dependencies -- the server
> might not have TK or GTK libs and stuff if it is normally 
> run headless.

Only the code in Sketch.UI and some plugins actually uses the GUI.  If
you stick to e.g. the import/export filter plugins, Sketch.Graphics and,
in 0.7, Sketch.Editor you should be fine.  That's the theory anyway :-), I
haven't really tested that lately.


Intevation GmbH                       

reply via email to

[Prev in Thread] Current Thread [Next in Thread]