Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
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 Nov 24 '12 at 17:59

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
and might be a better design choice because it is easier to combine several searches than to filter them –  Ciro Santilli Nov 20 '12 at 19:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.