python 从setup.json读取的示例setup.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 从setup.json读取的示例setup.py相关的知识,希望对你有一定的参考价值。

# -*- coding: utf-8 -*-
#
# setup.py
#

SETUP_JSON = 'setup.json'

import io
import json
import os
import sys
from shutil import rmtree
from setuptools import setup, find_packages, Command

HERE = os.path.abspath(os.path.dirname(__file__))


def load_json(path, here=HERE):
    """"""
    with io.open(os.path.join(here, path)) as f:
        return json.load(f)


def get_long_description(path, default='', here=HERE):
    """"""
    long_description = default
    with io.open(os.path.join(here, path), encoding='utf-8') as f:
        long_description = '\n' + f.read()
    return long_description


def get_version(path, key='__version__', here=HERE):
    """"""
    version = {}
    with open(os.path.join(here, path)) as f:
        exec(f.read(), version)
    return version[key]


class Upload(Command):
    """"""

    name = 'upload'
    description = 'Build and publish the package.'
    user_options = []

    @staticmethod
    def status(s):
        """Prints things in bold."""
        print('\033[1m{0}\033[0m'.format(s))

    def initialize_options(self):
        """"""

    def finalize_options(self):
        """"""

    def run(self):
        """"""
        try:
            self.status('Removing previous builds…')
            rmtree(os.path.join(HERE, 'dist'))
        except OSError:
            pass
        self.status('Building Source and Wheel (universal) distribution...')
        os.system(f'{sys.executable} setup.py sdist bdist_wheel --universal')
        self.status('Uploading the package to PyPI via Twine...')
        os.system('twine upload --repository-url https://upload.pypi.org/legacy/ dist/*')
        sys.exit()


if __name__ == '__main__':
    about = load_json(SETUP_JSON)

    about['version'] = get_version(about['version_file'])
    del about['version_file']

    about['long_description'] = get_long_description(about['long_description_file'])
    del about['long_description_file']

    if 'exclude' in about['packages']:
        about['packages'] = find_packages(exclude=tuple(about['packages']['exclude']))

    setup(cmdclass={Upload.name: Upload}, **about)

以上是关于python 从setup.json读取的示例setup.py的主要内容,如果未能解决你的问题,请参考以下文章

python 从NiFi ExecuteScript处理器使用的Python脚本示例,它从传入的流文件中读取第一行。

在python SSHCLient中将文件从远程服务器完全读取到本地机器?

如果没有用minicom打开一次,则无法从串口读取

word文档为啥JAVA流不能直接读取,像WORD,EXCEL这样的文件都要通过第三方的API来读写,在J2SE中怎么做

python之用unittest实现接口参数化示例

Python读取CSV文件