Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Python 3 compat #66

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

douglas-raillard-arm
Copy link

@douglas-raillard-arm douglas-raillard-arm commented Sep 7, 2018

Add Python 3 support using the past package, and its 2to3-based futurize script: https://pypi.org/project/past/

TODO: update the required version of TRAPpy once its Python 3 PR is merged

TypeError in TRAPpy are fixed by its Python 3 PR and will go away once merged

Run the futurize tool to convert to python 2 and 3 compatible code:
https://pypi.org/project/future/

$ futurize -wn -u **.py
Choose between true div and floor div and remove references to old_div.
Since all files now have a from __future__ import division statement,
both division operators (/ and //) will behave the same in Python 2 and
3 (with the Python 3 behavior).
Add a standard set of __future__ imports so that all the code will
behave consistently accross the whole library. Otherwise, new code may
be caught by a missing "from __future__ import division" and would get a
different behavior than in another file of Bart.
* Add dependency on "future" package. It is used to provide Python-3-like
helpers and modules that will run on both Python 2 and Python 3
* Add Python 3 as supported language
* Use setup.py in .travis.yml so the requirements are aligned as much as
possible
Since a number of builtins like zip and map are returning iterators in
Python 3 (instead of lists in Python 2), 2to3 adds calls to list()
everywhere. Remove most of them as they are usually not needed.
2to3 seems to convert dict.iteritems() to iter(dict.items()) since
.items() will return an iterator in Python 3 and a list in Python 2.
This distinction is irrelevant in most places, so remove useless calls
to iter().
In Python 3, class.method returns a function an not an unbound method as
it used to in Python 2. This makes inspect.ismethod(class.method) False,
so replace inspect.ismethod() with callable() builtin that will work in
both cases.

Also remove the use of dir() since it is meant for interactive use.
Replace with inspect.getmembers().

Improve the debugging experience by using a function instead of a lambda
to make it easier to find.
Since integers don't have limited size in Python 3, sys.maxint is gone.
Replace its use by sys.maxsize, which is the closest approximation.
TRAPpy does not require separate trace.txt and trace.raw.txt anymore.
@douglas-raillard-arm
Copy link
Author

That PR has been used for a few months now successfully using lisa-next (https://github.com/ARM-software/lisa/tree/next). As we seem to be the main user, I'll merge that PR in a week unless somebody screams :-)

@douglas-raillard-arm douglas-raillard-arm changed the title Python 3 compat [RFC] Python 3 compat Feb 1, 2019
@sinkap
Copy link
Collaborator

sinkap commented Feb 1, 2019 via email

@sinkap
Copy link
Collaborator

sinkap commented Feb 1, 2019

Does this have build errors still?

@douglas-raillard-arm
Copy link
Author

douglas-raillard-arm commented Feb 1, 2019

Let's update setup.py to see ...
EDIT: trappy version on PyPI is still stuck at 5.9 (2016), so there is no way I can mandate the right version in bart's setup.py until a new version is officially released.

@douglas-raillard-arm
Copy link
Author

Looks like the tests are passing, with an intermittent failure:

======================================================================
ERROR: Test that the result of getSignal covers the requested range
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dourai01/Data/Git/lisa/py3k/external/bart/tests/test_pelt_sim.py", line 91, in test_signal_time_range
    def test_signal_time_range(self, task_args, sim_args, signal_range):
  File "/home/dourai01/Data/Git/lisa/py3k/.lisa-venv-3.7/lib/python3.7/site-packages/hypothesis/core.py", line 1002, in wrapped_test
    raise the_error_hypothesis_found
  File "/home/dourai01/Data/Git/lisa/py3k/.lisa-venv-3.7/lib/python3.7/site-packages/hypothesis/core.py", line 961, in wrapped_test
    state.run()
  File "/home/dourai01/Data/Git/lisa/py3k/.lisa-venv-3.7/lib/python3.7/site-packages/hypothesis/core.py", line 682, in run
    falsifying_example.__expected_traceback,
  File "/home/dourai01/Data/Git/lisa/py3k/.lisa-venv-3.7/lib/python3.7/site-packages/hypothesis/core.py", line 558, in execute
    result = self.test_runner(data, run)
  File "/home/dourai01/Data/Git/lisa/py3k/.lisa-venv-3.7/lib/python3.7/site-packages/hypothesis/executors.py", line 56, in default_new_style_executor
    return function(data)
  File "/home/dourai01/Data/Git/lisa/py3k/.lisa-venv-3.7/lib/python3.7/site-packages/hypothesis/core.py", line 556, in run
    return test(*args, **kwargs)
  File "/home/dourai01/Data/Git/lisa/py3k/external/bart/tests/test_pelt_sim.py", line 91, in test_signal_time_range
    def test_signal_time_range(self, task_args, sim_args, signal_range):
  File "/home/dourai01/Data/Git/lisa/py3k/.lisa-venv-3.7/lib/python3.7/site-packages/hypothesis/core.py", line 526, in test
    raise DeadlineExceeded(runtime, self.settings.deadline)
hypothesis.errors.DeadlineExceeded: Test took 210.05ms, which exceeds the deadline of 200.00ms
-------------------- >> begin captured stdout << ---------------------
Falsifying example: test_signal_time_range(self=<test_pelt_sim.TestSimulator testMethod=test_signal_time_range>, task_args=(62709, 192, 8113, None), sim_args=(626, 256, None), signal_range=(10, 190))

You can reproduce this example by temporarily adding @reproduce_failure('4.4.3', b'ALD/////rf/5Cr4FHgf/AnL/AQAEBwcCAPT0BgF6wAIAxR+x') as a decorator on your test case

--------------------- >> end captured stdout << ----------------------

----------------------------------------------------------------------

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants