summaryrefslogtreecommitdiff
path: root/tools/py3tool.py
Commit message (Collapse)AuthorAgeFilesLines
* MAINT: Remove the tools/py3tool.py file.Charles Harris2013-04-241-301/+0
| | | | | The tools/py3tool.py file was responsible for running 2to3. Now that 2to3 is no longer run it is not needed and can be removed.
* 2to3: Apply unicode fixer.Charles Harris2013-04-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | The unicode fixer strips the u from u'hi' and converts the unicode type to str. The first won't work for Python 2 and instead we replace the u prefix with the sixu function borrowed from the six compatibility package. That function calls the unicode constructor with the 'unicode_escape' encoder so that the many tests using escaped unicode characters like u'\u0900' will be handled correctly. That makes the sixu function a bit different from the asunicode function currently in numpy.compat and also provides a target that can be converted back to the u prefix when support for Python 3.2 is dropped. Python 3.3 reintroduced the u prefix for compatibility. The unicode fixer also replaces 'unicode' with 'str' as 'unicode' is no longer a builtin in Python 3. For code compatibility, 'unicode' is defined either as 'str' or 'unicode' in numpy.compat so that checks like if isinstance(x, unicode): ... will work properly for all python versions. Closes #3089.
* Merge pull request #3242 from charris/2to3-apply-types-fixerCharles Harris2013-04-211-1/+1
|\ | | | | 2to3: Apply types fixer.
| * 2to3: Apply types fixer.Charles Harris2013-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Python 3 removes the builtin types from the types module. The types fixer replaces such references with the builtin types where possible and also takes care of some special cases: types.TypeNone <- type(None) types.NotImplementedType <- type(NotImplemented) types.EllipsisType <- type(Ellipsis) The only two tricky substitutions are types.StringType <- bytes types.LongType <- int These are fixed up to support both Python 3 and Python 2 code by importing the long and bytes types from numpy.compat. Closes #3240.
* | Merge pull request #3249 from charris/2to3-apply-next-fixerCharles Harris2013-04-151-1/+1
|\ \ | | | | | | 2to3: Apply next fixer.
| * | 2to3: Apply next fixer.Charles Harris2013-04-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The next builtin has been available since Python 2.6 and allows `it.next()` to be replaced by `next(it)`. In Python 3 the `next` method is gone entirely, replaced entirely by the `__next__` method. The next fixer changes all the `it.next()` calls to the new form and renames the `next` methods to `__next__`. In order to keep Numpy code backwards compatible with Python 2, a `next` method was readded to all the Numpy iterators after the fixer was run so they all contain both methods. The presence of the appropriate method could have been made version dependent, but that looked unduly complicated. Closes #3072.
* | | 2to3: Apply urllib fixer.Charles Harris2013-04-141-1/+1
|/ / | | | | | | | | | | | | | | | | | | | | Various functions have been moved around in the stdlib for Python 3, this fixes that up so that the code is valid in both Python 2 and Python 3. Note: monkey patching the stlib urlopen for testing looks a bit hokey to me, but I don't see an easier, more reliable way to do the test. Closes #3090.
* | 2to3: Skip isinstance fixer.Charles Harris2013-04-141-1/+1
|/ | | | | | | | | | | | | The isinstance fixer removes duplicate types in the second argument of isinstance(). For example, isinstance(x, (int, int)) is converted to isinstance(x, (int)). This would certainly apply if we let the long fixer replace long by int, but as is it does nothing. Duplicate entries are supposedly deprecated in Python 3, I'm not sure why or how, but it does not seem to be a problem at this point. If it ever becomes so, we can deal with it then. Closes #3085
* Merge pull request #3244 from charris/2to3-apply-zip-fixerCharles Harris2013-04-141-1/+1
|\ | | | | 2to3: Apply zip fixer.
| * 2to3: Apply zip fixer.Charles Harris2013-04-131-1/+1
| | | | | | | | | | | | | | | | | | | | In Python 3 zip returns an iterator instead of a list. Consequently, in places where an iterator won't do it must be enclosed in list(...). Lists instead of iterators are also used in array constructors as using iterators there usually results in an object array containing an iterator object. Closes #3094
* | Merge pull request #3241 from charris/2to3-apply-nonzero-fixerCharles Harris2013-04-141-1/+1
|\ \ | | | | | | 2to3: Apply nonzero fixer.
| * | 2to3: Apply nonzero fixer.Charles Harris2013-04-131-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | In Python 3 the `__nonzero__` class method is replaced by `__bool__`. This only affects the MaskedArray class in numpy/oldnumeric/ma.py file and the simplest solution is to provide both methods. I have my doubts that the fixed up Python 3 version was correct or even tested, but I think the current solution should work for as long as oldnumeric stays in numpy. Closes #3073.
* | Merge pull request #3238 from charris/2to3-apply-renames-fixerCharles Harris2013-04-141-1/+1
|\ \ | | | | | | 2to3: Apply renames fixer.
| * | 2to3: Apply renames fixer.Charles Harris2013-04-131-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | Rename sys.maxint to sys.maxsize when the Python version is >= 3. This change was made in Python 3 because all integers are 'long' integers and their maximum value bears no relationship to the C type that int used to represent. The new sys.maxsize value is the maximum value of Py_ssize_t. This change has not led to any reported problems since the numpy 1.5 release. Closes #3082
* | 2to3: Apply basestring fixer.Charles Harris2013-04-131-1/+1
|/ | | | | | | | | | | The basestring class is not defined in Python 3 and the fixer replaces it with str. In order to have a common code base we define basestring in numpy/compat/py3k.py to be str when the Python version is >= 3, otherwise basestring and import it where needed. That works for most cases, but there are a few files where the version dependent define needs to be in the file. Closes #3042.
* 2to3: Apply the `numliterals` fixer and skip the `long` fixer.Charles Harris2013-04-131-3/+3
| | | | | | | | | | | | | | | | | | | The numliterals fixer replaces the old style octal number like '01' by '0o1' removes the 'L' suffix. Octal values were previously mistakenly specified in some dates, those uses have been corrected by removing the leading zeros. Simply Removing the 'L' suffix should not be a problem, but in some testing code it looks neccesary, so in those places the Python long constructor is used instead. The 'long' type is no longer defined in Python 3. Because we need to have it defined for Python 2 it is added to numpy/compat/np3k.py where it is defined as 'int' for Python 3 and 'long' for Python 2. The `long` fixer then needs to be skipped so that it doesn't undo the good work. Closes #3074, #3067.
* 2to3: Apply itertools fixer.Charles Harris2013-04-121-1/+1
| | | | | | | | | | | | | In Python 3 zip, map, and filter are all iterators, consequently the itertools variants izip, imap, and ifilter have been removed and the itertools fixer replaces them with the unprefixed names. Because the places where the iterator variants are used in current look like places where the iterator version might be useful, the approach taken here is to define the prefixed versions to the unprefixed versions for Python 3, but otherwise import them from itertools. Closes #3233.
* 2to3: Skip itertools_imports fixer.Charles Harris2013-04-121-1/+1
| | | | | | | | No files are changed by the itertools_imports fixer so skip it. What the fixer does is rename imports of imap, ifilter, and izip to map, filter, and zip since the latter are iterators in Python 3. Closes #3234
* 2to3: Skip `setliteral` fixer.Charles Harris2013-04-121-1/+1
| | | | | | | | | | Setliterals are not available in Python 2.6. Because the current usage in numpy is forward compatible with Python 3 there is no need to run the fixer. When Python 2.6 support is dropped the fixer can be run, but that looks to be several years off. RHEL 6 with Python 2.6 was released in 2010 and will run for ten years.
* 2to3: Skip `funcattrs` fixer.Charles Harris2013-04-111-1/+1
| | | | | | | | | In Python 3 the func.func_name attribute is replaced by the func.__name__ attribute. The only file affected by this is doc/sphinxext/numpydoc/phantom_import.py, and there its use is already version dependent. Closes #3054.
* 2to3: Skip buffer fixer.Charles Harris2013-04-111-1/+1
| | | | | | | | | | The buffer object is replaced by memoryview in Python >= 3. The memory view object has also been backported to Python 2.7. However, the only use of `buffer1/1memoryview1 is in `numpy/core/tests/test_unicode.py` and there it is already version dependent: `memoryview` is used if the Python version is >= 3 and `buffer` is used otherwise. Closes #3043.
* 2to3: Skip `future` fixer.Charles Harris2013-04-101-1/+1
| | | | | | The `future` fixer removes the `from __future__ import ...` statements. That is fine for Python 3, but we need to keep that statement if we are shooting for a common code base for both Python 2 and Python 3.
* 2to3: Apply `map` fixer.Charles Harris2013-04-101-25/+46
| | | | | | | | | | | | | | | | | | | In Python 3 `map` is an iterator while in Python 2 it returns a list. The simple fix applied by the fixer is to inclose all instances of map with `list(...)`. This is not needed in all cases, and even where appropriate list comprehensions may be preferred for their clarity. Consequently, this patch attempts to use list comprehensions where it makes sense. When the mapped function has two arguments there is another problem that can arise. In Python 3 map stops execution when the shortest argument list is exhausted, while in Python 2 it stops when the longest argument list is exhausted. Consequently the two argument case might need special care. However, we have been running Python3 converted versions of numpy since 1.5 without problems, so it is probably not something that affects us. Closes #3068
* 2to3: Apply `repr` fixer.Charles Harris2013-04-081-0/+1
| | | | | | | | | | | | This replaces python backtics with repr(...). The backtics were mostly used to generate strings for printing with a string format and it is tempting to replace `'%s' % repr(x)` with `'%r' % x`. That would work except where `x` happened to be a tuple or a dictionary but, because it would be significant work to guarantee that and because there are not many places where backtics are used, the safe path is to let the repr replacements stand. Closes #3083.
* Merge pull request #3205 from charris/2to3-apply-dict-fixerCharles Harris2013-04-071-0/+1
|\ | | | | 2to3: apply `dict` fixer.
| * 2to3: apply `dict` fixer.Charles Harris2013-04-061-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Python3 `dict.items()`, `dict.keys()`, and `dict.values()` are iterators. This causes problems when a list is needed so the 2to3 fixer explicitly constructs a list when is finds on of those functions. However, that is usually not necessary, so a lot of the work here has been cleaning up those places where the fix is not needed. The big exception to that is the `numpy/f2py/crackfortran.py` file. The code there makes extensive use of loops that modify the contents of the dictionary being looped through, which raises an error. That together with the obscurity of the code in that file made it safest to let the `dict` fixer do its worst. Closes #3050.
* | Merge pull request #3202 from charris/2to3-reduce-fixupsnjsmith2013-04-071-9/+0
|\ \ | |/ |/| MAINT: Cleanup some imports involving reduce.
| * MAINT: Cleanup some imports involving reduce.Charles Harris2013-04-061-9/+0
| | | | | | | | | | | | | | | | | | | | Because reduce has been available in functools since Python 2.6 we can get rid of the version checks we currently have before we import it. Also removes some reduce related skips in tools/py3tool.py. We were already skipping the reduce fixer so this has no effect other than cleaning up the code.
* | 2to3: Apply `print` fixer.Charles Harris2013-04-061-1/+2
|/ | | | | | | Add `print_function` to all `from __future__ import ...` statements and use the python3 print function syntax everywhere. Closes #3078.
* MAINT: Append comma to last item tools/py3tool.py skipped fixers.Charles Harris2013-04-061-1/+1
| | | | Makes it easier to put in the next fixer.
* 2to3: Apply `imports2` fixer.Charles Harris2013-04-061-1/+2
| | | | | | | No files were changed by this fixer, so add it to the list of fixers to be skipped by 2to3. Closes #3181.
* 2to3: Apply `imports` fixer.Charles Harris2013-04-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The `imports` fixer deals with the standard packages that have been renamed, removed, or methods that have moved. cPickle -- removed, use pickle commands -- removed, getoutput, getstatusoutput moved to subprocess urlparse -- removed, urlparse moved to urllib.parse cStringIO -- removed, use StringIO or io.StringIO copy_reg -- renamed copyreg _winreg -- renamed winreg ConfigParser -- renamed configparser __builtin__ -- renamed builtins In the case of `cPickle`, it is imported as `pickle` when python < 3 and performance may be a consideration, but otherwise plain old `pickle` is used. Dealing with `StringIO` is a bit tricky. There is an `io.StringIO` function in the `io` module, available since Python 2.6, but it expects unicode whereas `StringIO.StringIO` expects ascii. The Python 3 equivalent is then `io.BytesIO`. What I have done here is used BytesIO for anything that is emulating a file for testing purposes. That is more explicit than using a redefined StringIO as was done before we dropped support for Python 2.4 and 2.5. Closes #3180.
* 2to3: Use absolute imports.Charles Harris2013-03-281-42/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new import `absolute_import` is added the `from __future__ import` statement and The 2to3 `import` fixer is run to make the imports compatible. There are several things that need to be dealt with to make this work. 1) Files meant to be run as scripts run in a different environment than files imported as part of a package, and so changes to those files need to be skipped. The affected script files are: * all setup.py files * numpy/core/code_generators/generate_umath.py * numpy/core/code_generators/generate_numpy_api.py * numpy/core/code_generators/generate_ufunc_api.py 2) Some imported modules are not available as they are created during the build process and consequently 2to3 is unable to handle them correctly. Files that import those modules need a bit of extra work. The affected files are: * core/__init__.py, * core/numeric.py, * core/_internal.py, * core/arrayprint.py, * core/fromnumeric.py, * numpy/__init__.py, * lib/npyio.py, * lib/function_base.py, * fft/fftpack.py, * random/__init__.py Closes #3172
* BUG: Rebased tools/py3tool.py was missing `,` in list.Charles Harris2013-03-271-1/+1
|
* 2to3: Replace xrange by range and use list(range(...)) where neededCharles Harris2013-03-271-0/+1
| | | | | | | | | | | | | | | In python3 range is an iterator and `xrange` has been removed. This has two consequence for code: 1) Where a list is needed `list(range(...))` must be used. 2) `xrange` must be replaced by `range` Both of these changes also work in python2 and this patch makes both. There are three places fixed that do not need it, but I left them in so that the result would be `xrange` clean. Closes #3092
* 2to3: Remove xreadlines and replace f.readlines() by f where valid.Charles Harris2013-03-051-1/+2
| | | | | | | | | | An open file `f` has been an iterator since python2.3 and `f.xreadlines()` is no longer needed, so replace it with `f`. Also replace `f.readlines()` with `f` where an iterator will do. The replacement of `f.readlines()` is not critical because it is a list in both python2 and python3, but the code is a bit cleaner. Closes #3093
* 2to3:DEP: Remove interactive setup and gnu compiler configuration.Charles Harris2013-03-051-1/+3
| | | | | | | | | | | | | | | | | | | | | | These havn't been deprecated, but I think few have heard of them, much less used them. Before this change, running setup.py without any arguments would result in interactive help. This patch removes that interactive help and lets setup print its usual list of commands and options. All the script uses of the numpy/distutils/fcompiler compilers look quite broken to me, but I have tried to maintain compatibility with the earlier version of gnu.py after the removal of `raw_input`. These removals solve an incompatibility between Python3 and Python2. The current interactive setup help uses `raw_input`, which has been removed in python3 and replaced by `input`. However, python2 already has an `input` that has different semantics. Rather than deal with this, I think it simpler to keep both `raw_input` and `input` out of numpy. Closes #3063 Closes #3079
* ENH: Skip already applied fixers when running 2to3.Charles Harris2013-03-031-1/+36
| | | | | | | | This is done in `tools/py3tool.py` by providing a list of fixers that is passed in the call to 2to3 with with the `-x` option that tells 2to3 to skip them. Closes #3113
* 2to3: Put `from __future__ import division in every python file.Charles Harris2013-03-011-0/+2
| | | | | | | | This should be harmless, as we already are division clean. However, placement of this import takes some care. In the future a script can be used to append new features without worry, at least until such time as it exceeds a single line. Having that ability will make it easier to deal with absolute imports and printing updates.
* ENH: do not make backup copies when running 2to3.Ralf Gommers2011-04-171-1/+1
| | | | Copied from scipy commit f7dae4f2.
* BUG: Py3: ensure version.py imports are translated appropriatelyPauli Virtanen2010-11-251-1/+1
|
* BUG: core: fix _dotblas usage on Py3 (fixes #1609)Pauli Virtanen2010-09-111-1/+1
|
* ENH: 3K: optionally use lib2to3cache in 2to3 conversionPauli Virtanen2010-07-181-0/+3
|
* CLN: Remove some now unnecessary fixups to lib/npyio.Charles Harris2010-03-251-9/+0
|
* Rename numpy/lib/io.py to numpy/lib/npyio.py. The py3tool can probably beCharles Harris2010-03-241-2/+2
| | | | cleaned up a bit more with this change, but that is for later.
* 3K: BUG: work around bugs in Python 3.1.1 2to3 by not using fixes_reducePauli Virtanen2010-02-201-0/+9
| | | | Instead, manually import reduce where necessary.
* 3K: py3tool: use lib2to3 for the conversionsPauli Virtanen2010-02-201-2/+15
| | | | | This ensures that the Py3 version of 2to3 is always used, and that failures in conversion result to an immediate build failure.
* 3K: BUG: make test_defchararray convert properly via 2to3Pauli Virtanen2010-02-201-1/+0
|
* py3tool: customize 2to3 flags for some filesPauli Virtanen2009-12-061-19/+24
|
* py3tool: skip temporary etc filesPauli Virtanen2009-12-061-0/+4
|