Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best layout for a python command line application?

What is the right way (or I'll settle for a good way) to lay out a command line python application of moderate complexity? I've created a python project skeleton using paster, which gave me a few files to start with:

myproj/__init__.py
MyProj.egg-info/
 dependency_links.txt
 entry_points.txt
 PKG-INFO
 SOURCES.txt
 top_level.txt
 zip-safe
setup.cfg
setup.py

I want to know, mainly, where should my program entry point go, and how can I get it installed on the path? Does setuptools create it for me? I'm trying to find this in the HHGTP, but maybe I'm just missing it.

like image 668
Chris R Avatar asked Aug 12 '10 05:08

Chris R


1 Answers

You don't need to create all that, the .egg-info directory is generated by setuptools. You mention the command line, so I assumed you have a 'top level' script somewhere, let's say myproj-bin. Then this would work:

./setup.py
./myproj
./myproj/__init__.py
./scripts
./scripts/myproj-bin

And then put something like this in setup.py:

#! /usr/bin/python

from setuptools import setup

setup(name="myproj",
      description='shows how to create a python package',
      version='123',
      packages=['myproj'],  # python package names here
      scripts=['scripts/myproj-bin'],  # scripts here
      )

There's a lot more that you can do if your project is complex, the full manual of setuptools is here: http://peak.telecommunity.com/DevCenter/setuptools.

like image 129
Ivo Avatar answered Oct 18 '22 01:10

Ivo