Skip to content

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

Merged
merged 2 commits into from
Apr 17, 2018
Merged

Conversation

cmonr
Copy link
Contributor

@cmonr cmonr commented Apr 10, 2018

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

@@ -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\'', '\'')
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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)">]

Copy link
Contributor

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...

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EH, not that important.

theotherjimmy
theotherjimmy previously approved these changes Apr 10, 2018
@theotherjimmy
Copy link
Contributor

/morph build

jsonschema's error.message returns either u' or ' in strings depending on the python version.
@cmonr
Copy link
Contributor Author

cmonr commented Apr 10, 2018

Restarting CI since commit came after build command.

/morph build

@mbed-ci
Copy link

mbed-ci commented Apr 10, 2018

Build : SUCCESS

Build number : 1712
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6592/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Apr 10, 2018

@cmonr cmonr changed the title Modifies tools to run in Python 3 Updates tools to be runnable in Python 3 Apr 11, 2018
@mbed-ci
Copy link

mbed-ci commented Apr 12, 2018

@cmonr cmonr merged commit 934101e into ARMmbed:master Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants