如何向PyPi分发类型提示?

gaq*_*qzi 6 python setuptools

我一直致力于为响应库添加Python 3.5类型提示.但是当我测试制作发行版时,sdist或者bdist_wheel它没有安装我的.pyi文件.我可以看到它是分发的一部分,但它不会比这更进一步.

你可以在这里看到我在我的回购中得到的东西:https://github.com/gaqzi/responses/tree/feature/type-hints-file

我读过PEP484,它提到存根文件应该是可分发的.但我似乎无法弄清楚如何.:)

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

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

% 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)
Run Code Online (Sandbox Code Playgroud)

我安装完包后得到了这个:

% 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
Run Code Online (Sandbox Code Playgroud)

Ste*_*alt 8

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

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

  • 如果你想使用 `find_packages`: package_data={package: ["py.typed", "*.pyi", "**/*.pyi"] for package in setuptools.find_packages()} (3认同)
  • 您还可以通配所有 .pyi 文件:`["py.typed", "*.pyi", "**/*.pyi"]`。 (2认同)