Skip to content

Commit

Permalink
2to3: Use absolute imports.
Browse files Browse the repository at this point in the history
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 numpy#3172
  • Loading branch information
charris committed Mar 28, 2013
1 parent 4074218 commit d4b88c1
Show file tree
Hide file tree
Showing 378 changed files with 659 additions and 703 deletions.
2 changes: 1 addition & 1 deletion doc/cdoc/numpyfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Also, add Doxygen /** and /**< syntax automatically where appropriate.
"""
from __future__ import division
from __future__ import division, absolute_import

import sys
import re
Expand Down
2 changes: 1 addition & 1 deletion doc/cython/run_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from __future__ import division
from __future__ import division, absolute_import

from numpyx import test
test()
2 changes: 1 addition & 1 deletion doc/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
a line by itself, preferably preceeded by a blank line.
"""
from __future__ import division
from __future__ import division, absolute_import

import os # standard library imports first

Expand Down
2 changes: 1 addition & 1 deletion doc/newdtype_example/example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

import floatint.floatint as ff
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion doc/newdtype_example/floatint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import division
from __future__ import division, absolute_import


2 changes: 1 addition & 1 deletion doc/numpybook/comparison/ctypes/filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

__all__ = ['filter2d']

Expand Down
2 changes: 1 addition & 1 deletion doc/numpybook/comparison/ctypes/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

__all__ = ['add', 'filter2d']

Expand Down
2 changes: 1 addition & 1 deletion doc/numpybook/comparison/timing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

import timeit

Expand Down
2 changes: 1 addition & 1 deletion doc/numpybook/comparison/weave/filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

from scipy import weave, zeros_like

Expand Down
2 changes: 1 addition & 1 deletion doc/numpybook/comparison/weave/inline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

from scipy import weave
from numpy import rand, zeros_like
Expand Down
2 changes: 1 addition & 1 deletion doc/numpybook/runcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
-n name of code section (default MyCode)
"""
from __future__ import division
from __future__ import division, absolute_import

import sys
import optparse
Expand Down
2 changes: 1 addition & 1 deletion doc/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
MODE is either 'html' or 'tex'.
"""
from __future__ import division
from __future__ import division, absolute_import

import re, optparse

Expand Down
2 changes: 1 addition & 1 deletion doc/pyrex/run_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from __future__ import division
from __future__ import division, absolute_import

from numpyx import test
test()
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import division, absolute_import

import sys, os, re

Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/comment_eater.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

import sys
if sys.version_info[0] >= 3:
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/compiler_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
fixme: We may want to move to using _ast trees because the compiler for
them is about 6 times faster than compiler.compile.
"""
from __future__ import division
from __future__ import division, absolute_import

import sys
from compiler.ast import Const, Name, Tuple, Div, Mul, Sub, Add
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/docscrape.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Extract reference documentation from the NumPy source tree.
"""
from __future__ import division
from __future__ import division, absolute_import

import sys
import inspect
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/docscrape_sphinx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

import re, inspect, textwrap, pydoc
import sphinx
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/linkcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:license: BSD, see LICENSE for details.
"""
from __future__ import division
from __future__ import division, absolute_import

import warnings
import collections
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.. [1] https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
"""
from __future__ import division
from __future__ import division, absolute_import

import sphinx
import collections
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/phantom_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.. [1] http://code.google.com/p/pydocweb
"""
from __future__ import division
from __future__ import division, absolute_import

import imp, sys, compiler, types, os, inspect, re

Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
to make them appear side-by-side, or in floats.
"""
from __future__ import division
from __future__ import division, absolute_import

import sys, os, glob, shutil, imp, warnings, re, textwrap, traceback
import sphinx
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding:utf-8 -*-
from __future__ import division
from __future__ import division, absolute_import

import sys, textwrap

Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/numpydoc/traitsdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.. [2] http://code.enthought.com/projects/traits/
"""
from __future__ import division
from __future__ import division, absolute_import

import inspect
import os
Expand Down
2 changes: 1 addition & 1 deletion doc/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Show a summary about which Numpy functions are documented and which are not.
"""
from __future__ import division
from __future__ import division, absolute_import

import os, glob, re, sys, inspect, optparse
import collections
Expand Down
2 changes: 1 addition & 1 deletion doc/swig/test/testArray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env python
from __future__ import division
from __future__ import division, absolute_import

# System imports
from distutils.util import get_platform
Expand Down
2 changes: 1 addition & 1 deletion doc/swig/test/testFarray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env python
from __future__ import division
from __future__ import division, absolute_import

# System imports
from distutils.util import get_platform
Expand Down
2 changes: 1 addition & 1 deletion doc/swig/test/testFortran.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env python
from __future__ import division
from __future__ import division, absolute_import

# System imports
from distutils.util import get_platform
Expand Down
2 changes: 1 addition & 1 deletion doc/swig/test/testMatrix.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env python
from __future__ import division
from __future__ import division, absolute_import

# System imports
from distutils.util import get_platform
Expand Down
2 changes: 1 addition & 1 deletion doc/swig/test/testTensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env python
from __future__ import division
from __future__ import division, absolute_import

# System imports
from distutils.util import get_platform
Expand Down
2 changes: 1 addition & 1 deletion doc/swig/test/testVector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env python
from __future__ import division
from __future__ import division, absolute_import

# System imports
from distutils.util import get_platform
Expand Down
40 changes: 20 additions & 20 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
Exceptions to this rule are documented.
"""
from __future__ import division
from __future__ import division, absolute_import

# We first need to detect if we're being called as part of the numpy setup
# procedure itself in a reliable manner.
Expand All @@ -126,43 +126,43 @@
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there."""
raise ImportError(msg)
from version import git_revision as __git_revision__
from version import version as __version__
from .version import git_revision as __git_revision__
from .version import version as __version__

from _import_tools import PackageLoader
from ._import_tools import PackageLoader

def pkgload(*packages, **options):
loader = PackageLoader(infunc=True)
return loader(*packages, **options)

import add_newdocs
from . import add_newdocs
__all__ = ['add_newdocs']

pkgload.__doc__ = PackageLoader.__call__.__doc__

from testing import Tester
from .testing import Tester
test = Tester().test
bench = Tester().bench

import core
from core import *
import compat
import lib
from lib import *
import linalg
import fft
import polynomial
import random
import ctypeslib
import ma
import matrixlib as _mat
from matrixlib import *
from . import core
from .core import *
from . import compat
from . import lib
from .lib import *
from . import linalg
from . import fft
from . import polynomial
from . import random
from . import ctypeslib
from . import ma
from . import matrixlib as _mat
from .matrixlib import *

# Make these accessible from numpy name-space
# but not imported in from numpy import *
from __builtin__ import bool, int, long, float, complex, \
object, unicode, str
from core import round, abs, max, min
from .core import round, abs, max, min

__all__.extend(['__version__', 'pkgload', 'PackageLoader',
'show_config'])
Expand Down
2 changes: 1 addition & 1 deletion numpy/_import_tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

import os
import sys
Expand Down
2 changes: 1 addition & 1 deletion numpy/add_newdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
core/fromnumeric.py, core/defmatrix.py up-to-date.
"""
from __future__ import division
from __future__ import division, absolute_import

from numpy.lib import add_newdoc

Expand Down
2 changes: 1 addition & 1 deletion numpy/build_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from __future__ import division
from __future__ import division, absolute_import
2 changes: 1 addition & 1 deletion numpy/build_utils/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

import sys
import copy
Expand Down
4 changes: 2 additions & 2 deletions numpy/build_utils/waf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division
from __future__ import division, absolute_import

import os
import re
Expand All @@ -7,7 +7,7 @@
import waflib.Tools.c_config
from waflib import Logs, Utils

from common \
from .common \
import \
LONG_DOUBLE_REPRESENTATION_SRC, pyod, \
long_double_representation
Expand Down
10 changes: 5 additions & 5 deletions numpy/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* we may only need a small subset of the copied library/module
"""
from __future__ import division
from __future__ import division, absolute_import

import _inspect
import py3k
from _inspect import getargspec, formatargspec
from py3k import *
from . import _inspect
from . import py3k
from ._inspect import getargspec, formatargspec
from .py3k import *

__all__ = []
__all__.extend(_inspect.__all__)
Expand Down
2 changes: 1 addition & 1 deletion numpy/compat/_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
no overhead.
"""
from __future__ import division
from __future__ import division, absolute_import

import types

Expand Down
2 changes: 1 addition & 1 deletion numpy/compat/py3k.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Python 3 compatibility tools.
"""
from __future__ import division
from __future__ import division, absolute_import

__all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception', 'strchar',
'unicode', 'asunicode', 'asbytes_nested', 'asunicode_nested',
Expand Down
Loading

0 comments on commit d4b88c1

Please sign in to comment.