Skip to content

Commit

Permalink
Merge pull request #736 from maxnbk/maxnbk/feat-py3-iterators-conversion
Browse files Browse the repository at this point in the history
py3 iterators conversion
  • Loading branch information
nerdvegas authored Sep 13, 2019
2 parents f5f7781 + 971c15c commit 4eb25f3
Show file tree
Hide file tree
Showing 50 changed files with 118 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/rez/bind/_pymodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/rez/bind/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/rez/build_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/rez/cli/_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/rez/cli/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/rez/cli/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/rez/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/rez/cli/interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/rez/cli/memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/rez/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/rez/developer_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions src/rez/package_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rez/package_maker__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions src/rez/package_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions src/rez/package_py_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/rez/package_serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [])

Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion src/rez/packages_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rez/plugin_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
22 changes: 11 additions & 11 deletions src/rez/resolved_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/rez/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/rez/rex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/rez/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rez/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading

0 comments on commit 4eb25f3

Please sign in to comment.