gpt4 book ai didi

python - 如何向 PyPi 分发类型提示?

转载 作者:太空狗 更新时间:2023-10-30 01:33:16 25 4
gpt4 key购买 nike

我致力于将 Python 3.5 类型提示添加到响应库中。但是当我测试制作一个发行版时,sdistbdist_wheel,它没有安装我的 .pyi 文件。我可以看到它是发行版的一部分,但仅此而已。

你可以在这里看到我在我的仓库中得到了什么:https://github.com/gaqzi/responses/tree/feature/type-hints-file

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

responses 没有创建包是否有问题?它只是一个模块文件,这就是为什么它没有被正确添加的原因?

构建包时我看到的内容:

% 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

最佳答案

根据 the mypy docs ,你应该将 package_data={"my_package": ["py.typed", "foo.pyi"]} 作为参数传递给 setup in setup. py。请注意,"foo.pyi" 是从要分发的包的根目录到 stub 文件 ( docs )。

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

关于python - 如何向 PyPi 分发类型提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34571088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com