[Tutor] my own site-package

nik my.mailing.lists at noos.fr
Wed Oct 6 21:10:24 CEST 2004


Branimir Petrovic wrote:

>>In your case, as Kent said, all you need to do is move your 
>>module1.py 
>>out of the subfolder and put it directly into site-packages.  
>>Then you 
>>can simply 'import module1' and not worry about having an 
>>__init__.py or 
>>whether you're injecting unnecessary names into your namespace. :)
>>
>>    
>>
>
>To add another "angle" to this thread - I personally dislike disturbing
>sacredness of Python's site-packages. Instead I tend to place my project
>related modules in its own "Lib" folder right next to my "main script".
>For instance say I have MyScript.py that is using (undisclosed) number
>of custom (MyScript.py that is) related modules. I'd typically create 
>structure like this:
>
>	MyPyProject	(folder)
>		|
>		+- MyScript.py (this is the "main guy")
>		|
>		+- Lib (folder)
>		    |
>		    +- MyModule1.py
>		    +- MyModule2.py
>			...
>
>
># FileName: MyScript.py
>
>import sys, os
>
>def addLibPath():
>    """Add current script path and its Lib folder to system path"""
>    os.chdir(os.path.dirname(sys.argv[0]))
>    scriptPath, libPath = os.path.dirname(sys.argv[0]),
>os.path.abspath(r'..\Lib')
>    sys.path.extend([scriptPath, libPath])
>
>
>if __name__=='__main__':
>    addLibPath()            # know where to find your own library modules
>
>    # The rest of your code referencing (your own) project related modules 
>    # comes here:
>
>    # ...
>
>
>Of course - you can put your modules right next to Python's own, but
>to me at least this somehow does not "sound" right nor proper...
>
>
>Branimir
>                            
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>
Just where to put files is something I wasn't certain about.

My ultimate aim is to provide a software/hardware solution to my 
customers, and a large part of the software part will be python scripts 
that can be either used 'out of the box' or customised freely (or 
somewhere in between, a pick and choose situation). So, they'll receive 
a server with pre-installed software and a user account that has access 
to those components (to keep it separate from root). I'm not planning on 
selling it as a software only solution (yet), so there'd be no conflict 
with personal accounts etc.

Each instance of the main server app interfaces to the python scripts 
through a single file which has three required functions. There maybe 
several server apps running concurrently, which might require different 
scripts.
I'm providing a fairly comprehensive set of helper modules which can be 
called by that script file (ie database access, socket support, XML 
translation etc), which could be used as is, but I'm happy if the user 
modifies them (which they probably will).

My initial idea was to put the helper modules in a single package in 
site-packages, but I'm not sure where to put the main scripts that the 
server app accesses (/usr/local/etc, /home/serveradmin/scripts etc?).

I'm happy for suggestions on where things should go, although I guess 
it's all a matter of choice. But maybe there are some pro's and con's 
for various ways. One idea I've been considering is a publishing method, 
where the files are editable in the users account, and can then be 
published to the 'live' location, which then allows rolling back of code 
etc (assuming the users are bound to mess it all up). I'm not sure how 
complicated I want to make (my) life though (maybe I can use CVS?)...

nik


More information about the Tutor mailing list