-
Notifications
You must be signed in to change notification settings - Fork 56
Migrate some essential runtime files to Python 3 #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
We need to use portions of the runtime as part of the migration. Splitting out into a separate changelist shouold expedite the work.
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
| from third_party import six |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| from third_party import six |
| # inject them into a module so they run as globals | ||
| def register_functions(module, template_function_map): | ||
| for t_name, f_name in template_function_map.iteritems(): | ||
| for t_name, f_name in six.iteritems(template_function_map): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use the python2/python3 compatible iter(<map_value>) approach here (combined with next suggestion).
| for t_name, f_name in six.iteritems(template_function_map): | |
| for t_name in iter(template_function_map): |
| def register_functions(module, template_function_map): | ||
| for t_name, f_name in template_function_map.iteritems(): | ||
| for t_name, f_name in six.iteritems(template_function_map): | ||
| f_func = import_module_symbol(f_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| f_func = import_module_symbol(f_name) | |
| f_func = import_module_symbol(template_fucntion_map[tname]) |
| import logging | ||
| import weakref | ||
|
|
||
| from third_party.six.moves import builtins |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| from third_party.six.moves import builtins | |
| # Python3 moved "__builtin__" to "builtins". | |
| try: | |
| import builtins | |
| except ImportError: | |
| import __builtin__ as builtins | |
| # a few helpful filter functions | ||
|
|
||
| import functools | ||
| import types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import types | |
| import sys | |
| import types |
|
|
||
| from spitfire import runtime | ||
| from spitfire.runtime import udn | ||
| from third_party import six |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| from third_party import six |
| """Replace special characters '&', '<' and '>' by SGML entities.""" | ||
| value = simple_str_filter(value) | ||
| if isinstance(value, basestring): | ||
| if isinstance(value, six.string_types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simple_str_filter always calls str()
| if isinstance(value, six.string_types): | |
| if isinstance(value, str): |
| from spitfire.runtime import udn | ||
| from third_party import six | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if sys.version_info[0] == 2 | |
| SAFE_VALUE_TYPES = (str, unicode, int, long, float, | |
| runtime.UndefinedPlaceholder) | |
| else: | |
| SAFE_VALUE_TYPES = (str, int, float, runtime.UndefinedPlaceholder) | |
| """Deprecated - use simple_str_filter instead.""" | ||
| if isinstance(value, (str, unicode, int, long, float, | ||
| runtime.UndefinedPlaceholder)): | ||
| if isinstance(value, (str, six.text_type, float, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
| if isinstance(value, (str, six.text_type, float, | |
| if isinstance(value, SAFE_VALUE_TYPES): |
| if isinstance(value, (str, unicode, int, long, float, | ||
| runtime.UndefinedPlaceholder)): | ||
| if isinstance(value, (str, six.text_type, float, | ||
| runtime.UndefinedPlaceholder) + six.integer_types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| runtime.UndefinedPlaceholder) + six.integer_types): |
| """Return a string if the input type is something primitive.""" | ||
| if isinstance(value, (str, unicode, int, long, float, | ||
| runtime.UndefinedPlaceholder)): | ||
| if isinstance(value, (str, unicode, float, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
| if isinstance(value, (str, unicode, float, | |
| if isinstance(value, SAFE_VALUE_TYPES): |
| if isinstance(value, (str, unicode, int, long, float, | ||
| runtime.UndefinedPlaceholder)): | ||
| if isinstance(value, (str, unicode, float, | ||
| runtime.UndefinedPlaceholder) + six.integer_types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| runtime.UndefinedPlaceholder) + six.integer_types): |
nicksay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions to avoid needing six.
We need to use portions of the runtime as part of the migration. Splitting out into a separate changelist should help expedite the work.