如何向PyPi分发类型提示?

时间:2016-01-02 21:51:21

标签: python setuptools

我一直致力于在响应库中添加Python 3.5类型提示。但是,当我测试分发sdistbdist_wheel时,它不会安装我的.pyi文件。我可以看到它是分发的一部分,但它没有比这更进一步。

您可以在此处查看我的回购邮件:https://github.com/gaqzi/responses/tree/feature/type-hints-file

我读过PEP484 mentions that stub files should be distributable.但我似乎无法弄清楚如何。 :)

是否存在问题,因为响应无法创建包?它只是一个模块文件,这就是为什么它没有正确添加?

我在构建软件包时看到的内容:

% python setup.py sdist
running sdist
running egg_info
writing requirements to responses.egg-info/requires.txt
writing top-level names to responses.egg-info/top_level.txt
writing responses.egg-info/PKG-INFO
writing dependency_links to responses.egg-info/dependency_links.txt
reading manifest file 'responses.egg-info/SOURCES.txt'
writing manifest file 'responses.egg-info/SOURCES.txt'
running check
warning: check: missing meta-data: if 'author' supplied, 'author_email' must be supplied too
creating responses-0.6.0
creating responses-0.6.0/responses.egg-info
making hard links in responses-0.6.0...
hard linking README.rst -> responses-0.6.0
hard linking responses.py -> responses-0.6.0
hard linking responses.pyi -> responses-0.6.0
hard linking setup.cfg -> responses-0.6.0
hard linking setup.py -> responses-0.6.0
hard linking responses.egg-info/PKG-INFO -> responses-0.6.0/responses.egg-info
hard linking responses.egg-info/SOURCES.txt -> responses-0.6.0/responses.egg-info
hard linking responses.egg-info/dependency_links.txt -> responses-0.6.0/responses.egg-info
hard linking responses.egg-info/not-zip-safe -> responses-0.6.0/responses.egg-info
hard linking responses.egg-info/requires.txt -> responses-0.6.0/responses.egg-info
hard linking responses.egg-info/top_level.txt -> responses-0.6.0/responses.egg-info
copying setup.cfg -> responses-0.6.0
Writing responses-0.6.0/setup.cfg
Creating tar archive
removing 'responses-0.6.0' (and everything under it)

安装好包装后,我得到了这个:

% pip install dist/responses-0.6.0.tar.gz
[...snip...]
Installing collected packages: responses
Successfully installed responses-0.6.0
% pwd
/Users/ba/.virtualenvs/responses/lib/python3.5/site-packages
% ls responses*
responses.py

responses-0.6.0.dist-info:
DESCRIPTION.rst METADATA        RECORD          WHEEL           metadata.json   top_level.txt

1 个答案:

答案 0 :(得分:1)

根据the mypy docs,您应将T作为参数传递给package_data={"my_package": ["py.typed", "foo.pyi"]}中的setup。请注意,setup.py是从要分发的软件包根目录到目录的相对路径。 存根文件(docs)。

我创建了一个示例存储库,您可以在https://github.com/SKalt/stub_distrib_demo上对其进行测试。

相关问题