How to properly package/distribute a pure python module?

M

Matt Shomphe

Are there any guidelines for packaging a pure python module?
Specifically, say I have a set of 10 functions, all of varying
behaviors (no unifying theme to bind them together into clear
subsets), that I would like to make available to others. What is the
best structure for the distributed module? A single file called
"functions.py" that people can put in "site-packages"[1]? A
subdirectory called "MyFunctions" with an "__init__.py" and the
"functions.py" files[2]? Or should the functions be broken out into
individual files[3]?

I'm sure it depends on some other factorsbut are there general rules
for constructing a nice, logical package for others to use?

[1] site-packages/functions.py (from functions import f1)
[2] site-packages/MyFunctions/functions.py, __init__.py (from
MyFunctions.functions import f1)
[3] site-packages/MyFunctions/__init__.py, f1.py, f2.py, f3.py (from
MyFunctions.f1 import f1)
 
A

Andy Todd

Matt said:
Are there any guidelines for packaging a pure python module?
Specifically, say I have a set of 10 functions, all of varying
behaviors (no unifying theme to bind them together into clear
subsets), that I would like to make available to others. What is the
best structure for the distributed module? A single file called
"functions.py" that people can put in "site-packages"[1]? A
subdirectory called "MyFunctions" with an "__init__.py" and the
"functions.py" files[2]? Or should the functions be broken out into
individual files[3]?

I'm sure it depends on some other factorsbut are there general rules
for constructing a nice, logical package for others to use?

[1] site-packages/functions.py (from functions import f1)
[2] site-packages/MyFunctions/functions.py, __init__.py (from
MyFunctions.functions import f1)
[3] site-packages/MyFunctions/__init__.py, f1.py, f2.py, f3.py (from
MyFunctions.f1 import f1)

I'd suggest you look at the distribution utilities for Python;

http://www.python.org/sigs/distutils-sig/doc/

Specifically the documentation on distrbuting Python modules;

http://www.python.org/doc/current/dist/

The documentation can be a little confusing at first but stick with it
and if you have any questions please ask them here or on the
distutils-sig mailing list.

Regards,
Andy
 
C

Christopher Blunck

Are there any guidelines for packaging a pure python module?
Specifically, say I have a set of 10 functions, all of varying
behaviors (no unifying theme to bind them together into clear
subsets), that I would like to make available to others. What is the
best structure for the distributed module? A single file called
"functions.py" that people can put in "site-packages"[1]? A
subdirectory called "MyFunctions" with an "__init__.py" and the
"functions.py" files[2]? Or should the functions be broken out into
individual files[3]?

I'm sure it depends on some other factorsbut are there general rules
for constructing a nice, logical package for others to use?

[1] site-packages/functions.py (from functions import f1)
[2] site-packages/MyFunctions/functions.py, __init__.py (from
MyFunctions.functions import f1)
[3] site-packages/MyFunctions/__init__.py, f1.py, f2.py, f3.py (from
MyFunctions.f1 import f1)


Do a google search for the distutils module. For examples, look at
any python project (ZSI or SOAPpy for example), and take a look at the
setup.py.

The gist of it is that you define a setup.py module that defines which
modules are to be included in the distro. A user, when they download
your tarball, goes into your directory and (as root): "python setup.py
install".

Once you have your app in distutils compatible format, you can use
distutils to generate .exe installs, rpm installs, tarball downloads,
etc etc etc.

So definitely take a look at distutils. :)


-c
 
J

John J. Lee

Are there any guidelines for packaging a pure python module?
Specifically, say I have a set of 10 functions, all of varying
behaviors (no unifying theme to bind them together into clear
subsets), that I would like to make available to others. What is the
best structure for the distributed module? A single file called
"functions.py" that people can put in "site-packages"[1]? A

If it's "the simplest thing that could possibly work" (TM), I'd say
yes, do that.


John
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top