开发者

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

开发者 https://www.devze.com 2023-01-11 00:35 出处:网络
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 fil

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/
 d开发者_如何学Pythonependency_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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消