python (库、应用程序 ) (打包、上传、构建、安装) => LTS

来源:互联网 发布:千千静听 mac 老版本 编辑:程序博客网 时间:2024/06/11 09:06

首先你要有一个setup.py (不管用上古的distutils还是标准的setuptools还是其他先进的打包工具)

库的打包

打包成tar.gz python setup.py sdist
打包成exe python setup.py bdist_wininst
打包成rpm python setup.py bdist_rpm(rpm 指令支持)
打包成whl python setup.py bdist_wheel (需要 pip install wheel)

setup.py 上联requirements.txt 下联MANIFEST.in, 中走LICENSE
pip freeze > requirements.txt
参考
requirements.txt

alembic==0.8.6bleach==1.4.3click==6.6dominate==2.2.1Flask==0.11.1Flask-Bootstrap==3.3.6.0Flask-Login==0.3.2Flask-Migrate==1.8.1Flask-Moment==0.5.1Flask-PageDown==0.2.1

(可以不带版本号)

MANIFEST.in

include LICENSEinclude README.rstinclude requirements.txtrecursive-include polls/static *recursive-include polls/templates *

添加非py文件

import osfrom setuptools import find_packages, setupwith open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:    README = readme.read()with open('requirements.txt') as f:    required = f.read().splitlines()# allow setup.py to be run from any pathos.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))setup(    name = 'minghu6',    version = '1.0.0',    install_requires = required,    packages = find_packages(),    entry_points = {        'console_scripts' : ['captcha=minghu6.tools.captcha:interactive',                             'ffmpeg_fix=minghu6.tools.ffmpeg_fix:interactive',                             'fileformat=minghu6.tools.fileformat:interactive',                             'launch=minghu6.tools.launch:interactive',                             'proxy_ip=minghu6.tools.proxy_ip:interactive',                             'yinyuetai=minghu6.tools.Tai_downloader:interactive',                             'text_editor=minghu6.tools.textEditor:interactive',                             'youtube=minghu6.tools.Tube_downloader:interactive',                             'countlines=minghu6.tools.count_lines:interactive',                             'add_pypath=minghu6.tools.add_py_path:interactive',                             'tieba=minghu6.tools.Tieba_downloader:interactive',                             ],    },    include_package_data = True,    licence = 'BSD License',     description = 'A Core Utils Set for minghu6.',    long_description = README,    url = 'https://github.com/minghu6/minghu6_py',    author = 'minghu6',    author_email = 'a19678zy@163.com',    classifiers=[        'Intended Audience :: Developers',        'License :: OSI Approved :: BSD License',        'Operating System :: OS Independent',        'Programming Language :: Python',        'Programming Language :: Python :: 3',    ],    )

以setuptools为例,
其中, console_scripts是会打包成所在
对应平台的二进制文件, 比如Windows: pip.exe
'<binary-file-name> = <setup.py 下的pacage路径>:<入口函数名>'

另外注意 classifiers 是部署应用的必要环境,而不是支持的环境,所以不必过于细致,限制了
潜在的应用场合

Copyright (c) 2015, minghu6 <a19678zy@outlook.com>All rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

以BSD (3-clauses)为例

上传至PyPI

  1. 注册PyPI账户PyPI Doc ref
  2. 安装 twine (pip install twine)
  3. write a ~/.pypirc file like so.

    [distutils]index-servers=pypi[pypi]repository = https://upload.pypi.org/legacy/username = <username>password = <password>
  4. twine upload dist/*

通过pip安装

假设包名为minghu6pip install -v minghu6==1.0.1

通过travis 自动部署

安装travis,
根据官方教程,

注意:

1.通过travis的 Job log(包括raw) 查看部署的详细信息(trace)2.tags:true 需要与 all_branches: true 同时开启3.使用travis lint 进行格式检查,可能会超时报错,多试几次

Add badge for pypi

仅支持rst格式, 且需要注意冒号缩进

.. image:: https://landscape.io/github/minghu6/minghu6_py/master/landscape.svg?style=flat   :target: https://landscape.io/github/minghu6/minghu6_py/master   :alt: Code Health

PyPI version

0 0
原创粉丝点击