如何使用setup.py?

时间:2017-01-13 14:50:46

标签: setup.py pypi readme

我希望在PyPI的模块包中加入一个README.md文件,以便我的setup.py中的函数可以读取它。但是,对我来说,如何让setup.py及相关基础架构实际包含README.md文件并不明显。

我在我的包中添加了一个MANIFEST.in文件,该文件本身列出了README.md,我已将setuptools.setup参数include_package_data设置为True但这还没有工作

manifest.in

junkmodule.py
junkmodule_script.py
LICENSE
MANIFEST.in
README.md
setup.py

setup.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import pypandoc
import setuptools

def main():

    setuptools.setup(
        name                 = "junkmodule",
        version              = "2017.01.13.1416",
        description          = "junk testing module",
        long_description     = pypandoc.convert("README.md", "rst"),
        url                  = "https://github.com/user/junkmodule",
        author               = "LRH",
        author_email         = "lhr@psern.ch",
        license              = "GPLv3",
        include_package_data = True,
        py_modules           = [
                               "junkmodule"
                               ],
        install_requires     = [
                               "numpy"
                               ],
        scripts              = [
                               "junkmodule_script.py"
                               ],
        entry_points         = """
            [console_scripts]
            junkmodule = junkmodule:junkmodule
        """
    )

if __name__ == "__main__":
    main()

我用来注册并将模块上传到PyPI的命令如下:

python setup.py register -r https://pypi.python.org/pypi
python setup.py sdist upload -r https://pypi.python.org/pypi

1 个答案:

答案 0 :(得分:1)

我在我的模块中使用它,试试:

import pypandoc


try:
    description=pypandoc.convert('README.md', 'rst')
except (IOError, ImportError):
    description=open('README.md').read()