Skip to content
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

Small fixes to make it work with Python 3 #158

Closed
wants to merge 5 commits into from
Closed

Small fixes to make it work with Python 3 #158

wants to merge 5 commits into from

Conversation

kartikmohta
Copy link
Contributor

Note that two tests fail due to internal changes in Python 3:

  • test_iterable_literals_eval: The order of keys in dict changed in Py3
  • test_no_evaluation: ast.literal_eval('5 -2') gives 3 in Py3

Note that two tests fail due to internal changes in Python 3:
- test_iterable_literals_eval: The order of keys in dict changed in Py3
- test_no_evaluation: ast.literal_eval('5 -2') gives 3 in Py3
@rhaschke
Copy link
Contributor

rhaschke commented Sep 12, 2017

I'm wondering whether these changes are really neccessary. Did you have specific issues running xacro with python3? Running the unittests on my side, I don't see any issues.
Sorry, the unittests didn't yet used python3 on my side. Now, I'm getting some errors too ;-)

@kartikmohta
Copy link
Contributor Author

cStringIO and dict.iteritems are not present in Python 3, so these changes are required.

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Additionally to your requested changes, I had to
import xml.dom.minidom
in xmlutils.py. Strange, that you didn't notice that issue.

@@ -950,7 +950,7 @@ def process_doc(doc,
if do_check_order and symbols.redefined:
warning("Document is incompatible to --inorder processing.")
warning("The following properties were redefined after usage:")
for k, v in symbols.redefined.iteritems():
for k, v in symbols.redefined.items():
Copy link
Contributor

Choose a reason for hiding this comment

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

Although iteritems() is more efficient than items() in python2, I think for the sake of simplicity, we can switch to items().

@@ -50,7 +50,7 @@
this_dir_cwd = os.getcwd()
os.chdir(cur_dir)
# Remove this dir from path
sys.path = filter(lambda a: a not in [this_dir, this_dir_cwd], sys.path)
sys.path = [a for a in sys.path if a not in [this_dir, this_dir_cwd]]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is definitely more pythonic ;-)

@@ -31,6 +31,7 @@
# Maintainer: Morgan Quigley <morgan@osrfoundation.org>

import xml
Copy link
Contributor

Choose a reason for hiding this comment

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

The "import xml" can be removed then.

Parsing of number and boolean literals was done with ast.literal_eval().
However, since python3 this function evaluates expressions like "5 -3"
as the number result and not a string anymore.
Hence resort to explicit type-casting to int, float, or boolean.
@rhaschke
Copy link
Contributor

As soon as #161 is merged, I will add some more commits, cleanup and re-issue as a new PR.
I fixed everything for python3 already, such that the unittests pass:
https://travis-ci.org/ubi-agni/xacro

@rhaschke rhaschke mentioned this pull request Sep 15, 2017
@codebot
Copy link
Contributor

codebot commented Sep 15, 2017

I believe all these changes (and more) were incorporated into #163, which just merged. Thanks @kartikmohta and @rhaschke for iterating on this! Cheers

@codebot codebot closed this Sep 15, 2017
@kartikmohta kartikmohta deleted the fix/python3 branch October 10, 2017 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants