[Piglit] [PATCH 25/34] registry generation: Finish hybridizing
Jordan Justen
jordan.l.justen at intel.com
Sat Feb 21 17:05:35 PST 2015
On 2015-02-20 18:18:12, Dylan Baker wrote:
> registry/gl.py and tests/util/gen_dispatch.py and pretty much
> indistinguishable in purpose, so it makes sense to finsih porting them
> together.
>
> This is actually not very invasive, a few calls to six, and a few cases
> of using forward compatible functions (functools.reduce instead of the
> builtin reduce, which was removed in python3)
>
> The resulting output is exactly the same.
> ---
> registry/gl.py | 16 +++++++++++-----
> tests/util/gen_dispatch.py | 14 ++++++++++++--
> 2 files changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/registry/gl.py b/registry/gl.py
> index f85e393..a22e920 100644
> --- a/registry/gl.py
> +++ b/registry/gl.py
> @@ -30,9 +30,9 @@ import os.path
> import re
> import sys
> import functools
> -
> from copy import copy, deepcopy
>
> +import six
>
> # Export 'debug' so other Piglit modules can easily enable it.
> debug = False
> @@ -261,13 +261,13 @@ class OrderedKeyedSet(object):
> return node[3]
>
> def sort_by_key(self):
> - sorted_items = sorted(self.__map.iteritems())
> + sorted_items = sorted(six.iteritems(self.__map))
> self.clear()
> for item in sorted_items:
> self.add(item[1])
>
> def sort_by_value(self):
> - sorted_values = sorted(self.__map.itervalues())
> + sorted_values = sorted(six.itervalues(self.__map))
> self.clear()
> for value in sorted_values:
> self.add(value)
> @@ -909,7 +909,7 @@ class CommandAliasMap(object):
> def __iter__(self):
> """A sorted iterator over the map's unique CommandAliasSet values."""
> if self.__sorted_unique_values is None:
> - self.__sorted_unique_values = sorted(set(self.__map.itervalues()))
> + self.__sorted_unique_values = sorted(set(six.itervalues(self.__map)))
>
> return iter(self.__sorted_unique_values)
>
> @@ -1111,7 +1111,13 @@ class Enum(object):
> base = 16
> else:
> base = 10
> - self.num_value = long(self.str_value, base)
> +
> + if six.PY2:
> + # long is undefined in python3, and we are aware of that
> + # pylint: disable=undefined-variable
> + self.num_value = long(self.str_value, base)
> + elif six.PY3:
How about?
else:
assert six.PY3
14-25 Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>
> + self.num_value = int(self.str_value, base)
>
> _log_debug('parsed {0}'.format(self))
>
> diff --git a/tests/util/gen_dispatch.py b/tests/util/gen_dispatch.py
> index 4d7d756..98d63fd 100644
> --- a/tests/util/gen_dispatch.py
> +++ b/tests/util/gen_dispatch.py
> @@ -30,8 +30,10 @@ import argparse
> import os.path
> import re
> import sys
> +import functools
> from collections import namedtuple
>
> +import six
> import mako.runtime
> import mako.template
>
> @@ -105,7 +107,15 @@ def render_template(filename, out_dir, **context_vars):
> def fake_whitespace(proto_text):
> if debug:
> print('fake whitespace: before: {0!r}'.format(proto_text))
> - text = unicode(proto_text)
> +
> + if six.PY2:
> + # the unicode function was removed in python3, this will raise a
> + # pylint error, but not in python2
> + # pylint: disable=undefined-variable
> + text = unicode(proto_text)
> + elif six.PY3:
> + text = proto_text
> +
> text = fake_alignment.sub('', text)
> text = fake_tab.sub(' ', text)
> if debug:
> @@ -152,7 +162,7 @@ class EnumCode(object):
> for enum in enum_group.enums
> )
> enums = sorted(enums)
> - enums = reduce(append_enum_if_new_value, enums[1:], [enums[0]])
> + enums = functools.reduce(append_enum_if_new_value, enums[1:], [enums[0]])
> return enums
>
>
> --
> 2.3.0
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
More information about the Piglit
mailing list