from __future__ import division, absolute_import, print_function

from .info import __doc__
from numpy.version import version as __version__

# disables OpenBLAS affinity setting of the main thread that limits
# python threads or processes to one core
import os
env_added = []
for envkey in ['OPENBLAS_MAIN_FREE', 'GOTOBLAS_MAIN_FREE']:
    if envkey not in os.environ:
        os.environ[envkey] = '1'
        env_added.append(envkey)

try:
    from . import multiarray
except ImportError as exc:
    msg = """
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: %s
""" % (exc,)
    raise ImportError(msg)
finally:
    for envkey in env_added:
        del os.environ[envkey]
del envkey
del env_added
del os

from . import umath
from . import _internal  # for freeze programs
from . import numerictypes as nt
multiarray.set_typeDict(nt.sctypeDict)
from . import numeric
from .numeric import *
from . import fromnumeric
from .fromnumeric import *
from . import defchararray as char
from . import records as rec
from .records import *
from .memmap import *
from .defchararray import chararray
from . import function_base
from .function_base import *
from . import machar
from .machar import *
from . import getlimits
from .getlimits import *
from . import shape_base
from .shape_base import *
from . import einsumfunc
from .einsumfunc import *
del nt

from .fromnumeric import amax as max, amin as min, round_ as round
from .numeric import absolute as abs

# do this after everything else, to minimize the chance of this misleadingly
# appearing in an import-time traceback
from . import _add_newdocs

__all__ = ['char', 'rec', 'memmap']
__all__ += numeric.__all__
__all__ += fromnumeric.__all__
__all__ += rec.__all__
__all__ += ['chararray']
__all__ += function_base.__all__
__all__ += machar.__all__
__all__ += getlimits.__all__
__all__ += shape_base.__all__
__all__ += einsumfunc.__all__

# Make it possible so that ufuncs can be pickled
#  Here are the loading and unloading functions
# The name numpy.core._ufunc_reconstruct must be
#   available for unpickling to work.
def _ufunc_reconstruct(module, name):
    # The `fromlist` kwarg is required to ensure that `mod` points to the
    # inner-most module rather than the parent package when module name is
    # nested. This makes it possible to pickle non-toplevel ufuncs such as
    # scipy.special.expit for instance.
    mod = __import__(module, fromlist=[name])
    return getattr(mod, name)

def _ufunc_reduce(func):
    from pickle import whichmodule
    name = func.__name__
    return _ufunc_reconstruct, (whichmodule(func, name), name)


import sys
if sys.version_info[0] >= 3:
    import copyreg
else:
    import copy_reg as copyreg

copyreg.pickle(ufunc, _ufunc_reduce, _ufunc_reconstruct)
# Unclutter namespace (must keep _ufunc_reconstruct for unpickling)
del copyreg
del sys
del _ufunc_reduce

from numpy._pytesttester import PytestTester
test = PytestTester(__name__)
del PytestTester

@@ -499,17 +499,101 @@
     
-msg = %22%22%22
+import sys%0A    msg = %22%22%22%0A%0AIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!%0A
 %0AImp
@@ -708,16 +708,42 @@
  numpy.%0A
+Here is how to proceed:%0A- 
 If you'r
@@ -773,16 +773,22 @@
 git repo
+sitory
 , try %60g
@@ -801,16 +801,18 @@
 an -xdf%60
+%0A 
  (remove
@@ -816,17 +816,17 @@
 oves all
-%0A
+ 
 files no
@@ -853,36 +853,951 @@
 rol)
-.  Otherwise reinstall numpy
+ and rebuild numpy.%0A- If you are simply trying to use the numpy version that you have installed:%0A  your installation is broken - please reinstall numpy.%0A- If you have already reinstalled and that did not fix the problem, then:%0A  1. Check that you are using the Python you expect (you're using %25s),%0A     and that you have no directories in your PATH or PYTHONPATH that can%0A     interfere with the Python and numpy versions you're trying to use.%0A  2. If (1) looks fine, you can open a new issue at%0A     https://github.com/numpy/numpy/issues.  Please include details on:%0A     - how you installed Python%0A     - how you installed numpy%0A     - your operating system%0A     - whether or not you have multiple versions of Python installed%0A     - if you built from source, your compiler versions and ideally a build log%0A%0A     Note: this error has many possible causes, so please don't comment on%0A     an existing issue about this - open a new one instead
 .%0A%0AO
@@ -1829,12 +1829,27 @@
  %25 (
+sys.executable, 
 exc
-,
 )%0A  

add clearer message to assist users with failed builds.