5

I'm working on a new Python authentication library for WSGI frameworks and want to use the python-openid and maybe some other third-party libs too. I see 2 options:

  • Distribute my library with a copy of the third-party library inside (via GIT submodules)
  • Let the user of my library resolve the dependency on the third-party library by himself

The question is:

What is the preferred conventional way of incorporating a third party library in Python open source projects?

4

1 回答 1

6

首选的方法是使用setuptools / distribute并为您的项目定义一个setup.py通过PyPi下载第三方库。

这是我的一个项目的摘录。请注意 setup/install/test/extras-require 关键字参数的使用,这就是您要查找的内容

import distribute_setup
distribute_setup.use_setuptools()

import os
from setuptools import setup, find_packages

# Utility function to read the README file.
# Used for the long_description.  It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name='buildboticon',
    version='0.3.2',
    author='Marcus Lindblom',
    author_email='macke@yar.nu',
    description=('A buildbot monitoring utility'),
    license='GPL 3.0',
    keywords='buildbot systemtray pyqt',

    url='http://bitbucket.org/marcusl/buildboticon',
    download_url='http://packages.python.org/buildboticon',

    package_dir={'':'src'},
    packages=find_packages('src', exclude=['*.tests']),
    long_description=read('README'),

    entry_points={
        'setuptools.installation': [
            'eggsecutable = bbicon:main',
        ],
        'gui_scripts': [
            'buildboticon = bbicon:main',
        ]
    },

    setup_requires=[
        'setuptools_hg',
    ],

    tests_require=[
        'unittest2 >= 0.5',
        'mock >= 0.7.0b4',
    ],

    install_requires=[
        'pyyaml >= 0.3',
#        'pyqt >= 4.7'   # PyQt doesn't have anything useful on PyPi :(
    ],

    extras_require={
        'speech':  ['pyspeech >= 1.0'],
#        'phidgets': ['PhidgetsPython >= 2.1.7'],
    },

完整文件在这里:https ://bitbucket.org/marcusl/buildboticon/src/5232de5ead73/python/setup.py

于 2013-01-14T10:38:15.240 回答