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

RF: Python 2/3 compatibility #525

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

Conversation

chrispycheng
Copy link

@chrispycheng chrispycheng commented May 31, 2017

making code py2/py3 compatible per yarikoptic's instructions. please lmk if I did anything procedurally incorrectly.

TODOs (@yarikoptic's edits):

  • establish a baseline with some very basic unittests passing on both py2 and py3
  • keep going through components and mark them when corresponding submodules and tests are
    converted.
    While at it, I will try to move tests around (possibly screwing up some manual collection of tests) so we could adhere to the same "locality" setup as we do in other projects
    • base/ done in the sense that you can run tests on it, but not completely:
      • There is some discrepancy in summary output stats for some datasets between py2 and py3 - so something to be fixed up and solidified with a test.
      • test_hdf.py for now resides under main tests/ since pulls in too many other submodules
    • ...
  • reincarnate coverage reporting (was disabled for now)
    • there is still some pieces commented out TODO to reenable coverage
  • compare performance hit (against master) for py2. In many places we just use .items(), .keys() etc -- judging from timings of the run on travis -- there is sever hit ATM, but may be it is solely because we have more external dependencies installed for py2 than py3

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 80.051% when pulling e30751c on chrispycheng:patch-1 into e834243 on PyMVPA:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 80.051% when pulling e30751c on chrispycheng:patch-1 into e834243 on PyMVPA:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 80.051% when pulling e30751c on chrispycheng:patch-1 into e834243 on PyMVPA:master.

@coveralls
Copy link

coveralls commented May 31, 2017

Coverage Status

Coverage decreased (-59.7%) to 20.63% when pulling ab6f96a on chrispycheng:patch-1 into 6864d76 on PyMVPA:master.

@codecov-io
Copy link

codecov-io commented May 31, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@2617c4d). Click here to learn what that means.
The diff coverage is 39.44%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #525   +/-   ##
=========================================
  Coverage          ?   23.11%           
=========================================
  Files             ?      306           
  Lines             ?    36103           
  Branches          ?        0           
=========================================
  Hits              ?     8344           
  Misses            ?    27759           
  Partials          ?        0
Impacted Files Coverage Δ
mvpa2/mappers/tests/test_boxcarmapper.py 0% <ø> (ø)
mvpa2/datasets/tests/test_niftidataset.py 0% <ø> (ø)
mvpa2/tests/test_knn.py 0% <ø> (ø)
mvpa2/tests/test_cmdline.py 0% <ø> (ø)
mvpa2/clfs/tests/test_lars.py 0% <ø> (ø)
mvpa2/tests/test_datameasure.py 0% <ø> (ø)
mvpa2/measures/tests/test_clfcrossval.py 0% <ø> (ø)
mvpa2/base/tests/test_config.py 100% <ø> (ø)
mvpa2/tests/test_senses.py 0% <ø> (ø)
mvpa2/tests/test_stats.py 0% <ø> (ø)
... and 150 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2617c4d...09ac41c. Read the comment docs.

conversion to py2/3
@nno
Copy link
Contributor

nno commented May 31, 2017

Thanks!

Copy link
Member

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

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

"Procedurally" you are on the right track ;-)

@@ -225,7 +225,7 @@ def get_as_dtype(self, section, option, dtype, default=None):
return default
try:
return SafeConfigParser._get(self, section, dtype, option)
except ValueError, e:
except ValueError as e:
# provide somewhat descriptive error
raise ValueError, \
Copy link
Member

Choose a reason for hiding this comment

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

While at it, this statement could also be fixed right away to raise ValueError("....")

@chrispycheng chrispycheng changed the title Update config.py Py2/Py3 compatibility May 31, 2017
making constraints compatible.
I'm not completely certain about this one, given the printing of separate lines. Please advise as necessary!
Copy link
Member

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

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

left a few comments around - please clarify on import of builtins and bring back docstrings empty lines ;) otherwise -- lovely. We would need to wait for travis to start working properly again -- seems to be not picking up for testing across many projects ATM

raise ValueError, \
"Failed to obtain value from configuration for %s.%s. " \
"Original exception was: %s" % (section, option, e)
raise ValueError("Failed to obtain value from configuration for %s.%s." \
Copy link
Member

Choose a reason for hiding this comment

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

Just FYI: no trailing \ would longer be necessary here since now both strings are within ()

from builtins import map
from builtins import str
from past.builtins import basestring
from builtins import object
Copy link
Member

Choose a reason for hiding this comment

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

why explicit imports from builtins are necessary? shouldn't it all work just fine without?

Copy link
Member

Choose a reason for hiding this comment

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

ha ha -- I can answer my own question which came because I am (was) primarily six user, and not of the future. So builtins (and the past) is the compatibility layer from the future package. Thanks ;)

class Constraint(object):
"""Base class for input value conversion/validation.

Copy link
Member

Choose a reason for hiding this comment

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

we are following numpy docstrings convention. So empty line here is (was ;)) on purpose. See https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt#id6

An arbitrary number of constraints can be given. They are evaluated in the
order in which they were specified. The return value of each constraint is
passed an input into the next. The return value of the last constraint
is the global return value. No intermediate exceptions are caught.

Copy link
Member

Choose a reason for hiding this comment

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

here also some intensional blank lines should come back

Copy link
Author

Choose a reason for hiding this comment

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

sorry, professor. Futurize automatically plays around with some of the spacing. I'll work on going through and making sure the spacing stays the same.

Copy link
Member

Choose a reason for hiding this comment

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

btw -- the other spaces (two empty lines between classes etc) looked good to me. Just use "pycharm" IDE and it would also do the same suggestion(s)

per suggested changes
per suggestion
chrispycheng and others added 7 commits June 4, 2017 11:27
This is for ease of editing on my computer and to ensure that these changes can be pushed to git more easily.
planning to futurize files ad-hoc as error messages come up while running tests to ensure py3 compatibility of the code. suggestions/contributions welcome
… more documentation needed

old py2 codes included in files with the same name with the ending ".bak"

Please enter the commit message for your changes. Lines starting
@chrispycheng chrispycheng changed the title Py2/Py3 compatibility RF: Python 2/3 compatibility Jun 5, 2017
…ger used in RL

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "bash -c 'sed -i -e \"/if __name__ == .__main__..*no cover/,+5d\" {inputs}'",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [
  "mvpa2/*/test*py",
  "mvpa2/*/*/test*py",
  "mvpa2/*/*/*/test*py"
 ],
 "outputs": [
  "mvpa2/*/test*py",
  "mvpa2/*/*/test*py",
  "mvpa2/*/*/*/test*py"
 ],
 "pwd": "."
}
^^^ Do not change lines above ^^^
…er used in RL

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "bash -c 'sed -i -e \"/def suite().*no cover/,+2d\" {inputs}'",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [
  "mvpa2/*/test*py",
  "mvpa2/*/*/test*py",
  "mvpa2/*/*/*/test*py"
 ],
 "outputs": [
  "mvpa2/*/test*py",
  "mvpa2/*/*/test*py",
  "mvpa2/*/*/*/test*py"
 ],
 "pwd": "."
}
^^^ Do not change lines above ^^^
…cebacks

not even sure if that traceback information embedding would help us much,
and ATM I saw no easy way to do that reraising for both 2 and 3 so
just disabled that
… versions encoded so make explicit in the test
We did not handle them at all before so saving many types in PY3 would have
not worked
@yarikoptic yarikoptic mentioned this pull request May 3, 2020
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.

None yet

5 participants