使用 pip 搜索如何工作? [英] How does searching with pip work?

查看:79
本文介绍了使用 pip 搜索如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我对这个问题很认真.如何使用 pip 进行搜索?

Yes, I'm dead serious with this question. How does searching with pip work?

关键字search 的文档是指https://pip.pypa.io/en/stable/user_guide/#searching-for-packages 上的pip 搜索参考" 这只是一个参考.

The documentation of the keyword search refers to a "pip search reference" at https://pip.pypa.io/en/stable/user_guide/#searching-for-packages which is everything but a reference.

我无法从搜索尝试中得出搜索是如何工作的结论.例如.如果我搜索exec",我会得到各种结果,例如 exec-pypeline (0.4.2) - 一个令人难以置信的 python 包.我什至得到包名与exec"无关的结果,只要描述中包含exec"一词.

I can't conclude from search attempts how searching works. E.g. if I search for "exec" I get a variety of results such as exec-pypeline (0.4.2) - an incredible python package. I even get results with package names that have nothing to do with "exec" as long as the term "exec" is in the description.

但奇怪的是,尽管其中一个包的名称中包含 exec,但我没有在列表中看到我自己的包之一.现在仅此一项就可以让我们得出结论,pip(至少)会在包描述(我的包没有)中搜索完整的搜索词.

But strangely I don't see one of my own packages in the list though one of the packages contains exec in it's name. That alone now would lead us to the conclusion that pip (at least) searches for complete search terms in the package description (which my package doesn't have).

但是基于这个假设,如果我搜索包描述中提供的其他术语,我也不会列出我的包.这也适用于其他软件包:例如如果我搜索项目",我不会在结果集中得到 flask-macros,尽管在​​ flask-macros 的描述中明确存在术语项目".因此,由于这与上述假设相矛盾,这显然不是搜索的工作方式.

But building on that assumption if I search for other terms that are provided in the package description I don't get my package listed either. And that applies to other packages as well: E.g. if I search for "projects" I don't get flask-macros in the result set though the term "projects" clearly exists in the description of flask-macros. So as this contradicts the assumption above this is clearly not the way how searching works.

有趣的是,我可以搜索macro"并得到flask-macros",但如果我搜索macr",则找不到flask-macros".

And interestingly I can search for "macro" and get "flask-macros" as a result, but if I search for "macr" "flask-macros" is not found.

那么 pip 究竟是如何进行搜索的呢?在哪里可以找到合适的参考资料?

So how exactly is searching performed by pip? Where can a suitable reference be found for this?

推荐答案

pip search 查找包含在分发名称分发摘要中的子字符串.我在任何地方都看不到这个记录,并通过按照 源代码直接.

pip search looks for substring contained in the distribution name or the distribution summary. I can not see this documented anywhere, and found it by following the command in the source code directly.

2010 年 2 月的搜索功能代码仍在使用旧的 xmlrpc_client.有 issue395 来改变这一点,自 2011 年以来开放,因为 XML-RPC API 是现在认为是遗留问题,不应使用.有点令人惊讶的是,端点并没有在 pypi-legacy 到仓库移动中被弃用,因为 传统路线仍然存在.

The code for the search feature, which dates from Feb 2010, is still using an old xmlrpc_client. There is issue395 to change this, open since 2011, since the XML-RPC API is now considered legacy and should not be used. Somewhat surprisingly, the endpoint was not deprecated in the pypi-legacy to warehouse move, as the legacy routes are still there.

flask-macros 没有出现在搜索project"中,因为这是一个太常见的搜索词.只返回 100 个结果,,用于处理对那些 PyPI 搜索路由的请求.请注意,最近 PR3827 中的数量从 1000 减少.

flask-macros did not show up in a search for "project" because this is too common a search term. Only 100 results are returned, this is a hardcoded limit in the elasticsearch view which handles the requests to those PyPI search routes. Note that this was reduced from 1000 fairly recently in PR3827.

直接使用 API 客户端进行搜索的代码:

Code to do a search with an API client directly:

import xmlrpc.client

client = xmlrpc.client.ServerProxy('https://pypi.org/pypi')
query = 'project'
results = client.search({'name': query, 'summary': query}, 'or')
print(len(results), 'results returned')
for result in sorted(results, key=lambda data: data['name'].lower()):
    print(result)

现在记录了 100 个结果限制这里.

edit: The 100 result limit is now documented here.

这篇关于使用 pip 搜索如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆