在 Python 开源项目中加入第三方库的首选传统方式是什么? [英] What is the preferred conventional way of incorporating a third party library in Python open source projects?

查看:41
本文介绍了在 Python 开源项目中加入第三方库的首选传统方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 WSGI 框架开发一个新的 Python 身份验证库,并希望使用 python-openid 或许还有其他一些第三方库.我看到 2 个选项:

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:

  • 在我的库中分发第三方库的副本(通过 GIT 子模块)
  • 我的库的用户自己解决对第三方库的依赖
  • 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

问题是:

在 Python 开源项目中加入第三方库的首选传统方式是什么?

推荐答案

首选方式是使用 setuptools/distribute 并定义一个setup.py 用于通过 PyPi.

The preffered way is to use setuptools/distribute and define a setup.py for your project that downloads third-party libraries via PyPi.

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

Here's an extract from one of my projects. Note the use of setup/install/test/extras-require keyword arguments, which is what you're looking for

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

这篇关于在 Python 开源项目中加入第三方库的首选传统方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆