Skip to content

Apply python-future for Python 3.4 support #1221

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 125 commits into from
Oct 15, 2015
Merged

Conversation

alexsavio
Copy link
Contributor

No description provided.

@alexsavio
Copy link
Contributor Author

For Python 3 I need to futurize prov as well, which is in https://github.com/trungdong/prov/archive/rdf.zip
Unless I can get nipype to work with the new version. This is not a big issue for now, I will keep trying Python 2.7 to pass the tests.

@satra
Copy link
Member

satra commented Sep 17, 2015

@alexsavio - don't worry about prov for now. in fact if you want you can strip it out for now or use dummy functions in provenance.py

i'm working on updating nipype's prov support to be compatible with current master which already supports py3.

@alexsavio
Copy link
Contributor Author

FAIL in both versions: nipype.algorithms.tests.test_splitmerge.test_split_and_merge

@alexsavio
Copy link
Contributor Author

If I remove dumps and loads in getsource and create_function_from_source, it fixes many tests in pipeline.test.test_utils, this makes the function_str to be str instead of bytes in Python 3. In addition, assigning bytes to a traits.Str raises an error.
Is there any reason that I'm missing for you to be using "dumped" strings in function_str in Function?

@satra
Copy link
Member

satra commented Sep 21, 2015

@alexsavio - the thought process behind using pickle is to ensure that the contents of function_str could be hashed properly and also turned into a python function that can be executed. if there is a better way to achieve the same effect, we can definitely try it out.

@alexsavio
Copy link
Contributor Author

I have been busy with life. I'm currently stuck with unicodes, strings vs. Traits.
For example: nosetests -s nipype.interfaces.tests.test_base:test_TraitedSpec
In Python3 it works, now that everything is a unicode string, even what Traits returns, e.g., from get_hashval().
On Python2 the string literals are now unicode (thanks to from __future__ import unicode_literals) but TraitedSpec.get_hashval() is returning str. There are a few options to fix this, but I can't decide yet which one is better.

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

@alexsavio can you rebase on current master?

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

If I remove dumps and loads in getsource and create_function_from_source, it fixes many tests

This is a place where using six would make things easy; they take care of the import location change for cPickle...

@alexsavio
Copy link
Contributor Author

Hi @bcipolli, do you mean merging the current master to this PR?

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

git rebase upstream/master. It replays your commits on top of the current master, rather than merging master on top of your changes.

@alexsavio
Copy link
Contributor Author

Like this?

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

This branch has conflicts that must be resolved - have to fix this. Can you make me a collaborator on your repo?

@alexsavio
Copy link
Contributor Author

done

@alexsavio
Copy link
Contributor Author

I know, I haven't fixed everything yet

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

@alexsavio I will try to rebase. I added some questions from reviewing some commits. Will let you know how it goes!

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

I believe the Trait error is because environ = traits.DictStrStr, which likely requires a str (and not unicode). Will try to read a bit about how others have worked around things, if this is the issue.

@alexsavio
Copy link
Contributor Author

Yes, definitely that is the case. Thanks @bcipolli!

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

Temporary workaround is to relax from DictStrStr to Dict. I think the most important thing is to get something merged (since there are so many potential merge conflicts), then open issues for things like this to be solved before the next release...

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

@alexsavio I force-pushed the rebase to your branch; you will need to rename/remove your current local branch to work on the force-pushed one.

I will do a bit more investigation on other errors, now that the TraitError workaround is in place. We can revisit that later; looks like there are plenty of errors to address in Py2 and Py3 in the meantime.

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

@alexsavio I think the strategy of applying changes globally (e.g. traits.Str => traits.Unicode,from future import unicode_literals`) is going to be problematic.

  • I think we need a Py23Str that is traits.Str for py2, traits.Unicode for py3
  • I think literals should not be unicode, as that means the calling code will have to be using unicode exclusively, and we can't guarantee that--users using py2 will be passing values to compare that are bytes.

I made the first change. The second one, however, I am starting to think should be removed everywhere. Otherwise, I don't think we have a hope for Py2 compatibility. What do you think?

@alexsavio
Copy link
Contributor Author

@bcipolli Thanks!

Maybe you are right. I did the from future import unicode_literals because it was the recommendation in python-future.

Of course I realised it could be problematic once I stomped on the Traits failures. That is why I was asking. I suppose we have also the option to use six for strings (so, remove all the unicode_literals from the code and fix everywhere) or implement the Traits.Py6Str or Traits.Py23Str which was something in my mind, but I needed a hand to decide.

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

See the "Drawbacks" here, particularly the "user code" example:
http://python-future.org/imports.html#should-i-import-unicode-literals

My intuition says to try and migrate without unicode-literals. Is there a specific commit we can remove to try it out (rather than adding a commit to delete the code insertion)?

@alexsavio
Copy link
Contributor Author

I guess you are right.
Sadly I used the command futurize, which makes many different changes not only the unicode_literals import.
This was done in the first commits that say 'Futurize ...'.
I can only see that the best thing is to add a commit to delete these imports. :/

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

@alexsavio I made a commit to remove unicode_laterals. Now, checks such as this fail: isinstance\(.*, str\). This should migrate to six (isinstance\(.*, string_types\)). Do you have time for that? I have to move on to other work today.

@bcipolli
Copy link

bcipolli commented Oct 9, 2015

@alexsavio I need a break from my work, so I will try out the above replacement.

@alexsavio
Copy link
Contributor Author

Hi @bcipolli I was out. How is it going? can I help?

@satra
Copy link
Member

satra commented Oct 11, 2015

@bcipolli - the latest commits should take care of all the issues - let's see what circle says.

also if you have a chance to scroll through this commit that would be great.
alexsavio@df8fbaf

@@ -9,6 +9,7 @@ dependencies:
- "~/examples/fsl_course_data"
override:
- pip install --upgrade pip
- pip install -r requirements.txt
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? All dependencies should be in the setup.py file and picked up by

pip install -e .

I recommend removing requirements.txt from circle.yml. Keeping it may lead to tests passing, but pip-installed packages failing to run because some dependency was in in requirements.txt, but was left out of setup.py.

@satra
Copy link
Member

satra commented Oct 12, 2015

@chrisfilo - it's hard to read the circleci output, but am i understanding that the only error is in doc generation?

@chrisgorgo
Copy link
Member

both nosetest and doc generation are currently failing on this branch

nosetest:

======================================================================
FAIL: nipype.interfaces.spm.tests.test_base.test_spm_path(<type 'unicode'>, <type 'str'>)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 354, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: <type 'unicode'>
 DESIRED: <type 'str'>

documentation:

/home/ubuntu/nipype/doc/users/examples/fmri_ants_openfmri.rst:35: ERROR: Unexpected indentation.
/home/ubuntu/nipype/doc/users/examples/fmri_ants_openfmri.rst:49: ERROR: Unexpected indentation.

and many similar

@bcipolli
Copy link

Thanks @chrisfilo . I was able to reproduce the doc build issues locally; they are due to a missing blank line between the file docstring and first import. I can fix those.

The other issue is due to output streams coming out unicode on python 2/3. Haven't figured out why this is yet.

@bcipolli
Copy link

@satra @alexsavio tests are passing!! :) One last issue I thought of last night; the use of loads/dumps. I believe some were removed (per the discussion above) without replacement; please take a look for example at:
alexsavio@6ceb87e
alexsavio@f531ed6

to confirm this won't cause any problem.

@satra
Copy link
Member

satra commented Oct 12, 2015

@bcipolli - i'm going to open an issue for loads/dumps - i have no recollection why i wrote it with pickling. so we will monitor it in case we run into trouble, but otherwise i think this is ready for merging.

@chrisfilo - could i leave it to you to take any last look and hit the merge button?

@chrisgorgo
Copy link
Member

Did you guys try to switch Circle to python 3 for one commit and see if the workflows still work? That would convince me that we are indeed P3 compatible.

@bcipolli
Copy link

@chrisfilo no, we didn't. Any suggestion how to do that?

@chrisgorgo
Copy link
Member

According to this https://circleci.com/docs/language-python you need to add the following lines to circle.yml:

machine:
  python:
    version: 3.5.0

There are more versions available: https://circleci.com/docs/environment#python

@bcipolli
Copy link

@chrisfilo could you help look over the failures? There were four. I looked over the text, and it wasn't clear to me what the problem might be, nor how to reproduce them locally.

The easiest one to reproduce locally seemed to be: nipype.interfaces.tests.test_io:test_s3datagrabber_communication, which I guess just required installing boto, but when I run the following command, it hangs for 10 minutes (before I kill it):

python3 which nosetests nipype.interfaces.tests.test_io:test_s3datagrabber_communication

@chrisgorgo
Copy link
Member

The errors are indeed strange. I'll try rebuilding without cache. Hold tight it will take a while.

satra and others added 5 commits October 15, 2015 08:34
@bcipolli
Copy link

Please see #1253

chrisgorgo added a commit that referenced this pull request Oct 15, 2015
Apply python-future for Python 3.4 support
@chrisgorgo chrisgorgo merged commit 7e3393e into nipy:master Oct 15, 2015
@satra
Copy link
Member

satra commented Oct 15, 2015

woohoo!

@alexsavio
Copy link
Contributor Author

:)

@alexsavio alexsavio deleted the enh/py3k branch November 16, 2015 14:13
@coveralls
Copy link

Coverage Status

Coverage decreased (-47.02%) to 25.084% when pulling 6406ace on alexsavio:enh/py3k into 11111cd on nipy:master.

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.

5 participants