How can I 'pip search' for all provided search terms?

2

Is there a way to do an AND on search terms in a pip search?

For example, doing:

pip search django toolbar

seems to show all django related packages, even if they have nothing to do with toolbar.

The best I can do is to workaround with:

pip search django toolbar | grep toolbar | grep django

UPDATE:

this is better:

pip search toolbar | grep django

and makes my question useless

Ciro Santilli 新疆改造中心法轮功六四事件

Posted 2012-11-20T18:46:59.567

Reputation: 5 621

my old workaround was silly, with the new one I see it does not matter if there is no AND: just search for what you think is has less matches, and grep away for each other search term – Ciro Santilli 新疆改造中心法轮功六四事件 – 2012-11-24T17:59:36.907

Answers

2

In short, you can't.

After the installation of pip, I had a look at site-packages/pip-1.2.1-py2.6.egg/pip/commands/search.py, which is where the search command is implemented.

It uses the XML-RPC interface to PyPi, which is documented at http://wiki.python.org/moin/PyPiXmlRpc
We can see that the footprint for the search is search(spec[, operator]). The documentation notes:

Arguments for different fields are combined using either "and" (the default) or "or". Example: search({'name': 'foo', 'description': 'bar'}, 'or'). The results are returned as a list of dicts {'name': package name, 'version': package release version, 'summary': package release summary}

Awesome! So this is where we define the search operator! And and is even the default!

Now back to search.py...

def search(self, query, index_url):
    pypi = xmlrpclib.ServerProxy(index_url, pip.download.xmlrpclib_transport)
    hits = pypi.search({'name': query, 'summary': query}, 'or')
    return hits

And here we see that the 'or' is hardcoded.

Der Hochstapler

Posted 2012-11-20T18:46:59.567

Reputation: 77 228

and might be a better design choice because it is easier to combine several searches than to filter them – Ciro Santilli 新疆改造中心法轮功六四事件 – 2012-11-20T19:15:28.397