diff --git a/src/rez/bind/_pymodule.py b/src/rez/bind/_pymodule.py index 35dabcfa3..b80926848 100644 --- a/src/rez/bind/_pymodule.py +++ b/src/rez/bind/_pymodule.py @@ -113,7 +113,7 @@ def make_root(variant, root): else: pkg.commands = commands - for key, value in extra_attrs.iteritems(): + for key, value in extra_attrs.items(): pkg[key] = value return pkg.installed_variants diff --git a/src/rez/bind/python.py b/src/rez/bind/python.py index 3e17a7dd0..b0c17d6ed 100644 --- a/src/rez/bind/python.py +++ b/src/rez/bind/python.py @@ -71,7 +71,7 @@ def make_root(variant, root): if builtin_paths: pypath = make_dirs(root, "python") - for dirname, srcpath in builtin_paths.iteritems(): + for dirname, srcpath in builtin_paths.items(): destpath = os.path.join(pypath, dirname) log("Copying builtins from %s to %s..." % (srcpath, destpath)) shutil.copytree(srcpath, destpath) diff --git a/src/rez/build_system.py b/src/rez/build_system.py index f61312945..51a394b2c 100644 --- a/src/rez/build_system.py +++ b/src/rez/build_system.py @@ -260,7 +260,7 @@ def set_standard_vars(cls, executor, context, variant, build_type, build_path=build_path, install_path=install_path) - for var, value in vars.iteritems(): + for var, value in vars.items(): executor.env[var] = value diff --git a/src/rez/cli/_entry_points.py b/src/rez/cli/_entry_points.py index 7b69b0069..2f5cc1a9e 100644 --- a/src/rez/cli/_entry_points.py +++ b/src/rez/cli/_entry_points.py @@ -26,7 +26,7 @@ def get_specifications(): """ specs = {} - for attr, obj in sys.modules[__name__].__dict__.iteritems(): + for attr, obj in sys.modules[__name__].__dict__.items(): scriptname = getattr(obj, "__scriptname__", None) if scriptname: spec = "%s = rez.cli._entry_points:%s" % (scriptname, attr) diff --git a/src/rez/cli/_util.py b/src/rez/cli/_util.py index e69224740..5a68d0ff0 100644 --- a/src/rez/cli/_util.py +++ b/src/rez/cli/_util.py @@ -114,7 +114,7 @@ def format_help(self): if self._subparsers: for action in self._subparsers._actions: if isinstance(action, LazySubParsersAction): - for parser_name, parser in action._name_parser_map.iteritems(): + for parser_name, parser in action._name_parser_map.items(): action._setup_subparser(parser_name, parser) return super(LazyArgumentParser, self).format_help() diff --git a/src/rez/cli/complete.py b/src/rez/cli/complete.py index a9e7266d6..ed62354ee 100644 --- a/src/rez/cli/complete.py +++ b/src/rez/cli/complete.py @@ -55,7 +55,7 @@ def _pop_arg(l, p): subcommand = cmd.split("-", 1)[-1] if subcommand is None: - cmds = [k for k, v in subcommands.iteritems() if not v.get("hidden")] + cmds = [k for k, v in subcommands.items() if not v.get("hidden")] if prefix: cmds = (x for x in cmds if x.startswith(prefix)) diff --git a/src/rez/cli/context.py b/src/rez/cli/context.py index 6eb6af799..d2de50c31 100644 --- a/src/rez/cli/context.py +++ b/src/rez/cli/context.py @@ -163,7 +163,7 @@ def _graph(): env = rc.get_environ(parent_environ=parent_env) if opts.format == 'table': - rows = [x for x in sorted(env.iteritems())] + rows = [x for x in sorted(env.items())] print('\n'.join(columnise(rows))) elif opts.format == 'dict': print(pformat(env)) diff --git a/src/rez/cli/interpret.py b/src/rez/cli/interpret.py index 75587a42b..3069daa61 100644 --- a/src/rez/cli/interpret.py +++ b/src/rez/cli/interpret.py @@ -68,7 +68,7 @@ def command(opts, parser, extra_arg_groups=None): o = ex.get_output() if isinstance(o, dict): if opts.format == "table": - rows = [x for x in sorted(o.iteritems())] + rows = [x for x in sorted(o.items())] print('\n'.join(columnise(rows))) else: print(pformat(o)) diff --git a/src/rez/cli/memcache.py b/src/rez/cli/memcache.py index e8105b27e..1e40dcee9 100644 --- a/src/rez/cli/memcache.py +++ b/src/rez/cli/memcache.py @@ -42,7 +42,7 @@ def poll(client, interval): t, stats = entry dt = t - prev_t - for instance, payload in stats.iteritems(): + for instance, payload in stats.items(): prev_payload = prev_stats.get(instance) if payload and prev_payload: # stats diff --git a/src/rez/config.py b/src/rez/config.py index 894408139..1f60f85ad 100644 --- a/src/rez/config.py +++ b/src/rez/config.py @@ -769,7 +769,7 @@ def _expanded(value): elif isinstance(value, (list, tuple, set)): return [_expanded(x) for x in value] elif isinstance(value, dict): - return dict((k, _expanded(v)) for k, v in value.iteritems()) + return dict((k, _expanded(v)) for k, v in value.items()) else: return value return _expanded(data) @@ -834,7 +834,7 @@ def _load_config_py(filepath): raise ConfigurationError("Error loading configuration from %s: %s" % (filepath, str(e))) - for k, v in g.iteritems(): + for k, v in g.items(): if k != '__builtins__' \ and not ismodule(v) \ and k not in reserved: diff --git a/src/rez/developer_package.py b/src/rez/developer_package.py index a14145a86..2e816ee3b 100644 --- a/src/rez/developer_package.py +++ b/src/rez/developer_package.py @@ -119,7 +119,7 @@ def from_path(cls, path, format=None): package.includes = set() def visit(d): - for k, v in d.iteritems(): + for k, v in d.items(): if isinstance(v, SourceCode): package.includes |= (v.includes or set()) elif isinstance(v, dict): diff --git a/src/rez/package_filter.py b/src/rez/package_filter.py index a97d74f55..e6ceeee40 100644 --- a/src/rez/package_filter.py +++ b/src/rez/package_filter.py @@ -140,9 +140,9 @@ def copy(self): def __and__(self, other): """Combine two filters.""" result = self.copy() - for rule in other._excludes.itervalues(): + for rule in other._excludes.values(): result.add_exclusion(rule) - for rule in other._includes.itervalues(): + for rule in other._includes.values(): result.add_inclusion(rule) return result @@ -160,7 +160,7 @@ def cost(self): float: The approximate cost of the filter. """ total = 0.0 - for family, rules in self._excludes.iteritems(): + for family, rules in self._excludes.items(): cost = sum(x.cost() for x in rules) if family: cost = cost / float(10) @@ -186,7 +186,7 @@ def to_pod(self): ("includes", self._includes)): if dict_: rules = [] - for rules_ in dict_.itervalues(): + for rules_ in dict_.values(): rules.extend(map(str, rules_)) data[namespace] = rules return data diff --git a/src/rez/package_maker__.py b/src/rez/package_maker__.py index 13288e421..0bb0136a6 100644 --- a/src/rez/package_maker__.py +++ b/src/rez/package_maker__.py @@ -137,7 +137,7 @@ def _get_data(self): data.pop("skipped_variants", None) data.pop("package_cls", None) - data = dict((k, v) for k, v in data.iteritems() if v is not None) + data = dict((k, v) for k, v in data.items() if v is not None) return data diff --git a/src/rez/package_order.py b/src/rez/package_order.py index 7d5124b8c..73ccd2eea 100644 --- a/src/rez/package_order.py +++ b/src/rez/package_order.py @@ -158,13 +158,13 @@ def to_pod(self): packages = {} # group package fams by orderer they use - for fam, orderer in self.order_dict.iteritems(): + for fam, orderer in self.order_dict.items(): k = id(orderer) orderers[k] = orderer packages.setdefault(k, set()).add(fam) orderlist = [] - for k, fams in packages.iteritems(): + for k, fams in packages.items(): orderer = orderers[k] data = to_pod(orderer) data["packages"] = sorted(fams) @@ -421,7 +421,7 @@ def register_orderer(cls): # registration of builtin orderers _orderers = {} -for o in globals().values(): +for o in list(globals().values()): register_orderer(o) diff --git a/src/rez/package_py_utils.py b/src/rez/package_py_utils.py index 8ef487613..39b08afc0 100644 --- a/src/rez/package_py_utils.py +++ b/src/rez/package_py_utils.py @@ -116,7 +116,7 @@ def visit_version(version): # 'foo-1+<1_' - '1_' is the next possible version after '1'. So we have # to detect this case and remap the uid-ified wildcard back here too. # - for v, expanded_v in expanded_versions.iteritems(): + for v, expanded_v in expanded_versions.items(): if version == next(v): return next(expanded_v) @@ -133,7 +133,7 @@ def visit_version(version): result = str(req) # do some cleanup so that long uids aren't left in invalid wildcarded strings - for uid, token in wildcard_map.iteritems(): + for uid, token in wildcard_map.items(): result = result.replace(uid, token) # cast back to a Requirement again, then back to a string. This will catch diff --git a/src/rez/package_serialise.py b/src/rez/package_serialise.py index f350cb117..9f094b45d 100644 --- a/src/rez/package_serialise.py +++ b/src/rez/package_serialise.py @@ -112,7 +112,7 @@ def dump_package_data(data, buf, format_=FileFormat.py, skip_attributes=None): if format_ == FileFormat.txt: raise ValueError("'txt' format not supported for packages.") - data_ = dict((k, v) for k, v in data.iteritems() if v is not None) + data_ = dict((k, v) for k, v in data.items() if v is not None) data_ = package_serialise_schema.validate(data_) skip = set(skip_attributes or []) @@ -124,7 +124,7 @@ def dump_package_data(data, buf, format_=FileFormat.py, skip_attributes=None): items.append((key, value)) # remaining are arbitrary keys - for key, value in data_.iteritems(): + for key, value in data_.items(): if key not in skip: items.append((key, value)) diff --git a/src/rez/packages_.py b/src/rez/packages_.py index 2e17d5022..97dcbfaa0 100644 --- a/src/rez/packages_.py +++ b/src/rez/packages_.py @@ -29,7 +29,7 @@ class PackageRepositoryResourceWrapper(ResourceWrapper, StringFormatMixin): def validated_data(self): data = ResourceWrapper.validated_data(self) - data = dict((k, v) for k, v in data.iteritems() if v is not None) + data = dict((k, v) for k, v in data.items() if v is not None) return data @property diff --git a/src/rez/plugin_managers.py b/src/rez/plugin_managers.py index 56891688f..60149308a 100644 --- a/src/rez/plugin_managers.py +++ b/src/rez/plugin_managers.py @@ -189,7 +189,7 @@ def config_schema(self): from rez.config import _plugin_config_dict d = _plugin_config_dict.get(self.type_name, {}) - for name, plugin_class in self.plugin_classes.iteritems(): + for name, plugin_class in self.plugin_classes.items(): if hasattr(plugin_class, "schema_dict") \ and plugin_class.schema_dict: d_ = {name: plugin_class.schema_dict} diff --git a/src/rez/resolved_context.py b/src/rez/resolved_context.py index 4456f5e2f..2176c527a 100644 --- a/src/rez/resolved_context.py +++ b/src/rez/resolved_context.py @@ -843,7 +843,7 @@ def print_resolve_diff(self, other, heading=None): removed_packages = d.get("removed_packages", set()) if newer_packages: - for name, pkgs in newer_packages.iteritems(): + for name, pkgs in newer_packages.items(): this_pkg = pkgs[0] other_pkg = pkgs[-1] diff_str = "(+%d versions)" % (len(pkgs) - 1) @@ -852,7 +852,7 @@ def print_resolve_diff(self, other, heading=None): diff_str)) if older_packages: - for name, pkgs in older_packages.iteritems(): + for name, pkgs in older_packages.items(): this_pkg = pkgs[0] other_pkg = pkgs[-1] diff_str = "(-%d versions)" % (len(pkgs) - 1) @@ -909,7 +909,7 @@ def get_dependency_graph(self): ("fillcolor", node_color), ("style", "filled")] - for name, qname in nodes.iteritems(): + for name, qname in nodes.items(): g.add_node(name, attrs=attrs + [("label", qname)]) for edge in edges: g.add_edge(edge) @@ -991,7 +991,7 @@ def get_tool_variants(self, tool_name): """ variants = set() tools_dict = self.get_tools(request_only=False) - for variant, tools in tools_dict.itervalues(): + for variant, tools in tools_dict.values(): if tool_name in tools: variants.add(variant) return variants @@ -1011,11 +1011,11 @@ def get_conflicting_tools(self, request_only=False): tool_sets = defaultdict(set) tools_dict = self.get_tools(request_only=request_only) - for variant, tools in tools_dict.itervalues(): + for variant, tools in tools_dict.values(): for tool in tools: tool_sets[tool].add(variant) - conflicts = dict((k, v) for k, v in tool_sets.iteritems() if len(v) > 1) + conflicts = dict((k, v) for k, v in tool_sets.items() if len(v) > 1) return conflicts @_on_success @@ -1328,8 +1328,8 @@ def _add(field): requested_timestamp=self.requested_timestamp, building=self.building, caching=self.caching, - implicit_packages=map(str, self.implicit_packages), - package_requests=map(str, self._package_requests), + implicit_packages=list(map(str, self.implicit_packages)), + package_requests=list(map(str, self._package_requests)), package_paths=self.package_paths, default_patch_lock=self.default_patch_lock.name, @@ -1356,7 +1356,7 @@ def _add(field): )) if fields: - data = dict((k, v) for k, v in data.iteritems() if k in fields) + data = dict((k, v) for k, v in data.items() if k in fields) return data @@ -1471,7 +1471,7 @@ def _print_version(value): # track context usage if config.context_tracking_host: - data = dict((k, v) for k, v in d.iteritems() + data = dict((k, v) for k, v in d.items() if k in config.context_tracking_context_fields) r._track_context(data, action="sourced") @@ -1621,7 +1621,7 @@ def _minor_heading(txt): # binds objects such as 'request', which are accessible before a resolve bindings = self._get_pre_resolve_bindings() - for k, v in bindings.iteritems(): + for k, v in bindings.items(): executor.bind(k, v) executor.bind('resolve', VariantsBinding(resolved_pkgs)) diff --git a/src/rez/resolver.py b/src/rez/resolver.py index f17342054..0fd254ed4 100644 --- a/src/rez/resolver.py +++ b/src/rez/resolver.py @@ -251,7 +251,7 @@ def _packages_changed(key, data): def _releases_since_solve(key, data): _, release_times_dict, _ = data - for package_name, release_time in release_times_dict.iteritems(): + for package_name, release_time in release_times_dict.items(): time_ = last_release_times.get(package_name) if time_ is None: time_ = get_last_release_time(package_name, self.package_paths) @@ -267,7 +267,7 @@ def _releases_since_solve(key, data): def _timestamp_is_earlier(key, data): _, release_times_dict, _ = data - for package_name, release_time in release_times_dict.iteritems(): + for package_name, release_time in release_times_dict.items(): if self.timestamp < release_time: self._print("Resolve timestamp (%d) is earlier than %r in " "solve (%d) (entry: %r)", self.timestamp, diff --git a/src/rez/rex.py b/src/rez/rex.py index 73c2202cd..19e5c76a4 100644 --- a/src/rez/rex.py +++ b/src/rez/rex.py @@ -623,7 +623,7 @@ def subprocess(self, args, **subproc_kwargs): if self.manager: self.target_environ.update(self.manager.environ) - shell_mode = not hasattr(args, '__iter__') + shell_mode = isinstance(args, basestring) return popen(args, shell=shell_mode, env=self.target_environ, @@ -961,7 +961,7 @@ def __init__(self, manager): """ self.manager = manager self._var_cache = dict((k, EnvironmentVariable(k, self)) - for k in manager.parent_environ.iterkeys()) + for k in manager.parent_environ.keys()) def keys(self): return self._var_cache.keys() diff --git a/src/rez/serialise.py b/src/rez/serialise.py index 571cf7912..5fbb01a8b 100644 --- a/src/rez/serialise.py +++ b/src/rez/serialise.py @@ -247,7 +247,7 @@ def _load_py(stream, filepath=None): excludes = set(('scope', 'InvalidPackageError', '__builtins__', 'early', 'late', 'include', 'ModifyList')) - for k, v in g.iteritems(): + for k, v in g.items(): if k not in excludes and \ (k not in __builtins__ or __builtins__[k] != v): result[k] = v @@ -360,7 +360,7 @@ def _process(value): def _trim(value): if isinstance(value, dict): - for k, v in value.items(): + for k, v in value.copy().items(): if isfunction(v): if v.__name__ == "preprocess": # preprocess is a special case. It has to stay intact diff --git a/src/rez/shells.py b/src/rez/shells.py index 9bae5992a..8535719c5 100644 --- a/src/rez/shells.py +++ b/src/rez/shells.py @@ -23,7 +23,7 @@ def get_shell_types(): """Returns the available shell types: bash, tcsh etc.""" from rez.plugin_managers import plugin_manager - return plugin_manager.get_plugins('shell') + return list(plugin_manager.get_plugins('shell')) def create_shell(shell=None, **kwargs): diff --git a/src/rez/solver.py b/src/rez/solver.py index 9942ab4df..2aa6f113e 100644 --- a/src/rez/solver.py +++ b/src/rez/solver.py @@ -1113,7 +1113,7 @@ def _get_dependency_order(g, node_list): """Return list of nodes as close as possible to the ordering in node_list, but with child nodes earlier in the list than parents.""" access_ = accessibility(g) - deps = dict((k, set(v) - set([k])) for k, v in access_.iteritems()) + deps = dict((k, set(v) - set([k])) for k, v in access_.items()) nodes = node_list + list(set(g.nodes()) - set(node_list)) ordered_nodes = [] @@ -1615,16 +1615,16 @@ def _add_reduct_node(request): _add_edge(id1, id2) # add extractions - for (src_fam, _), dest_req in self.extractions.iteritems(): + for (src_fam, _), dest_req in self.extractions.items(): id1 = scope_nodes.get(src_fam) if id1 is not None: id2 = _add_request_node(dest_req) _add_edge(id1, id2) # add extraction intersections - extracted_fams = set(x[1] for x in self.extractions.iterkeys()) + extracted_fams = set(x[1] for x in self.extractions.keys()) for fam in extracted_fams: - requests = [v for k, v in self.extractions.iteritems() if k[1] == fam] + requests = [v for k, v in self.extractions.items() if k[1] == fam] if len(requests) > 1: reqlist = RequirementList(requests) if not reqlist.conflict: @@ -1681,7 +1681,7 @@ def _add_reduct_node(request): _add_cycle_edge(id1, id2) # connect leaf-node requests to a matching scope, if any - for request, id1 in request_nodes.iteritems(): + for request, id1 in request_nodes.items(): if not g.neighbors(id1): # leaf node id2 = scope_nodes.get(request.name) if id2 is not None: @@ -1694,7 +1694,7 @@ def _add_reduct_node(request): access_dict = accessibility(g) del_nodes = set() - for n, access_nodes in access_dict.iteritems(): + for n, access_nodes in access_dict.items(): if not (set(access_nodes) & failure_nodes): del_nodes.add(n) @@ -1711,7 +1711,7 @@ def _get_minimal_graph(self): edges = set() scopes = dict((x.package_name, x) for x in self.scopes) - for scope in scopes.itervalues(): + for scope in scopes.values(): variant = scope._get_solved_variant() if variant: nodes.add(variant.name) diff --git a/src/rez/status.py b/src/rez/status.py index f15fa5ac2..66f966e97 100644 --- a/src/rez/status.py +++ b/src/rez/status.py @@ -149,7 +149,7 @@ def print_tools(self, pattern=None, buf=sys.stdout): seen.add(tool) for suite in self.suites: - for tool, d in suite.get_tools().iteritems(): + for tool, d in suite.get_tools().items(): if tool in seen: continue if pattern and not fnmatch(tool, pattern): diff --git a/src/rez/suite.py b/src/rez/suite.py index 6c65d9b00..a024b86fb 100644 --- a/src/rez/suite.py +++ b/src/rez/suite.py @@ -58,7 +58,7 @@ def context_names(self): Reurns: List of strings. """ - return self.contexts.keys() + return list(self.contexts.keys()) @cached_property def tools_path(self): @@ -364,7 +364,7 @@ def get_conflicting_aliases(self): List of strings. """ self._update_tools() - return self.tool_conflicts.keys() + return list(self.tool_conflicts.keys()) def get_alias_conflicts(self, tool_alias): """Get a list of conflicts on the given tool alias. @@ -394,7 +394,7 @@ def validate(self): def to_dict(self): contexts_ = {} - for k, data in self.contexts.iteritems(): + for k, data in self.contexts.items(): data_ = data.copy() if "context" in data_: del data_["context"] @@ -413,7 +413,7 @@ def from_dict(cls, d): s.contexts = d["contexts"] if s.contexts: s.next_priority = max(x["priority"] - for x in s.contexts.itervalues()) + 1 + for x in s.contexts.values()) + 1 else: s.next_priority = 1 return s @@ -462,7 +462,7 @@ def save(self, path, verbose=False): print("creating alias wrappers in %r..." % tools_path) tools = self.get_tools() - for tool_alias, d in tools.iteritems(): + for tool_alias, d in tools.items(): tool_name = d["tool_name"] context_name = d["context_name"] @@ -536,7 +536,7 @@ def print_info(self, buf=sys.stdout, verbose=False): _pr("Suite is empty.") return - context_names = sorted(self.contexts.iterkeys()) + context_names = sorted(self.contexts.keys()) _pr("Suite contains %d contexts:" % len(context_names)) if not verbose: @@ -609,14 +609,14 @@ def _get_row(entry): self._context(context_name) # check context exists context_names = [context_name] else: - context_names = sorted(self.contexts.iterkeys()) + context_names = sorted(self.contexts.keys()) rows = [["TOOL", "ALIASING", "PACKAGE", "CONTEXT", ""], ["----", "--------", "-------", "-------", ""]] colors = [None, None] entries_dict = defaultdict(list) - for d in self.get_tools().itervalues(): + for d in self.get_tools().values(): entries_dict[d["context_name"]].append(d) if verbose: @@ -627,7 +627,7 @@ def _get_row(entry): entries_dict[d["context_name"]].append(d_) # add conflicting tools - for docs in self.tool_conflicts.itervalues(): + for docs in self.tool_conflicts.values(): for d in docs: d_ = d.copy() d_["conflicting"] = True @@ -692,7 +692,7 @@ def _flush_tools(self): def _validate_tool(self, context_name, tool_name): context = self.context(context_name) context_tools = context.get_tools(request_only=True) - for _, tool_names in context_tools.itervalues(): + for _, tool_names in context_tools.values(): if tool_name in tool_names: return raise SuiteError("No such tool %r in context %r" @@ -715,7 +715,7 @@ def _update_tools(self): context = self.context(context_name) context_tools = context.get_tools(request_only=True) - for variant, tool_names in context_tools.itervalues(): + for variant, tool_names in context_tools.values(): for tool_name in tool_names: alias = tool_aliases.get(tool_name) if alias is None: diff --git a/src/rez/tests/test_copy_package.py b/src/rez/tests/test_copy_package.py index 1114de53b..f1bfb18cc 100644 --- a/src/rez/tests/test_copy_package.py +++ b/src/rez/tests/test_copy_package.py @@ -298,7 +298,7 @@ def test_7(self): # check copied variant contains expected timestamp dest_pkg = self._get_dest_pkg("floob", "1.2.0") - for k, v in overrides.iteritems(): + for k, v in list(overrides.items()): self.assertEqual(getattr(dest_pkg, k), v) def test_8(self): diff --git a/src/rez/tests/test_resources_.py b/src/rez/tests/test_resources_.py index c016f2a38..9ab28b3eb 100644 --- a/src/rez/tests/test_resources_.py +++ b/src/rez/tests/test_resources_.py @@ -237,7 +237,7 @@ def _validate(resource, expected_data): # after full validation, each attrib should validate exactly once. # Those with value None are optional and missing attributes, so were # never validated. - expected_validations = dict((k, 1) for k, v in expected_data.iteritems() + expected_validations = dict((k, 1) for k, v in list(expected_data.items()) if v is not None) self.assertEqual(resource.validations, expected_validations) diff --git a/src/rez/util.py b/src/rez/util.py index c2126492a..27d0f9495 100644 --- a/src/rez/util.py +++ b/src/rez/util.py @@ -152,7 +152,7 @@ def get_close_pkgs(pkg, pkgs, fuzziness=0.4): for pkg_, r in (matches + fam_matches): d[pkg_] = d.get(pkg_, 0.0) + r - combined = [(k, v * 0.5) for k, v in d.iteritems()] + combined = [(k, v * 0.5) for k, v in d.items()] return sorted(combined, key=lambda x: -x[1]) diff --git a/src/rez/utils/backcompat.py b/src/rez/utils/backcompat.py index c0f800f9b..0023fa12c 100644 --- a/src/rez/utils/backcompat.py +++ b/src/rez/utils/backcompat.py @@ -22,7 +22,7 @@ def convert_old_variant_handle(handle_dict): old_variables = handle_dict.get("variables", {}) variables = dict(repository_type="filesystem") - for old_key, key in variant_key_conversions.iteritems(): + for old_key, key in variant_key_conversions.items(): value = old_variables.get(old_key) #if value is not None: variables[key] = value diff --git a/src/rez/utils/data_utils.py b/src/rez/utils/data_utils.py index 6a78305b8..6525b91a2 100644 --- a/src/rez/utils/data_utils.py +++ b/src/rez/utils/data_utils.py @@ -37,7 +37,7 @@ def apply(self, v): def remove_nones(**kwargs): """Return diict copy with nones removed. """ - return dict((k, v) for k, v in kwargs.iteritems() if v is not None) + return dict((k, v) for k, v in kwargs.items() if v is not None) def deep_update(dict1, dict2): @@ -51,7 +51,7 @@ def flatten(v): if isinstance(v, ModifyList): return v.apply([]) elif isinstance(v, dict): - return dict((k, flatten(v_)) for k, v_ in v.iteritems()) + return dict((k, flatten(v_)) for k, v_ in v.items()) else: return v @@ -65,11 +65,11 @@ def merge(v1, v2): else: return flatten(v2) - for k1, v1 in dict1.iteritems(): + for k1, v1 in dict1.items(): if k1 not in dict2: dict1[k1] = flatten(v1) - for k2, v2 in dict2.iteritems(): + for k2, v2 in dict2.items(): v1 = dict1.get(k2) if v1 is KeyError: @@ -88,7 +88,7 @@ def deep_del(data, fn): """ result = {} - for k, v in data.iteritems(): + for k, v in data.items(): if not fn(v): if isinstance(v, dict): result[k] = deep_del(v, fn) @@ -115,7 +115,7 @@ def _diff(d1_, d2_, namespace): removed = [] changed = [] - for k1, v1 in d1_.iteritems(): + for k1, v1 in d1_.items(): if k1 not in d2_: removed.append(namespace + [k1]) else: @@ -130,7 +130,7 @@ def _diff(d1_, d2_, namespace): else: changed.append(namespace + [k1]) - for k2 in d2_.iterkeys(): + for k2 in d2_.keys(): if k2 not in d1_: added.append(namespace + [k2]) @@ -335,7 +335,7 @@ def convert_dicts(d, to_class=AttrDictWrapper, from_class=dict): Converted data as `to_class` instance. """ d_ = to_class() - for key, value in d.iteritems(): + for key, value in d.items(): if isinstance(value, from_class): d_[key] = convert_dicts(value, to_class=to_class, from_class=from_class) @@ -508,7 +508,7 @@ def _defined(x): if schema: schema_dict = schema._schema - for key, key_schema in schema_dict.iteritems(): + for key, key_schema in schema_dict.items(): optional = isinstance(key, Optional) while isinstance(key, Schema): key = key._schema diff --git a/src/rez/utils/formatting.py b/src/rez/utils/formatting.py index 41656596e..00c394364 100644 --- a/src/rez/utils/formatting.py +++ b/src/rez/utils/formatting.py @@ -269,7 +269,7 @@ def dict_to_attributes_code(dict_): str. """ lines = [] - for key, value in dict_.iteritems(): + for key, value in dict_.items(): if isinstance(value, dict): txt = dict_to_attributes_code(value) lines_ = txt.split('\n') diff --git a/src/rez/utils/graph_utils.py b/src/rez/utils/graph_utils.py index 416a2d93c..afb735982 100644 --- a/src/rez/utils/graph_utils.py +++ b/src/rez/utils/graph_utils.py @@ -107,7 +107,7 @@ def conv(value): value = tuple(list(edge) + [label]) if label else edge d_edges.setdefault(tuple(attrs), []).append(tuple(value)) - doc = dict(nodes=d_nodes.items(), edges=d_edges.items()) + doc = dict(nodes=list(d_nodes.items()), edges=list(d_edges.items())) contents = str(doc) return contents @@ -171,7 +171,7 @@ def prune_graph(graph_str, package_name): g = read_dot(graph_str) nodes = set() - for node, attrs in g.node_attr.iteritems(): + for node, attrs in g.node_attr.items(): attr = [x for x in attrs if x[0] == "label"] if attr: label = attr[0][1] diff --git a/src/rez/utils/json.py b/src/rez/utils/json.py index f12a6ecc5..4d2a1ce91 100644 --- a/src/rez/utils/json.py +++ b/src/rez/utils/json.py @@ -28,7 +28,7 @@ def _byteify(input, ignore_dicts=False): elif isinstance(input, dict) and not ignore_dicts: return { _byteify(k, ignore_dicts=True): _byteify(v, True) - for k, v in input.iteritems() + for k, v in input.items() } else: return input diff --git a/src/rez/utils/pip.py b/src/rez/utils/pip.py index 738e241bc..377623e77 100644 --- a/src/rez/utils/pip.py +++ b/src/rez/utils/pip.py @@ -266,7 +266,7 @@ def fmt(txt): ) # convert each spec into rez equivalent - ranges = map(convert_spec, specifier) + ranges = list(map(convert_spec, specifier)) # AND together ranges total_range = VersionRange(ranges[0]) @@ -560,7 +560,7 @@ def get_marker_sys_requirements(marker): # note: packaging lib already delimits with whitespace marker_parts = marker.split() - for varname, sys_reqs in sys_requires_lookup.iteritems(): + for varname, sys_reqs in sys_requires_lookup.items(): if varname in marker_parts: sys_requires.update(sys_reqs) diff --git a/src/rez/utils/platform_mapped.py b/src/rez/utils/platform_mapped.py index 668f5b1ae..b63c7b182 100644 --- a/src/rez/utils/platform_mapped.py +++ b/src/rez/utils/platform_mapped.py @@ -33,7 +33,7 @@ def inner(*args, **kwargs): # The function name is used as primary key entry = config.platform_map.get(func.__name__) if entry: - for key, value in entry.iteritems(): + for key, value in entry.items(): result, changes = re.subn(key, value, result) if changes > 0: break diff --git a/src/rez/utils/schema.py b/src/rez/utils/schema.py index b6af6c3e7..58bd65084 100644 --- a/src/rez/utils/schema.py +++ b/src/rez/utils/schema.py @@ -33,7 +33,7 @@ def _get_leaf(value): dict_ = schema._schema assert isinstance(dict_, dict) - for key in dict_.iterkeys(): + for key in dict_.keys(): key_ = _get_leaf(key) if isinstance(key_, basestring): keys.add(key_) @@ -60,7 +60,7 @@ def dict_to_schema(schema_dict, required, allow_custom_keys=True, modifier=None) def _to(value): if isinstance(value, dict): d = {} - for k, v in value.iteritems(): + for k, v in value.items(): if isinstance(k, basestring): k = Required(k) if required else Optional(k) d[k] = _to(v) diff --git a/src/rez/utils/scope.py b/src/rez/utils/scope.py index b644b28d2..cde3a46d9 100644 --- a/src/rez/utils/scope.py +++ b/src/rez/utils/scope.py @@ -91,7 +91,7 @@ def _create_child_attribute(self, attr): def to_dict(self): """Get an equivalent dict representation.""" d = {} - for k, v in self.__dict__["data"].iteritems(): + for k, v in self.__dict__["data"].items(): if isinstance(v, RecursiveAttribute): d[k] = v.to_dict() else: @@ -108,7 +108,7 @@ def update(self, data): self._update(data) def _update(self, data): - for k, v in data.iteritems(): + for k, v in data.items(): if isinstance(v, dict): v = RecursiveAttribute(v) self.__dict__["data"][k] = v @@ -140,7 +140,7 @@ def __exit__(self, *args): d = self.__dict__ locals_ = sys._getframe(1).f_locals self_locals = d["locals"] - for k, v in locals_.iteritems(): + for k, v in locals_.items(): if not (k.startswith("__") and k.endswith("__")) \ and (k not in self_locals or v != self_locals[k]) \ and not isinstance(v, _Scope): diff --git a/src/rezgui/objects/ProcessTrackerThread.py b/src/rezgui/objects/ProcessTrackerThread.py index a6b9f2509..b98e21a21 100644 --- a/src/rezgui/objects/ProcessTrackerThread.py +++ b/src/rezgui/objects/ProcessTrackerThread.py @@ -33,7 +33,7 @@ def running_instances(self, context, process_name): is the epoch time the process was added. """ handle = (id(context), process_name) - it = self.processes.get(handle, {}).itervalues() + it = self.processes.get(handle, {}).values() entries = [x for x in it if x[0].poll() is None] return entries @@ -71,8 +71,8 @@ def _update(self): # rebuild proc list to iterate over if self.processes and not self.proc_list: - for (context_id, process_name), d in self.processes.iteritems(): - for proc, _ in d.itervalues(): + for (context_id, process_name), d in self.processes.items(): + for proc, _ in d.values(): entry = (context_id, process_name, proc) self.proc_list.append(entry) diff --git a/src/rezgui/widgets/ContextSettingsWidget.py b/src/rezgui/widgets/ContextSettingsWidget.py index adca7837c..d9a21cf96 100644 --- a/src/rezgui/widgets/ContextSettingsWidget.py +++ b/src/rezgui/widgets/ContextSettingsWidget.py @@ -40,12 +40,12 @@ def __init__(self, context_model=None, attributes=None, parent=None): super(ContextSettingsWidget, self).__init__(parent) ContextViewMixin.__init__(self, context_model) - self.schema_keys = set(self.schema_dict.iterkeys()) + self.schema_keys = set(self.schema_dict.keys()) if attributes: self.schema_keys &= set(attributes) assert self.schema_keys - schema_dict = dict((k, v) for k, v in self.schema_dict.iteritems() + schema_dict = dict((k, v) for k, v in self.schema_dict.items() if k in self.schema_keys) self.schema = Schema(schema_dict) @@ -129,7 +129,7 @@ def set_defaults(self): "implicit_packages": implicits, "package_filter": package_filter, "caching": caching} - data = dict((k, v) for k, v in data.iteritems() + data = dict((k, v) for k, v in data.items() if k in self.schema_keys) self._set_text(data) @@ -143,7 +143,7 @@ def _update_text(self): "implicit_packages": implicits, "package_filter": model.package_filter, "caching": model.caching} - data = dict((k, v) for k, v in data.iteritems() + data = dict((k, v) for k, v in data.items() if k in self.schema_keys) self._set_text(data) @@ -152,7 +152,7 @@ def _update_text(self): def _set_text(self, data): lines = [] - for key, value in data.iteritems(): + for key, value in data.items(): lines.append('') txt = yaml.dump({key: value}, default_flow_style=False) title = self.titles.get(key) diff --git a/src/rezgui/widgets/ContextTableWidget.py b/src/rezgui/widgets/ContextTableWidget.py index a2e23aecb..a4c4c2819 100644 --- a/src/rezgui/widgets/ContextTableWidget.py +++ b/src/rezgui/widgets/ContextTableWidget.py @@ -455,7 +455,7 @@ def _contextChanged(self, flags=0): if flags & ContextModel.LOCKS_CHANGED and self._show_effective_request: update_request_columns[0] = self.context_model - for column, context_model in update_request_columns.iteritems(): + for column, context_model in update_request_columns.items(): self._update_request_column(column, context_model) # set column headers @@ -498,7 +498,7 @@ def _update_request_column(self, column, context_model): row += 1 d = context_model.get_lock_requests() - for lock, requests in d.iteritems(): + for lock, requests in d.items(): for request in requests: request_str = str(request) self._set_effective_package_cell(row, column, request_str, lock.name) diff --git a/src/rezgui/widgets/PackageTabWidget.py b/src/rezgui/widgets/PackageTabWidget.py index d919926ec..9061e7fea 100644 --- a/src/rezgui/widgets/PackageTabWidget.py +++ b/src/rezgui/widgets/PackageTabWidget.py @@ -83,7 +83,7 @@ def _set_packagebase(self, variant): prev_index = self.currentIndex() disabled_tabs = set() - for d in self.tabs.itervalues(): + for d in self.tabs.values(): index = d["index"] if (not d["lazy"]) or (self.currentIndex() == index): self.widget(index).set_variant(variant) diff --git a/src/rezgui/widgets/PackageVersionsTable.py b/src/rezgui/widgets/PackageVersionsTable.py index 31fcf158e..f3689fb49 100644 --- a/src/rezgui/widgets/PackageVersionsTable.py +++ b/src/rezgui/widgets/PackageVersionsTable.py @@ -50,7 +50,7 @@ def select_version(self, version_range): """ row = -1 version = None - for i, package in self.packages.iteritems(): + for i, package in self.packages.items(): if package.version in version_range \ and (version is None or version < package.version): version = package.version diff --git a/src/rezplugins/build_system/cmake.py b/src/rezplugins/build_system/cmake.py index fe8dd8978..6904309cf 100644 --- a/src/rezplugins/build_system/cmake.py +++ b/src/rezplugins/build_system/cmake.py @@ -56,7 +56,7 @@ class CMakeBuildSystem(BuildSystem): schema_dict = { "build_target": Or(*build_targets), - "build_system": Or(*build_systems.keys()), + "build_system": Or(*list(build_systems.keys())), "cmake_args": [basestring], "cmake_binary": Or(None, basestring), "make_binary": Or(None, basestring) @@ -83,7 +83,7 @@ def bind_cli(cls, parser, group): help="set the build target (default: %(default)s).") group.add_argument("--bs", "--cmake-build-system", dest="cmake_build_system", - choices=cls.build_systems.keys(), + choices=list(cls.build_systems.keys()), default=settings.build_system, help="set the cmake build system (default: %(default)s).") diff --git a/src/rezplugins/build_system/custom.py b/src/rezplugins/build_system/custom.py index c3ca1d21c..0a6f7f005 100644 --- a/src/rezplugins/build_system/custom.py +++ b/src/rezplugins/build_system/custom.py @@ -1,6 +1,11 @@ """ Package-defined build command """ +try: + from builtins import str + from builtins import map +except ImportError: + pass from pipes import quote import functools import os.path @@ -136,7 +141,7 @@ def expand(txt): cmd_str = command else: # list command = command + self.build_args - command = map(expand, command) + command = list(map(expand, command)) cmd_str = ' '.join(map(quote, command)) if self.verbose: @@ -158,7 +163,7 @@ def _callback(executor): # write args defined in ./parse_build_args.py out as env vars extra_args = getattr(self.opts.parser, "_rezbuild_extra_args", []) - for key, value in vars(self.opts).iteritems(): + for key, value in list(vars(self.opts).items()): if key in extra_args: varname = "__PARSE_ARG_%s" % key.upper() @@ -166,8 +171,8 @@ def _callback(executor): if isinstance(value, bool): value = 1 if value else 0 elif isinstance(value, (list, tuple)): - value = map(str, value) - value = map(quote, value) + value = list(map(str, value)) + value = list(map(quote, value)) value = ' '.join(value) executor.env[varname] = value diff --git a/src/rezplugins/package_repository/filesystem.py b/src/rezplugins/package_repository/filesystem.py index 6b1a3b92b..8becadbce 100644 --- a/src/rezplugins/package_repository/filesystem.py +++ b/src/rezplugins/package_repository/filesystem.py @@ -377,7 +377,7 @@ def _load(self): overrides = self.parent.version_overrides if overrides: - for range_, data_ in overrides.iteritems(): + for range_, data_ in overrides.items(): if version in range_: data.update(data_) del data["version_overrides"] @@ -1060,7 +1060,7 @@ def _remove_build_keys(obj): # This is done so that variants added to an existing package don't change # attributes such as 'timestamp' or release-related fields like 'revision'. # - for key, value in overrides.iteritems(): + for key, value in overrides.items(): if existing_package: if key not in package_data: package_data[key] = value diff --git a/src/rezplugins/package_repository/memory.py b/src/rezplugins/package_repository/memory.py index 27cb6eb00..88da55073 100644 --- a/src/rezplugins/package_repository/memory.py +++ b/src/rezplugins/package_repository/memory.py @@ -39,7 +39,7 @@ def iter_packages(self): return # versioned packages - for version_str in data.iterkeys(): + for version_str in data.keys(): package = self._repository.get_resource( MemoryPackageResource.key, location=self.location, @@ -174,7 +174,7 @@ def get_package_family(self, name): return None def iter_package_families(self): - for name in self.data.iterkeys(): + for name in self.data.keys(): family = self.get_package_family(name) yield family diff --git a/src/rezplugins/release_hook/command.py b/src/rezplugins/release_hook/command.py index 59644af01..64897fe43 100644 --- a/src/rezplugins/release_hook/command.py +++ b/src/rezplugins/release_hook/command.py @@ -182,7 +182,7 @@ def _execute_commands(self, commands, install_path, package, errors=None, msgs = [] msgs.append("running command: %s" % list2cmdline(toks)) if env: - for key, value in env.iteritems(): + for key, value in env.items(): msgs.append(" with: %s=%s" % (key, value)) if self.settings.print_commands: diff --git a/src/rezplugins/release_hook/emailer.py b/src/rezplugins/release_hook/emailer.py index 7e5a4237d..3dacc0dc9 100644 --- a/src/rezplugins/release_hook/emailer.py +++ b/src/rezplugins/release_hook/emailer.py @@ -130,7 +130,7 @@ def test(value, type_): match = True if filters: - for attr, test_value in test(filters, dict).iteritems(): + for attr, test_value in test(filters, dict).items(): missing = object() value = getattr(self.package, attr, missing) diff --git a/src/rezplugins/release_vcs/hg.py b/src/rezplugins/release_vcs/hg.py index d753a0aa2..7f6ece969 100644 --- a/src/rezplugins/release_vcs/hg.py +++ b/src/rezplugins/release_vcs/hg.py @@ -149,7 +149,7 @@ def get_tags(self, patch=False): # rsplit, once, since we KNOW how the right side should be formatted tags = dict(line.rstrip().rsplit(None, 1) for line in lines if line.strip()) - for tag_name, tag_info in tags.iteritems(): + for tag_name, tag_info in tags.items(): rev, shortnode = tag_info.split(':') tags[tag_name] = {'rev': rev, 'shortnode': shortnode} return tags