python module打包发布

打包工具 setuptools 文档:

https://setuptools.readthedocs.io/en/latest/index.html#

一个例子:

#以mmcv的setup为例

from setuptools import Extension, dist, find_packages, setup

setup(
    name='mmcv',
    version=get_version(),
    description='Open MMLab Computer Vision Foundation',
    long_description=readme(),
    keywords='computer vision',
    packages=find_packages(),
    classifiers=[
        'Development Status :: 4 - Beta',
        'License :: OSI Approved :: Apache Software License',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Topic :: Utilities',
    ],
    url='https://github.com/open-mmlab/mmcv',
    author='Kai Chen',
    author_email='chenkaidev@gmail.com',
    setup_requires=['pytest-runner'],
    tests_require=['pytest'],
    install_requires=install_requires,
    ext_modules=EXT_MODULES,
    cmdclass={'build_ext': build_ext},
    zip_safe=False)


"""
classifiers = [ # 发展时期,常见的如下 # 3 - Alpha # 4 - Beta # 5 - Production/Stable 'Development Status :: 3 - Alpha', # 开发的目标用户 'Intended Audience :: Developers', # 属于什么类型 'Topic :: Software Development :: Build Tools', # 许可证信息 'License :: OSI Approved :: MIT License', # 目标 Python 版本 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', ]
"""

name,version,author等这些基本信息是要发布的包的基本信息,通过packages=find_packages()找到当前目录下有哪些包

setup参数配置可参考文档:

https://packaging.python.org/guides/distributing-packages-using-setuptools/

 

完成setup.py配置后, 打包, 注意执行clean清理上一次打包的缓存:

python setup.py clean
python setup.py bdist_wheel

 

发布到pypi, 注册PyPI账号,创建~/.pypirc文件,配置PyPI访问地址和账号 (例如)

[distutils]
index-servers =
    pypixxxxx

[pypixxxxx]
repository: https://pypi.xxxxx
username: xxxxx
password: xxxxx

 

使用twine上传pypi

pip install twine

twine check dist/*

twine upload dist/*

 

posted @ 2020-12-05 20:16  awr2sdgae  阅读(212)  评论(0)    收藏  举报