You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I would appreciate that pip search <module> has the following options:
(1) not only by name and summary but just by name
(2) exact matiching by name (with case insensitiveness)
Any better idea?
Describe the solution you'd like
--- pip/_internal/commands/search.py.orig+++ pip/_internal/commands/search.py@@ -38,6 +38,14 @@
metavar='URL',
default=PyPI.pypi_url,
help='Base URL of Python Package Index (default %default)')
+ self.cmd_opts.add_option(+ '-n', '--name',+ action="store_true", default=False, dest='matchName',+ help='Search for packages by name only')+ self.cmd_opts.add_option(+ '-e', '--exact',+ action="store_true", default=False, dest='exactName',+ help='Search for packages by exactly-matched name')
self.parser.insert_option_group(0, self.cmd_opts)
@@ -52,7 +60,7 @@
if sys.stdout.isatty():
terminal_width = get_terminal_size()[0]
- print_results(hits, terminal_width=terminal_width)+ print_results(hits, options, terminal_width=terminal_width)
if pypi_hits:
return SUCCESS
return NO_MATCHES_FOUND
@@ -62,7 +70,13 @@
with self._build_session(options) as session:
transport = PipXmlrpcTransport(index_url, session)
pypi = xmlrpc_client.ServerProxy(index_url, transport)
- hits = pypi.search({'name': query, 'summary': query}, 'or')+ if options.matchName or options.exactName:+ hits = pypi.search({'name': query})+ if options.exactName:+ hits = filter(+ lambda hit: in_case_insensitive(hit['name'], query), hits)+ else:+ hits = pypi.search({'name': query, 'summary': query}, 'or')
return hits
@@ -94,7 +108,7 @@
return list(packages.values())
-def print_results(hits, name_column_width=None, terminal_width=None):+def print_results(hits, options, name_column_width=None, terminal_width=None):
if not hits:
return
if name_column_width is None:
@@ -117,19 +131,32 @@
line = '%-*s - %s' % (name_column_width,
'%s (%s)' % (name, latest), summary)
+ if options.exactName:+ line += '\n%-*s %s' % (name_column_width, '',+ '%s/%s' % (PyPI.pypi_url, name))
try:
logger.info(line)
- if name in installed_packages:+ if in_case_insensitive(name, installed_packages):
dist = pkg_resources.get_distribution(name)
with indent_log():
if dist.version == latest:
- logger.info('INSTALLED: %s (latest)', dist.version)+ if options.exactName:+ logger.info('INSTALLED')+ else:+ logger.info('INSTALLED: %s (latest)', dist.version)
else:
logger.info('INSTALLED: %s', dist.version)
- logger.info('LATEST: %s', latest)+ if not options.exactName:+ logger.info('LATEST: %s', latest)+ elif options.exactName:+ with indent_log():+ logger.info('NOT INSTALLED')
except UnicodeEncodeError:
pass
def highest_version(versions):
return max(versions, key=parse_version)
++def in_case_insensitive(x, list):+ return x.lower() in [y.lower() for y in list]
The text was updated successfully, but these errors were encountered:
I think this information can be useful to expose in search. I do have feedback on the code (avoid use of camelCase, don't pass options and some logic seems incorrect on first glance) but I'll refrain from going into more detail until there's a PR.
I guess it would help to see #4883 -- we're planning to remove 'pip search'.
Hello,
I would appreciate that
pip search <module>
has the following options:(1) not only by name and summary but just by name
(2) exact matiching by name (with case insensitiveness)
Any better idea?
Describe the solution you'd like
The text was updated successfully, but these errors were encountered: