本文介绍了在 setup.py 中使用“scripts"关键字的 Python setuptools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 setuptools 了解 Python 打包的工作原理.>

setup() 函数的参数之一是 scripts .该文档没有指定该参数的用途.任何帮助都会很棒!!下面是一些使用脚本的示例代码.

from setuptools import setup, find_packages设置(name="HelloWorld",版本=0.1",包=find_packages(),脚本=['say_hello.py'],# 项目使用reStructuredText,所以确保docutils得到# 在目标机器上安装或升级install_requires=['docutils>=0.3'],包数据={# 如果任何包包含 *.txt 或 *.rst 文件,请包含它们:'': ['*.txt', '*.rst'],# 并包含在 'hello' 包中找到的任何 *.msg 文件:'你好': ['*.msg'],},# 上传到 PyPI 的元数据作者 =我",author_email="me@example.com",description="这是一个示例包",许可证=PSF",关键字="你好世界示例示例",url="http://example.com/HelloWorld/", # 项目主页,如果有的话# 还可以包括 long_description、download_url、分类器等.)
解决方案

它主要用于定义您将在包中使用的附加脚本.以下是参考链接的片段:

#!/usr/bin/env python导入最有趣的打印 funniest.joke()

然后我们可以像这样在 setup() 中声明脚本:

设置(...脚本=['bin/最有趣的笑话'],...)

当我们安装软件包时,setuptools 会将脚本复制到我们的 PATH 并使其可供一般使用.这具有可推广到的优点非 python 脚本,以及:最有趣的笑话可能是一个 shell 脚本,或者完全不同的东西.

参考:http://python-packaging.readthedocs.io/en/latest/command-line-scripts.html#the-scripts-keyword-argument

I am trying to understand how python packaging works using setuptools.

One of the arguments for setup() function is scripts .The documentation doesn't specify what that argument is used for. Any help would be great!!Here is some sample code where scripts is used.

from setuptools import setup, find_packages
setup(
    name="HelloWorld",
    version="0.1",
    packages=find_packages(),
    scripts=['say_hello.py'],

    # Project uses reStructuredText, so ensure that the docutils get
    # installed or upgraded on the target machine
    install_requires=['docutils>=0.3'],

    package_data={
        # If any package contains *.txt or *.rst files, include them:
        '': ['*.txt', '*.rst'],
        # And include any *.msg files found in the 'hello' package, too:
        'hello': ['*.msg'],
    },

    # metadata for upload to PyPI
    author="Me",
    author_email="me@example.com",
    description="This is an Example Package",
    license="PSF",
    keywords="hello world example examples",
    url="http://example.com/HelloWorld/",   # project home page, if any

    # could also include long_description, download_url, classifiers, etc.
)
解决方案

Its mainly used to define the additional scripts you'll be using in your package. Here's a snippet from the reference link:

#!/usr/bin/env python
import funniest print funniest.joke()

Then we can declare the script in setup() like this:

setup(
    ...
    scripts=['bin/funniest-joke'],
    ...
    )

Reference: http://python-packaging.readthedocs.io/en/latest/command-line-scripts.html#the-scripts-keyword-argument

这篇关于在 setup.py 中使用“scripts"关键字的 Python setuptools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 01:25