-
Notifications
You must be signed in to change notification settings - Fork 3k
Updates tools to be runnable in Python 3 #6592
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
Conversation
tools/config/__init__.py
Outdated
@@ -393,7 +393,7 @@ def format_validation_error(self, error, path): | |||
return self.format_validation_error(error.context[0], path) | |||
else: | |||
return "in {} element {}: {}".format( | |||
path, str(".".join(str(p) for p in error.absolute_path)), error.message) | |||
path, str(".".join(str(p) for p in error.absolute_path)), error.message).replace('u\'', '\'') |
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.
I'd like to see this done another way, possibly without the outer str
.
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.
diff --git a/tools/config/__init__.py b/tools/config/__init__.py
index 04677215e..cbfc980af 100644
--- a/tools/config/__init__.py
+++ b/tools/config/__init__.py
@@ -393,7 +393,7 @@ class Config(object):
return self.format_validation_error(error.context[0], path)
else:
return "in {} element {}: {}".format(
- path, str(".".join(str(p) for p in error.absolute_path)), error.message)
+ path, ".".join(str(p) for p in error.absolute_path), error.message)
def __init__(self, tgt, top_level_dirs=None, app_config=None):
"""Construct a mbed configuration
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.
I feel like I'm missing something. Implementing the above diff does not appear to work across Py versions.
In Py2, the error returned looks like:
[<Validation Error: "Additional properties are not allowed (u'unknown_key' was unexpected)">]
In Py3:
[<Validation Error: "Additional properties are not allowed ('unknown_key' was unexpected)">]
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.
Oh dang it. That's a string that's coming directly from jsonschema. We may have to allow both versions...
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.
Also, for reference, error.message
is typed as a string in this function, which from what I understand, the u'
is already a part of the variable.
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.
Oh dang it. That's a string that's coming directly from jsonschema.
Yeah. It does it's own internal conversion to support both Py versions.
We may have to allow both versions...
Are you referring to having to support both within json parsing, or just for the particular tests?
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.
Alright, can we move the .replace
to the error.message
then? I don't want to accidentally replace more than we want to.
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.
EH, not that important.
/morph build |
jsonschema's error.message returns either u' or ' in strings depending on the python version.
Restarting CI since commit came after build command. /morph build |
Build : SUCCESSBuild number : 1712 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 1345 |
Test : SUCCESSBuild number : 1517 |
Description
Modifies tools to complete Python 3 porting.
Tested using the following command within two Python virtual environments (Python 2.7.14 and 3.6.4):
reset && find . -name *pyc -delete && clear && PYTHONPATH=. coverage run -a -m pytest tools/test
Pull request type
[ ] Fix
[X] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change