Skip to content

Commit

Permalink
Merge pull request conda#1647 from asmeurer/show-channel-urls
Browse files Browse the repository at this point in the history
Add --show-channel-urls and --no-show-channel-urls command line flags
  • Loading branch information
asmeurer committed Sep 24, 2015
2 parents 159ab95 + 535f15e commit 935d924
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
17 changes: 17 additions & 0 deletions conda/cli/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def add_parser_install(p):
default=not config.update_dependencies,
help="Don't update dependencies (default: %(default)s).",
)
add_parser_show_channel_urls(p)

if 'update' in p.prog:
# I don't know if p.prog is the correct thing to use here but it's the
Expand Down Expand Up @@ -298,6 +299,22 @@ def add_parser_no_pin(p):
help="Ignore pinned file.",
)

def add_parser_show_channel_urls(p):
p.add_argument(
"--show-channel-urls",
action="store_true",
dest="show_channel_urls",
default=config.show_channel_urls,
help="Show channel urls (default: %(default)s).",
)
p.add_argument(
"--no-show-channel-urls",
action="store_false",
dest="show_channel_urls",
default=not config.show_channel_urls,
help="Don't show channel urls (default: %(default)s).",
)

def ensure_override_channels_requires_channel(args, dashc=True, json=False):
if args.override_channels and not (args.channel or args.use_local):
if dashc:
Expand Down
2 changes: 1 addition & 1 deletion conda/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def install(args, parser, command='install'):
if not args.json:
print()
print("Package plan for installation in environment %s:" % prefix)
plan.display_actions(actions, index)
plan.display_actions(actions, index, show_channel_urls=args.show_channel_urls)

if command in {'install', 'update'}:
common.check_write(command, prefix)
Expand Down
13 changes: 8 additions & 5 deletions conda/cli/main_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def configure_parser(sub_parsers):
common.add_parser_help(p)
common.add_parser_prefix(p)
common.add_parser_json(p)
common.add_parser_show_channel_urls(p)
p.add_argument(
'-c', "--canonical",
action="store_true",
Expand Down Expand Up @@ -111,7 +112,7 @@ def get_packages(installed, regex):
yield dist


def list_packages(prefix, installed, regex=None, format='human'):
def list_packages(prefix, installed, regex=None, format='human', show_channel_urls=config.show_channel_urls):
res = 1

result = []
Expand All @@ -130,7 +131,7 @@ def list_packages(prefix, installed, regex=None, format='human'):
features = set(info.get('features', '').split())
disp = '%(name)-25s %(version)-15s %(build)15s' % info
disp += ' %s' % common.disp_features(features)
if config.show_channel_urls:
if show_channel_urls:
disp += ' %s' % config.canonical_channel_name(info.get('url'))
result.append(disp)
except (AttributeError, IOError, KeyError, ValueError) as e:
Expand All @@ -140,7 +141,8 @@ def list_packages(prefix, installed, regex=None, format='human'):
return res, result


def print_packages(prefix, regex=None, format='human', piplist=False, json=False):
def print_packages(prefix, regex=None, format='human', piplist=False,
json=False, show_channel_urls=config.show_channel_urls):
if not isdir(prefix):
common.error_and_exit("""\
Error: environment does not exist: %s
Expand All @@ -160,7 +162,7 @@ def print_packages(prefix, regex=None, format='human', piplist=False, json=False
if piplist and config.use_pip and format == 'human':
add_pip_installed(prefix, installed, json=json)

exitcode, output = list_packages(prefix, installed, regex, format=format)
exitcode, output = list_packages(prefix, installed, regex, format=format, show_channel_urls=show_channel_urls)
if not json:
print('\n'.join(output))
else:
Expand Down Expand Up @@ -200,5 +202,6 @@ def execute(args, parser):
if args.json:
format = 'canonical'

exitcode = print_packages(prefix, regex, format, piplist=args.pip, json=args.json)
exitcode = print_packages(prefix, regex, format, piplist=args.pip,
json=args.json, show_channel_urls=args.show_channel_urls)
sys.exit(exitcode)
10 changes: 6 additions & 4 deletions conda/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ def print_dists(dists_extras):
print(line)


def display_actions(actions, index):
def display_actions(actions, index, show_channel_urls=None):
if show_channel_urls is None:
show_channel_urls = config.show_channel_urls
if actions.get(inst.FETCH):
print("\nThe following packages will be downloaded:\n")

disp_lst = []
for dist in actions[inst.FETCH]:
info = index[dist + '.tar.bz2']
extra = '%15s' % human_bytes(info['size'])
if config.show_channel_urls:
if show_channel_urls:
extra += ' %s' % config.canonical_channel_name(
info.get('channel'))
disp_lst.append((dist, extra))
Expand Down Expand Up @@ -117,13 +119,13 @@ def display_actions(actions, index):
# That's right. I'm using old-style string formatting to generate a
# string with new-style string formatting.
oldfmt[pkg] = '{pkg:<%s} {vers[0]:<%s}' % (maxpkg, maxoldver)
if config.show_channel_urls:
if show_channel_urls:
oldfmt[pkg] += ' {channel[0]:<%s}' % maxoldchannel
if packages[pkg][0]:
newfmt[pkg] = '{vers[1]:<%s}' % maxnewver
else:
newfmt[pkg] = '{pkg:<%s} {vers[1]:<%s}' % (maxpkg, maxnewver)
if config.show_channel_urls:
if show_channel_urls:
newfmt[pkg] += ' {channel[1]:<%s}' % maxnewchannel
# TODO: Should we also care about the old package's link type?
if pkg in linktypes and linktypes[pkg] != install.LINK_HARD:
Expand Down

0 comments on commit 935d924

Please sign in to comment.