"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "conda/cli/main_config.py" between
conda-4.6.2.tar.gz and conda-4.6.3.tar.gz

About: Conda is a cross-platform, language-agnostic, system-level binary package manager and ecosystem.

main_config.py  (conda-4.6.2):main_config.py  (conda-4.6.3)
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2012 Anaconda, Inc # Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
from __future__ import absolute_import, division, print_function, unicode_litera ls from __future__ import absolute_import, division, print_function, unicode_litera ls
from collections import OrderedDict from collections import OrderedDict
import json import json
from logging import getLogger
import os import os
from os.path import isfile, join from os.path import isfile, join
import sys import sys
from textwrap import wrap from textwrap import wrap
from .. import CondaError from .. import CondaError
from .._vendor.auxlib.entity import EntityEncoder from .._vendor.auxlib.entity import EntityEncoder
from .._vendor.toolz import concat, groupby from .._vendor.toolz import concat, groupby
from ..base.constants import (ChannelPriority, DepsModifier, PathConflict, Safet yChecks, from ..base.constants import (ChannelPriority, DepsModifier, PathConflict, Safet yChecks,
UpdateModifier) UpdateModifier)
from ..base.context import context, sys_rc_path, user_rc_path from ..base.context import context, sys_rc_path, user_rc_path
from ..common.compat import Mapping, Sequence, isiterable, iteritems, itervalues from ..common.compat import (Mapping, Sequence, isiterable, iteritems, itervalue
, string_types s, string_types,
text_type)
from ..common.configuration import pretty_list, pretty_map from ..common.configuration import pretty_list, pretty_map
from ..common.io import timeout from ..common.io import timeout
from ..common.serialize import yaml, yaml_dump, yaml_load from ..common.serialize import yaml, yaml_dump, yaml_load
def execute(args, parser): def execute(args, parser):
from ..exceptions import CouldntParseError from ..exceptions import CouldntParseError
try: try:
execute_config(args, parser) execute_config(args, parser)
except (CouldntParseError, NotImplementedError) as e: except (CouldntParseError, NotImplementedError) as e:
raise CondaError(e) raise CondaError(e)
skipping to change at line 96 skipping to change at line 98
builder.append('# ###################################################### ') builder.append('# ###################################################### ')
builder.append('# ## {:^48} ##'.format(category)) builder.append('# ## {:^48} ##'.format(category))
builder.append('# ###################################################### ') builder.append('# ###################################################### ')
builder.append('') builder.append('')
builder.extend(concat(parameter_description_builder(name) builder.extend(concat(parameter_description_builder(name)
for name in parameter_names)) for name in parameter_names))
builder.append('') builder.append('')
return '\n'.join(builder) return '\n'.join(builder)
def execute_config(args, parser): def execute_config(args, parser):
stdout_write = getLogger("conda.stdout").info
stderr_write = getLogger("conda.stderr").info
json_warnings = [] json_warnings = []
json_get = {} json_get = {}
if args.show_sources: if args.show_sources:
if context.json: if context.json:
print(json.dumps(context.collect_all(), sort_keys=True, stdout_write(
indent=2, separators=(',', ': '))) json.dumps(context.collect_all(), sort_keys=True, indent=2, sepa
rators=(',', ': '))
)
else: else:
lines = [] lines = []
for source, reprs in iteritems(context.collect_all()): for source, reprs in iteritems(context.collect_all()):
lines.append("==> %s <==" % source) lines.append("==> %s <==" % source)
lines.extend(format_dict(reprs)) lines.extend(format_dict(reprs))
lines.append('') lines.append('')
print('\n'.join(lines)) stdout_write('\n'.join(lines))
return return
if args.show is not None: if args.show is not None:
if args.show: if args.show:
paramater_names = args.show paramater_names = args.show
all_names = context.list_parameters() all_names = context.list_parameters()
not_params = set(paramater_names) - set(all_names) not_params = set(paramater_names) - set(all_names)
if not_params: if not_params:
from ..exceptions import ArgumentError from ..exceptions import ArgumentError
from ..common.io import dashlist from ..common.io import dashlist
raise ArgumentError("Invalid configuration parameters: %s" % das hlist(not_params)) raise ArgumentError("Invalid configuration parameters: %s" % das hlist(not_params))
else: else:
paramater_names = context.list_parameters() paramater_names = context.list_parameters()
d = OrderedDict((key, getattr(context, key)) for key in paramater_names) d = OrderedDict((key, getattr(context, key)) for key in paramater_names)
if context.json: if context.json:
print(json.dumps(d, sort_keys=True, indent=2, separators=(',', ': ') stdout_write(json.dumps(
, d, sort_keys=True, indent=2, separators=(',', ': '), cls=EntityE
cls=EntityEncoder)) ncoder
))
else: else:
# Add in custom formatting # Add in custom formatting
if 'custom_channels' in d: if 'custom_channels' in d:
d['custom_channels'] = { d['custom_channels'] = {
channel.name: "%s://%s" % (channel.scheme, channel.location) channel.name: "%s://%s" % (channel.scheme, channel.location)
for channel in itervalues(d['custom_channels']) for channel in itervalues(d['custom_channels'])
} }
if 'custom_multichannels' in d: if 'custom_multichannels' in d:
from ..common.io import dashlist from ..common.io import dashlist
d['custom_multichannels'] = { d['custom_multichannels'] = {
multichannel_name: dashlist(channels, indent=4) multichannel_name: dashlist(channels, indent=4)
for multichannel_name, channels in iteritems(d['custom_multi channels']) for multichannel_name, channels in iteritems(d['custom_multi channels'])
} }
print('\n'.join(format_dict(d))) stdout_write('\n'.join(format_dict(d)))
context.validate_configuration() context.validate_configuration()
return return
if args.describe is not None: if args.describe is not None:
if args.describe: if args.describe:
paramater_names = args.describe paramater_names = args.describe
all_names = context.list_parameters() all_names = context.list_parameters()
not_params = set(paramater_names) - set(all_names) not_params = set(paramater_names) - set(all_names)
if not_params: if not_params:
from ..exceptions import ArgumentError from ..exceptions import ArgumentError
from ..common.io import dashlist from ..common.io import dashlist
raise ArgumentError("Invalid configuration parameters: %s" % das hlist(not_params)) raise ArgumentError("Invalid configuration parameters: %s" % das hlist(not_params))
if context.json: if context.json:
print(json.dumps([context.describe_parameter(name) for name in p stdout_write(json.dumps(
aramater_names], [context.describe_parameter(name) for name in paramater_name
sort_keys=True, indent=2, separators=(',', ': ' s],
), sort_keys=True, indent=2, separators=(',', ': '), cls=Entity
cls=EntityEncoder)) Encoder
))
else: else:
builder = [] builder = []
builder.extend(concat(parameter_description_builder(name) builder.extend(concat(parameter_description_builder(name)
for name in paramater_names)) for name in paramater_names))
print('\n'.join(builder)) stdout_write('\n'.join(builder))
else: else:
if context.json: if context.json:
skip_categories = ('CLI-only', 'Hidden and Undocumented') skip_categories = ('CLI-only', 'Hidden and Undocumented')
paramater_names = sorted(concat( paramater_names = sorted(concat(
parameter_names for category, parameter_names in context.cat egory_map.items() parameter_names for category, parameter_names in context.cat egory_map.items()
if category not in skip_categories if category not in skip_categories
)) ))
print(json.dumps([context.describe_parameter(name) for name in p stdout_write(json.dumps(
aramater_names], [context.describe_parameter(name) for name in paramater_name
sort_keys=True, indent=2, separators=(',', ': ' s],
), sort_keys=True, indent=2, separators=(',', ': '), cls=Entity
cls=EntityEncoder)) Encoder
))
else: else:
print(describe_all_parameters()) stdout_write(describe_all_parameters())
return return
if args.validate: if args.validate:
context.validate_all() context.validate_all()
return return
if args.system: if args.system:
rc_path = sys_rc_path rc_path = sys_rc_path
elif args.env: elif args.env:
if 'CONDA_PREFIX' in os.environ: if 'CONDA_PREFIX' in os.environ:
skipping to change at line 232 skipping to change at line 239
# Get # Get
if args.get is not None: if args.get is not None:
context.validate_all() context.validate_all()
if args.get == []: if args.get == []:
args.get = sorted(rc_config.keys()) args.get = sorted(rc_config.keys())
for key in args.get: for key in args.get:
if key not in primitive_parameters + sequence_parameters: if key not in primitive_parameters + sequence_parameters:
message = "unknown key %s" % key message = "unknown key %s" % key
if not context.json: if not context.json:
print(message, file=sys.stderr) stderr_write(message)
else: else:
json_warnings.append(message) json_warnings.append(message)
continue continue
if key not in rc_config: if key not in rc_config:
continue continue
if context.json: if context.json:
json_get[key] = rc_config[key] json_get[key] = rc_config[key]
continue continue
if isinstance(rc_config[key], (bool, string_types)): if isinstance(rc_config[key], (bool, string_types)):
print("--set", key, rc_config[key]) stdout_write(" ".join(("--set", key, text_type(rc_config[key]))) )
else: # assume the key is a list-type else: # assume the key is a list-type
# Note, since conda config --add prepends, these are printed in # Note, since conda config --add prepends, these are printed in
# the reverse order so that entering them in this order will # the reverse order so that entering them in this order will
# recreate the same file # recreate the same file
items = rc_config.get(key, []) items = rc_config.get(key, [])
numitems = len(items) numitems = len(items)
for q, item in enumerate(reversed(items)): for q, item in enumerate(reversed(items)):
# Use repr so that it can be pasted back in to conda config --add # Use repr so that it can be pasted back in to conda config --add
if key == "channels" and q in (0, numitems-1): if key == "channels" and q in (0, numitems-1):
print("--add", key, repr(item), stdout_write(" ".join((
" # lowest priority" if q == 0 else " # highest "--add", key, repr(item),
priority") " # lowest priority" if q == 0 else " # highest pr
iority"
)))
else: else:
print("--add", key, repr(item)) stdout_write(" ".join(("--add", key, repr(item))))
if args.stdin: if args.stdin:
content = timeout(5, sys.stdin.read) content = timeout(5, sys.stdin.read)
if not content: if not content:
return return
try: try:
parsed = yaml_load(content) parsed = yaml_load(content)
rc_config.update(parsed) rc_config.update(parsed)
except Exception: # pragma: no cover except Exception: # pragma: no cover
from ..exceptions import ParseError from ..exceptions import ParseError
skipping to change at line 290 skipping to change at line 299
from ..exceptions import CouldntParseError from ..exceptions import CouldntParseError
bad = rc_config[key].__class__.__name__ bad = rc_config[key].__class__.__name__
raise CouldntParseError("key %r should be a list, not %s." % (ke y, bad)) raise CouldntParseError("key %r should be a list, not %s." % (ke y, bad))
arglist = rc_config.setdefault(key, []) arglist = rc_config.setdefault(key, [])
if item in arglist: if item in arglist:
# Right now, all list keys should not contain duplicates # Right now, all list keys should not contain duplicates
message = "Warning: '%s' already in '%s' list, moving to the %s" % ( message = "Warning: '%s' already in '%s' list, moving to the %s" % (
item, key, "top" if prepend else "bottom") item, key, "top" if prepend else "bottom")
arglist = rc_config[key] = [p for p in arglist if p != item] arglist = rc_config[key] = [p for p in arglist if p != item]
if not context.json: if not context.json:
print(message, file=sys.stderr) stderr_write(message)
else: else:
json_warnings.append(message) json_warnings.append(message)
arglist.insert(0 if prepend else len(arglist), item) arglist.insert(0 if prepend else len(arglist), item)
# Set # Set
for key, item in args.set: for key, item in args.set:
key, subkey = key.split('.', 1) if '.' in key else (key, None) key, subkey = key.split('.', 1) if '.' in key else (key, None)
if key in primitive_parameters: if key in primitive_parameters:
value = context.typify_parameter(key, item) value = context.typify_parameter(key, item)
rc_config[key] = value rc_config[key] = value
 End of changes. 16 change blocks. 
29 lines changed or deleted 39 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)