Re: [Numpy-discussion] numpydoc for python 3?
On 01/14/2013 02:44 PM, Matthew Brett wrote: On Mon, Jan 14, 2013 at 10:35 AM, Jaakko Luttinen jaakko.lutti...@aalto.fi wrote: On 01/14/2013 12:53 AM, Matthew Brett wrote: You might be able to get away without 2to3, using the kind of stuff that Pauli has used for scipy recently: https://github.com/scipy/scipy/pull/397 Ok, thanks, maybe I'll try to make the tests valid in all Python versions. It seems there's only one line which I'm not able to transform. In doc/sphinxext/tests/test_docscrape.py, on line 559: assert doc['Summary'][0] == u'öäöäöäöäö'.encode('utf-8') This is invalid in Python 3.0-3.2. How could I write this in such a way that it is valid in all Python versions? I'm a bit lost with these unicode encodings in Python (and in general).. And I didn't want to add dependency on 'six' package. Pierre's suggestion is good; you can also do something like this: # -*- coding: utf8 -*- import sys if sys.version_info[0] = 3: a = 'öäöäöäöäö' else: a = unicode('öäöäöäöäö', 'utf8') The 'coding' line has to be the first or second line in the file. Thanks for all the comments! I reported an issue and made a pull request: https://github.com/numpy/numpy/pull/2919 However, I haven't been able to make nosetests work. I get error: ValueError: Attempted relative import in non-package Don't know how to fix it properly.. -Jaakko ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpydoc for python 3?
14.01.2013 14:44, Matthew Brett kirjoitti: [clip] Pierre's suggestion is good; you can also do something like this: # -*- coding: utf8 -*- import sys if sys.version_info[0] = 3: a = 'öäöäöäöäö' else: a = unicode('öäöäöäöäö', 'utf8') The 'coding' line has to be the first or second line in the file. Another useful option would be from __future__ import unicode_literals This makes the literal 'spam' be unicode also on Python 2, so that b'spam' is bytes. This might make unicode unification easier. OTOH, it might open some cans of worms. -- Pauli Virtanen ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpydoc for python 3?
Hi, Le 14/01/2013 11:35, Jaakko Luttinen a écrit : Ok, thanks, maybe I'll try to make the tests valid in all Python versions. It seems there's only one line which I'm not able to transform. In doc/sphinxext/tests/test_docscrape.py, on line 559: assert doc['Summary'][0] == u'öäöäöäöäö'.encode('utf-8') This is invalid in Python 3.0-3.2. How could I write this in such a way that it is valid in all Python versions? I'm a bit lost with these unicode encodings in Python (and in general).. And I didn't want to add dependency on 'six' package. Just as a side note about Python and encodings, I found great help in watching (by chance) the PyCon 2012 presentation Pragmatic Unicode or How do I stop the Pain ? by Ned Batchelder : http://nedbatchelder.com/text/unipain.html Now, if I understand the problem correctly, the u'xxx' syntax was reintroduced in Python 3.3 specifically to enhance the 2to3 compatibility (http://docs.python.org/3/whatsnew/3.3.html#pep-414-explicit-unicode-literals). Maybe the question is then whether it's worth supporting Python 3.0-3.2 or not ? Also, one possible rewrite of the test could be to replace the unicode string with the corresponding utf8-encoded bytes : assert doc['Summary'][0] == b'\xc3\xb6\xc3\xa4\xc3\xb6\xc3\xa4\xc3\xb6\xc3\xa4\xc3\xb6\xc3\xa4\xc3\xb6\xc3\xa5\xc3\xa5\xc3\xa5\xc3\xa5' # output of 'öäöäöäöäö'.encode('utf-8') (One restriction : I think the b'' prefix was introduced in Python 2.6) I'm not sure for the readability though... Best, Pierre signature.asc Description: OpenPGP digital signature ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpydoc for python 3?
Hi, On Mon, Jan 14, 2013 at 10:35 AM, Jaakko Luttinen jaakko.lutti...@aalto.fi wrote: On 01/14/2013 12:53 AM, Matthew Brett wrote: On Sun, Jan 13, 2013 at 10:46 PM, Jaakko Luttinen jaakko.lutti...@aalto.fi wrote: I'm a bit stuck trying to make numpydoc Python 3 compatible. I made setup.py try to use distutils.command.build_py.build_py_2to3 in order to transform installed code automatically to Python 3. However, the tests (in tests folder) are not part of the package but rather package_data, so they won't get transformed. How can I automatically transform the tests too? Probably there is some easy and right solution to this, but I haven't been able to figure out a nice and simple solution.. Any ideas? Thanks. Can you add tests as a package 'numpydoc.tests' and add an __init__.py file to the 'tests' directory? I thought there is some reason why the 'tests' directory is not added as a package 'numpydoc.tests', so I didn't want to take that route. I think the only reason is so that people can't import 'numpydoc.tests' in case they get confused. We (nipy.org/nipy etc) used to use packagedata for tests, but then we lost interest in preventing people doing the import, and started to enjoy being able to port things across as packages, do relative imports, run 2to3 and so on. So, I'd just go for it. You might be able to get away without 2to3, using the kind of stuff that Pauli has used for scipy recently: https://github.com/scipy/scipy/pull/397 Ok, thanks, maybe I'll try to make the tests valid in all Python versions. It seems there's only one line which I'm not able to transform. In doc/sphinxext/tests/test_docscrape.py, on line 559: assert doc['Summary'][0] == u'öäöäöäöäö'.encode('utf-8') This is invalid in Python 3.0-3.2. How could I write this in such a way that it is valid in all Python versions? I'm a bit lost with these unicode encodings in Python (and in general).. And I didn't want to add dependency on 'six' package. Pierre's suggestion is good; you can also do something like this: # -*- coding: utf8 -*- import sys if sys.version_info[0] = 3: a = 'öäöäöäöäö' else: a = unicode('öäöäöäöäö', 'utf8') The 'coding' line has to be the first or second line in the file. Best, Matthew ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpydoc for python 3?
On 2013-01-10 17:16, Jaakko Luttinen wrote: On 01/10/2013 05:04 PM, Pauli Virtanen wrote: Jaakko Luttinen jaakko.luttinen at aalto.fi writes: The files in numpy/doc/sphinxext/ and numpydoc/ (from PyPI) are a bit different. Which ones should be modified? The stuff in sphinxext/ is the development version of the package on PyPi, so the changes should be made in sphinxext/ Thanks! I'm trying to run the tests with Python 2 using nosetests, but I get some errors http://pastebin.com/Mp9i8T2f . Am I doing something wrong? How should I run the tests? If I run nosetests on the numpydoc folder from PyPI, all the tests are successful. I'm a bit stuck trying to make numpydoc Python 3 compatible. I made setup.py try to use distutils.command.build_py.build_py_2to3 in order to transform installed code automatically to Python 3. However, the tests (in tests folder) are not part of the package but rather package_data, so they won't get transformed. How can I automatically transform the tests too? Probably there is some easy and right solution to this, but I haven't been able to figure out a nice and simple solution.. Any ideas? Thanks. -Jaakko ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpydoc for python 3?
Hi, Jaakko Luttinen jaakko.luttinen at aalto.fi writes: I'm trying to use numpydoc (Sphinx extension) for my project written in Python 3.2. However, installing numpydoc gives errors shown at http://pastebin.com/MPED6v9G and although it says Successfully installed numpydoc, trying to import numpydoc raises errors.. Could this be fixed or am I doing something wrong? Numpydoc hasn't been ported to Python 3 so far. This probably wouldn't a very large amount of work --- patches are accepted! -- Pauli Virtanen ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpydoc for python 3?
The files in numpy/doc/sphinxext/ and numpydoc/ (from PyPI) are a bit different. Which ones should be modified? -Jaakko On 01/10/2013 02:04 PM, Pauli Virtanen wrote: Hi, Jaakko Luttinen jaakko.luttinen at aalto.fi writes: I'm trying to use numpydoc (Sphinx extension) for my project written in Python 3.2. However, installing numpydoc gives errors shown at http://pastebin.com/MPED6v9G and although it says Successfully installed numpydoc, trying to import numpydoc raises errors.. Could this be fixed or am I doing something wrong? Numpydoc hasn't been ported to Python 3 so far. This probably wouldn't a very large amount of work --- patches are accepted! ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpydoc for python 3?
Jaakko Luttinen jaakko.luttinen at aalto.fi writes: The files in numpy/doc/sphinxext/ and numpydoc/ (from PyPI) are a bit different. Which ones should be modified? The stuff in sphinxext/ is the development version of the package on PyPi, so the changes should be made in sphinxext/ -- Pauli Virtanen ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpydoc for python 3?
On 01/10/2013 05:04 PM, Pauli Virtanen wrote: Jaakko Luttinen jaakko.luttinen at aalto.fi writes: The files in numpy/doc/sphinxext/ and numpydoc/ (from PyPI) are a bit different. Which ones should be modified? The stuff in sphinxext/ is the development version of the package on PyPi, so the changes should be made in sphinxext/ Thanks! I'm trying to run the tests with Python 2 using nosetests, but I get some errors http://pastebin.com/Mp9i8T2f . Am I doing something wrong? How should I run the tests? If I run nosetests on the numpydoc folder from PyPI, all the tests are successful. -Jaakko ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion