公司的插件还不成熟,最近需要不断丰富完善、频繁改造,所以需要用到打包,这里记录一下。与Java的JAR文件类似,具体操作如下:

1、打包制作egg,zip,.exe文件

1.1 setup.py脚本如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import io
from pkgutil import walk_packages

from setuptools import setup


def find_packages(path):
    # This method returns packages and subpackages as well.
    return [name for _, name, is_pkg in walk_packages([path]) if is_pkg]

# def find_packages(path):
#     # This method returns packages and subpackages as well.
#     return [name for _, name, is_pkg in walk_packages([path]) if is_pkg]
def read_file(filename):
    with io.open(filename,'r', encoding='UTF-8') as fp:
        return fp.read().strip()

def read_rst(filename):
    # Ignore unsupported directives by pypi.
    content = read_file(filename)
    return ''.join(line for line in io.StringIO(content)
                   if not line.startswith('.. comment::'))

def read_requirements(filename):
    return [line.strip() for line in read_file(filename).splitlines()
            if not line.startswith('#')]

setup(
    name='bwjf-scrapy',
    version=read_file('VERSION'),
    description="wxm scrapy base module",
    long_description=read_rst('README.rst') + '\n\n' + read_rst('HISTORY.rst'),
    author="simon",
    author_email='simon_wang00@163.com',
    url='',
    packages=list(find_packages('src')),
    package_dir={'': 'src'},
    setup_requires=read_requirements('requirements-setup.txt'),
    install_requires=read_requirements('requirements-install.txt'),
    include_package_data=True,
    license="MIT",
    keywords='wxm-scrapy',
    classifiers=[
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Natural Language :: English',
        "Programming Language :: Python :: 2",
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
		'Programming Language :: Python :: 3.6',
    ],
)

1.2 打包的注释说明、更改记录和版本信息等可以分别写在README.rst、HISTORY.rst和VERSION文件。

      可参考如下项目结构:

1.3 生成打包文件

python setup.py bdist_egg     #生成*.egg文件,支持easy_install安装

 

python setup.py bdist_wininst #生成exe文件

python setup.py sdist         #生成*.zip/*.tar.gz文件,支持pip安装

python setup.py bdist_wheel     #生成.whl文件

1.4 几种安装方法的总结归纳

python setup.py install 
easy_install xx.egg
easy_install xx
pip install xx.whl

 

2、通过pypi-server远程发布

参考链接:https://mp.csdn.net/postedit/82216320

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐