对Distutils的贡献
项目描述
Python包distcontrib向Distutils贡献实用函数,扩展其功能,如与Cython构建的集成和doctest的启动器。
distcontrib存在的主要原因是在编写项目的setup.py时使生活变得更加容易。您可以创建一个模板setup.py文件,并简单地将其复制到您所有的新项目或现有项目中,在大多数情况下无需任何修改。在幕后,distcontrib找到了有关您的项目的多个部分,并自动配置自己,这样您就不必每次创建新项目时都调整您的setup.py文件。
另请参阅:distcontrib-migrate
用法
这是您的setup.py将看起来像的示例
#!/usr/bin/env python
from setuptools import find_packages
from distutils.core import setup
from Cython.Distutils import build_ext as cython_build
import distcontrib as du
##
# This block contains settings you will eventually need to change
###
import myapp as myapp #--- adjust to your package name
PACKAGE = myapp.pkg_name
VERSION = myapp.pkg_version
DESCRIPTION = myapp.pkg_description
LICENSE = myapp.pkg_license
URL = myapp.pkg_url
AUTHOR = myapp.pkg_author
AUTHOR_EMAIL = myapp.pkg_email
KEYWORDS = myapp.pkg_keywords
REQUIREMENTS = myapp.pkg_requirements
LONG_DESCRIPTION = du.tools.read('README')
CLASSIFIERS = [ 'License :: ' + LICENSE,
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Cython',
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Environment :: Console' ]
##
# From this point on, it's unlikely you will be changing anything.
###
PACKAGES = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"])
PACKAGES_DATA = du.tools.findall_package_data(PACKAGES)
EXT_MODULES = du.tools.find_ext_modules(PACKAGES)
setup(
name=PACKAGE,
version=VERSION,
description=DESCRIPTION,
url=URL,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
long_description=LONG_DESCRIPTION,
license=LICENSE,
keywords=KEYWORDS,
classifiers=CLASSIFIERS,
packages=PACKAGES,
package_data=PACKAGES_DATA,
cmdclass={ 'build_ext' : cython_build,
'doctest' : du.doctest,
'zap' : du.zap, },
ext_modules=EXT_MODULES,
install_requires=REQUIREMENTS
)
然后在您的myapp/__init__.py文件中创建类似以下内容
#!/usr/bin/env python pkg_name = __name__ if __package__ is None else __package__ pkg_description = 'This application does everything you can imagine' pkg_version = '0.1.0' pkg_license = 'OSI Approved :: BSD License' pkg_url = 'http://' + pkg_name + '.readthedocs.org/' pkg_author = 'Richard Gomes http://rgomes-info.blogspot.com' pkg_email = 'rgomes.info@gmail.com' pkg_keywords = [ 'artificial','intelligence','magic','sorcery','voodoo' ] pkg_requirements = [ 'lxml', 'sqlalchemy' ]
然后您可以在命令行中执行
$ python setup.py zap # clean on steroids $ python setup.py doctest # run your doctests $ python setup.py build_ext # build with Cython
命令zap比命令clean清除更多内容,是提交源代码控制更改或创建工作文件夹的备份副本的理想步骤。
命令 doctest 运行所有来自您所有包的 doctests。如果您发现某些 doctests 没有运行,请确保您已在所有包中创建了 __init__.py 文件。
特殊情况
在特定情况下,您可能需要确保您的 setup.py 安装一组基本需求,如果没有安装,可能会阻止您的 setup.py 正确运行。通过从包 distcontrib.bootstrap 借用函数 install_requirements 并在您的 setup.py 顶部调用它,您可以安装这些基本需求,如下所示
#!/usr/bin/env python
ESSENTIAL = [ 'distribute', 'version', 'Cython', 'distcontrib', 'distcontrib-migrate' ]
# This function was copied verbatim from distcontrib.bootstrap
# In certain situations, you are not sure if distcontrib is installed, then
# makes sense to have this function straight on the top of your setup.py
def install_requirements(requirements, verbose=True):
import os, pip
pip_args = list()
if verbose:
print('Installing requirements: ' + str(requirements))
pip_args.append( '--verbose' )
proxy = os.environ['http_proxy']
if proxy:
pip_args.append('--proxy')
pip_args.append(proxy)
if verbose:
print('http_proxy=' + proxy)
pip_args.append('install')
for req in requirements:
pip_args.append( req )
pip.main(initial_args = pip_args)
try:
from setuptools import find_packages
from distutils.core import setup
from Cython.Distutils import build_ext as cython_build
import distcontrib as du
import distcontrib_migrate as dm
except:
#-- import distcontrib.bootstrap
#-- distcontrib.bootstrap.install_requirements( ESSENTIAL )
install_requirements( ESSENTIAL )
# do it again
from setuptools import find_packages
from distutils.core import setup
from Cython.Distutils import build_ext as cython_build
import distcontrib as du
import distcontrib_migrate as dm
... the rest of your setup.py comes here
支持
错误:[https://bugs.launchpad.net/distcontrib](https://bugs.launchpad.net/distcontrib)
论坛:[https://answers.launchpad.net/distcontrib](https://answers.launchpad.net/distcontrib)
源代码:[https://code.launchpad.net/distcontrib](https://code.launchpad.net/distcontrib)
项目详情
distcontrib-0.1.0.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 2fafe2a59a1f27a814d87a3a61203311ac806b5624b1f88dddf83a587d2e469f |
|
| MD5 | 6b45e8ab79d07bd058721cf885dd7f06 |
|
| BLAKE2b-256 | b63ae663c8cf81158121fb9339a13fdcc3ea515cc746cc05cdfcfb866923fd4c |