[英]How to distribute type hints to PyPi?
我一直致力於向響應庫添加 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)
安裝包后,我得到了這個:
% 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
根據mypy docs ,您應該將package_data={"my_package": ["py.typed", "foo.pyi"]}
作為參數傳遞給setup.py
setup
。 請注意, "foo.pyi"
是從要分發的包的根目錄到存根文件 ( docs ) 的相對路徑。
我已經創建了一個示例存儲庫,您可以在https://github.com/SKalt/stub_distrib_demo 上對此進行測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.