Skip to content

Commit

Permalink
itervalues be gone.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Mar 24, 2022
1 parent 9334532 commit cc01014
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 97 deletions.
4 changes: 2 additions & 2 deletions conda/base/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from os.path import join
import struct

from ..common.compat import itervalues, on_win, six_with_metaclass
from ..common.compat import on_win, six_with_metaclass

PREFIX_PLACEHOLDER = ('/opt/anaconda1anaconda2'
# this is intentionally split into parts, such that running
Expand Down Expand Up @@ -325,7 +325,7 @@ def __str__(self):
}

NAMESPACE_PACKAGE_NAMES = frozenset(NAMESPACES_MAP)
NAMESPACES = frozenset(itervalues(NAMESPACES_MAP))
NAMESPACES = frozenset(NAMESPACES_MAP.values())

# Namespace arbiters of uniqueness
# global: some repository established by Anaconda, Inc. and conda-forge
Expand Down
4 changes: 2 additions & 2 deletions conda/base/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .._vendor.boltons.setutils import IndexedSet
from .._vendor.frozendict import frozendict
from .._vendor.toolz import concat, concatv, unique
from ..common.compat import NoneType, iteritems, itervalues, odict, on_win
from ..common.compat import NoneType, iteritems, odict, on_win
from ..common.configuration import (Configuration, ConfigurationLoadError, MapParameter,
ParameterLoader, PrimitiveParameter, SequenceParameter,
ValidationError)
Expand Down Expand Up @@ -720,7 +720,7 @@ def custom_channels(self):
custom_channels = (Channel.make_simple_channel(self.channel_alias, url, name)
for name, url in iteritems(self._custom_channels))
channels_from_multichannels = concat(channel for channel
in itervalues(self.custom_multichannels))
in self.custom_multichannels.values())
all_channels = odict((x.name, x) for x in (ch for ch in concatv(
channels_from_multichannels,
custom_channels,
Expand Down
4 changes: 2 additions & 2 deletions conda/cli/main_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..base.constants import (ChannelPriority, DepsModifier, PathConflict, SafetyChecks,
UpdateModifier, SatSolverChoice, ExperimentalSolverChoice)
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
from ..common.configuration import pretty_list, pretty_map
from ..common.io import timeout
from ..common.serialize import yaml, yaml_round_trip_dump, yaml_round_trip_load
Expand Down Expand Up @@ -163,7 +163,7 @@ def execute_config(args, parser):
if 'custom_channels' in d:
d['custom_channels'] = {
channel.name: "%s://%s" % (channel.scheme, channel.location)
for channel in itervalues(d['custom_channels'])
for channel in d['custom_channels'].values()
}
if 'custom_multichannels' in d:
from ..common.io import dashlist
Expand Down
4 changes: 2 additions & 2 deletions conda/cli/main_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .common import print_envs_list, stdout_json
from .. import CONDA_PACKAGE_ROOT, __version__ as conda_version
from ..base.context import conda_in_private_env, context, env_name, sys_rc_path, user_rc_path
from ..common.compat import iteritems, itervalues, on_win
from ..common.compat import iteritems, on_win
from ..common.url import mask_anaconda_token
from ..core.index import _supplement_index_with_system
from ..models.channel import all_channel_urls, offline_keep
Expand Down Expand Up @@ -91,7 +91,7 @@ def print_package_info(packages):
if context.json:
stdout_json({package: results[package] for package in packages})
else:
for result in itervalues(results):
for result in results.values():
for prec in result:
pretty_package(prec)

Expand Down
3 changes: 0 additions & 3 deletions conda/common/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def encode_arguments(arguments):
# equivalent functions
# #############################

def itervalues(d, **kw):
return iter(d.values(**kw))

def iteritems(d, **kw):
return iter(d.items(**kw))

Expand Down
6 changes: 3 additions & 3 deletions conda/common/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from stat import S_IFDIR, S_IFMT, S_IFREG
import sys

from .compat import isiterable, iteritems, itervalues, odict, primitive_types, scandir
from .compat import isiterable, iteritems, odict, primitive_types, scandir
from .constants import NULL
from .path import expand
from .serialize import yaml_round_trip_load
Expand Down Expand Up @@ -1232,7 +1232,7 @@ def raw_parameters_from_single_source(name, names, raw_parameters):
if numkeys == 0:
return None, None
elif numkeys == 1:
return next(itervalues(matches)), None
return next(matches.values()), None
elif name in keys:
return matches[name], MultipleKeysError(
raw_parameters[next(iter(keys))].source, keys, name)
Expand Down Expand Up @@ -1381,7 +1381,7 @@ def collect_all(self):
validation_errors = odict()
for source in self.raw_data:
typed_values[source], validation_errors[source] = self.check_source(source)
raise_errors(tuple(chain.from_iterable(itervalues(validation_errors))))
raise_errors(tuple(chain.from_iterable(validation_errors.values()))))
return odict((k, v) for k, v in iteritems(typed_values) if v)

def describe_parameter(self, parameter_name):
Expand Down
3 changes: 1 addition & 2 deletions conda/common/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from itertools import chain

from ._logic import Clauses as _Clauses, FALSE, TRUE
from .compat import itervalues


# TODO: We may want to turn the user-facing {TRUE,FALSE} values into an Enum and
Expand Down Expand Up @@ -203,7 +202,7 @@ def LinearBound(self, equation, lo, hi, preprocess=True, polarity=None, name=Non
# in case of duplicate literal -> coefficient mappings, always take the last one
equation = {named_lit: coeff for coeff, named_lit in equation}
named_literals = list(equation.keys())
coefficients = list(itervalues(equation))
coefficients = list(equation.values())
return self._eval(
self._clauses.LinearBound,
(named_literals,), (coefficients, lo, hi, preprocess), polarity, name,
Expand Down
4 changes: 2 additions & 2 deletions conda/common/pkg_formats/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import warnings

from ... import CondaError
from ..compat import StringIO, itervalues, odict, open, scandir
from ..compat import StringIO, odict, open, scandir
from ..path import (
get_python_site_packages_short_path, pyc_path, win_path_ok, get_major_minor_version,
)
Expand Down Expand Up @@ -329,7 +329,7 @@ def pyspec_to_norm_req(pyspec):
"python_version": self.python_version,
}
depends.update(
pyspec_to_norm_req(pyspec) for pyspec in concat(itervalues(marker_groups))
pyspec_to_norm_req(pyspec) for pyspec in concat(marker_groups.values())
if interpret(pyspec.marker, execution_context)
)
constrains = set(pyspec_to_norm_req(pyspec) for pyspec in extras if pyspec.constraints)
Expand Down
5 changes: 2 additions & 3 deletions conda/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from .._vendor.boltons.setutils import IndexedSet
from .._vendor.toolz import concat, concatv
from ..base.context import context
from ..common.compat import itervalues
from ..common.io import ThreadLimitedThreadPoolExecutor, time_recorder
from ..exceptions import ChannelNotAllowed, InvalidSpec
from ..gateways.logging import initialize_logging
Expand Down Expand Up @@ -86,7 +85,7 @@ def fetch_index(channel_urls, use_cache=False, index=None, repodata_fn=context.r

def dist_str_in_index(index, dist_str):
match_spec = MatchSpec.from_dist_str(dist_str)
return any(match_spec.match(prec) for prec in itervalues(index))
return any(match_spec.match(prec) for prec in index.values())


def _supplement_index_with_prefix(index, prefix):
Expand Down Expand Up @@ -315,7 +314,7 @@ def push_record(record):

# add feature records for the solver
known_features = set()
for rec in itervalues(reduced_index):
for rec in reduced_index.values():
known_features.update(concatv(rec.track_features, rec.features))
known_features.update(context.track_features)
for ftr_str in known_features:
Expand Down
22 changes: 11 additions & 11 deletions conda/core/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ..base.constants import DEFAULTS_CHANNEL_NAME, PREFIX_MAGIC_FILE, SafetyChecks
from ..base.context import context
from ..cli.common import confirm_yn
from ..common.compat import ensure_text_type, iteritems, itervalues, odict, on_win
from ..common.compat import ensure_text_type, iteritems, odict, on_win
from ..common.io import Spinner, dashlist, time_recorder
from ..common.io import DummyExecutor, ThreadLimitedThreadPoolExecutor
from ..common.path import (explode_directories, get_all_directories, get_major_minor_version,
Expand Down Expand Up @@ -164,7 +164,7 @@ def __init__(self, *setups):
self.prefix_setups = odict((stp.target_prefix, stp) for stp in setups)
self.prefix_action_groups = odict()

for stp in itervalues(self.prefix_setups):
for stp in self.prefix_setups.values():
log.info("initializing UnlinkLinkTransaction with\n"
" target_prefix: %s\n"
" unlink_precs:\n"
Expand All @@ -188,9 +188,9 @@ def __init__(self, *setups):
@property
def nothing_to_do(self):
return (
not any((stp.unlink_precs or stp.link_precs) for stp in itervalues(self.prefix_setups))
not any((stp.unlink_precs or stp.link_precs) for stp in self.prefix_setups.values())
and all(is_conda_environment(stp.target_prefix)
for stp in itervalues(self.prefix_setups))
for stp in self.prefix_setups.values())
)

def download_and_extract(self):
Expand All @@ -212,7 +212,7 @@ def prepare(self):

with Spinner("Preparing transaction", not context.verbosity and not context.quiet,
context.json):
for stp in itervalues(self.prefix_setups):
for stp in self.prefix_setups.values():
grps = self._prepare(self.transaction_context, stp.target_prefix,
stp.unlink_precs, stp.link_precs,
stp.remove_specs, stp.update_specs,
Expand Down Expand Up @@ -278,7 +278,7 @@ def execute(self):

assert not context.dry_run
try:
self._execute(tuple(concat(interleave(itervalues(self.prefix_action_groups)))))
self._execute(tuple(concat(interleave(self.prefix_action_groups.values()))))
finally:
rm_rf(self.transaction_context['temp_dir'])

Expand All @@ -289,7 +289,7 @@ def _get_pfe(self):
elif not self.prefix_setups:
self._pfe = pfe = ProgressiveFetchExtract(())
else:
link_precs = set(concat(stp.link_precs for stp in itervalues(self.prefix_setups)))
link_precs = set(concat(stp.link_precs for stp in self.prefix_setups.values()))
self._pfe = pfe = ProgressiveFetchExtract(link_precs)
return pfe

Expand Down Expand Up @@ -536,7 +536,7 @@ def _verify_transaction_level(prefix_setups):
# TODO: Verification 4

conda_prefixes = (join(context.root_prefix, 'envs', '_conda_'), context.root_prefix)
conda_setups = tuple(setup for setup in itervalues(prefix_setups)
conda_setups = tuple(setup for setup in prefix_setups.values()
if setup.target_prefix in conda_prefixes)

conda_unlinked = any(prec.name == 'conda'
Expand Down Expand Up @@ -588,13 +588,13 @@ def _verify_transaction_level(prefix_setups):

# Verification 3. enforce disallowed_packages
disallowed = tuple(MatchSpec(s) for s in context.disallowed_packages)
for prefix_setup in itervalues(prefix_setups):
for prefix_setup in prefix_setups.values():
for prec in prefix_setup.link_precs:
if any(d.match(prec) for d in disallowed):
yield DisallowedPackageError(prec)

# Verification 5. make sure conda-meta/history for each prefix is writable
for prefix_setup in itervalues(prefix_setups):
for prefix_setup in prefix_setups.values():
test_path = join(prefix_setup.target_prefix, PREFIX_MAGIC_FILE)
test_path_existed = lexists(test_path)
dir_existed = None
Expand All @@ -620,7 +620,7 @@ def _verify(self, prefix_setups, prefix_action_groups):

exceptions = []
for exc in self.verify_executor.map(UnlinkLinkTransaction._verify_individual_level,
itervalues(prefix_action_groups)):
prefix_action_groups.values()):
if exc:
exceptions.extend(exc)
for exc in self.verify_executor.map(
Expand Down
16 changes: 9 additions & 7 deletions conda/core/package_cache_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ..base.constants import (CONDA_PACKAGE_EXTENSIONS, CONDA_PACKAGE_EXTENSION_V1,
CONDA_PACKAGE_EXTENSION_V2, PACKAGE_CACHE_MAGIC_FILE)
from ..base.context import context
from ..common.compat import iteritems, itervalues, odict, scandir
from ..common.compat import iteritems, odict, scandir
from ..common.constants import NULL
from ..common.io import ProgressBar, time_recorder
from ..common.path import expand, strip_pkg_extension, url_to_path
Expand All @@ -44,6 +44,7 @@
except NameError:
FileNotFoundError = IOError


class PackageCacheType(type):
"""
This metaclass does basic caching of PackageCache instance objects.
Expand Down Expand Up @@ -122,11 +123,12 @@ def query(self, package_ref_or_match_spec):
if isinstance(param, str):
param = MatchSpec(param)
if isinstance(param, MatchSpec):
return (pcrec for pcrec in itervalues(self._package_cache_records)
return (pcrec for pcrec in self._package_cache_records.values()
if param.match(pcrec))
else:
assert isinstance(param, PackageRecord)
return (pcrec for pcrec in itervalues(self._package_cache_records) if pcrec == param)
return (pcrec for pcrec in self._package_cache_records.values()
if pcrec == param)

def iter_records(self):
return iter(self._package_cache_records)
Expand Down Expand Up @@ -192,7 +194,7 @@ def all_caches_writable_first(cls, pkgs_dirs=None):
@classmethod
def get_all_extracted_entries(cls):
package_caches = (cls(pd) for pd in context.pkgs_dirs)
return tuple(pc_entry for pc_entry in concat(map(itervalues, package_caches))
return tuple(pc_entry for pc_entry in concat((package_cache.values() for package_cache in package_caches))
if pc_entry.is_extracted)

@classmethod
Expand Down Expand Up @@ -231,7 +233,7 @@ def tarball_file_in_this_cache(self, tarball_path, md5sum=None):
tarball_full_path, md5sum = self._clean_tarball_path_and_get_md5sum(tarball_path, md5sum)
tarball_basename = basename(tarball_full_path)
pc_entry = first(
(pc_entry for pc_entry in itervalues(self)),
(pc_entry for pc_entry in self.values()),
key=lambda pce: pce.tarball_basename == tarball_basename and pce.md5 == md5sum
)
return pc_entry
Expand Down Expand Up @@ -613,11 +615,11 @@ def prepare(self):

@property
def cache_actions(self):
return tuple(axns[0] for axns in itervalues(self.paired_actions) if axns[0])
return tuple(axns[0] for axns in self.paired_actions.values() if axns[0])

@property
def extract_actions(self):
return tuple(axns[1] for axns in itervalues(self.paired_actions) if axns[1])
return tuple(axns[1] for axns in self.paired_actions.values() if axns[1])

def execute(self):
if self._executed:
Expand Down
8 changes: 4 additions & 4 deletions conda/core/prefix_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..auxlib.exceptions import ValidationError
from ..base.constants import CONDA_PACKAGE_EXTENSIONS, PREFIX_MAGIC_FILE, CONDA_ENV_VARS_UNSET_VAR
from ..base.context import context
from ..common.compat import itervalues, odict, scandir
from ..common.compat import odict, scandir
from ..common.constants import NULL
from ..common.io import time_recorder
from ..common.path import get_python_site_packages_short_path, win_path_ok
Expand Down Expand Up @@ -135,15 +135,15 @@ def get(self, package_name, default=NULL):
raise

def iter_records(self):
return itervalues(self._prefix_records)
return self._prefix_records.values()

def iter_records_sorted(self):
prefix_graph = PrefixGraph(self.iter_records())
return iter(prefix_graph.graph)

def all_subdir_urls(self):
subdir_urls = set()
for prefix_record in itervalues(self._prefix_records):
for prefix_record in self.iter_records():
subdir_url = prefix_record.channel.subdir_url
if subdir_url and subdir_url not in subdir_urls:
log.debug("adding subdir url %s for %s", subdir_url, prefix_record)
Expand Down Expand Up @@ -212,7 +212,7 @@ def _has_python(self):
def _python_pkg_record(self):
"""Return the prefix record for the package python."""
return next(
(prefix_record for prefix_record in itervalues(self.__prefix_records)
(prefix_record for prefix_record in self.__prefix_records.values()
if prefix_record.name == 'python'),
None
)
Expand Down
Loading

0 comments on commit cc01014

Please sign in to comment.