Your IP : 216.73.216.52


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/pyximport/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/pyximport/__pycache__/pyximport.cpython-37.pyc

B

Z��Z�Z�	@s"dZddlZddlZddlZddlZddlmZmZdZdZ	dZ
dZdZd	d
�Z
dd�Zd
d�Zdd�Zd/dd�Zdd�Zdd�Zd0dd�Zd1dd�ZGdd�de�ZGdd�de�ZGdd �d e�Ze�ZGd!d"�d"e�ZGd#d$�d$e�Zd%d&�Zd2d(d)�Zd*d+�Zd,d-�Z e!d.k�re �dS)3a0
Import hooks; when installed with the install() function, these hooks
allow importing .pyx files as if they were Python modules.

If you want the hook installed every time you run Python
you can add it to your Python version by adding these lines to
sitecustomize.py (which you can create from scratch in site-packages
if it doesn't exist there or somewhere else on your python path)::

    import pyximport
    pyximport.install()

For instance on the Mac with a non-system Python 2.3, you could create
sitecustomize.py with only those two lines at
/usr/local/lib/python2.3/site-packages/sitecustomize.py .

A custom distutils.core.Extension instance and setup() args
(Distribution) for for the build can be defined by a <modulename>.pyxbld
file like:

# examplemod.pyxbld
def make_ext(modname, pyxfilename):
    from distutils.extension import Extension
    return Extension(name = modname,
                     sources=[pyxfilename, 'hello.c'],
                     include_dirs=['/myinclude'] )
def make_setup_args():
    return dict(script_args=["--compiler=mingw32"])

Extra dependencies can be defined by a <modulename>.pyxdep .
See README.

Since Cython 0.11, the :mod:`pyximport` module also has experimental
compilation support for normal Python modules.  This allows you to
automatically run Cython on every .pyx and .py module that Python
imports, including parts of the standard library and installed
packages.  Cython will still fail to compile a lot of Python modules,
in which case the import mechanism will fall back to loading the
Python source modules instead.  The .py import mechanism is installed
like this::

    pyximport.install(pyimport = True)

Running this module as a top-level script will run a test and then print
the documentation.

This code is based on the Py2.3+ import protocol as described in PEP 302.
�N)�zipimporter�ZipImportError�	pyximportz.pyxz.pyxdepz.pyxbldFcCs|r||}t|�dS)N)�print)�message�args�r�F/opt/alt/python37/lib64/python3.7/site-packages/pyximport/pyximport.py�_printAsr
cGstrt||�dS)N)�DEBUG_IMPORTr
)rrrrr	�_debugGsrcGst||�dS)N)r
)rrrrr	�_infoLsr
cCsdS)z,Load a pyrex file given a name and filename.Nr)�name�filenamerrr	�_load_pyrexWsrcCs^t||�\}}|sVt|t�s*|�t���}ddlm}|||gd�}|dk	rVd|i|_||fS)Nr)�	Extension)r�sources�language_level)	�handle_special_build�
isinstance�str�encode�sys�getfilesystemencoding�distutils.extensionr�cython_directives)�modname�pyxfilenamer�
extension_mod�
setup_argsrrrr	�get_distutils_extension[s

r cs�tj�|�dt�d}i}tj���r�t�d�t���}t|dd�}|rj|||�}|r^|j	sjt
d���t|dd�}|r�|�}t|t�s�t
d���t
s�|s�t
d����fdd	�|j	D�|_	||fS)
NrZXXXX�make_extz'make_ext in %s did not return Extension�make_setup_argsz+make_setup_args in %s did not return a dictz'neither make_ext nor make_setup_args %scs"g|]}tj�tj���|��qSr)�os�path�join�dirname)�.0�source)�
special_buildrr	�
<listcomp>�sz(handle_special_build.<locals>.<listcomp>)r#r$�splitext�
PYXBLD_EXT�exists�imp�load_source�open�getattrr�AssertionErrorr�dict�set)rr�extr�modr!r"r)r)r	ros&

rc
Cs�dt�k}tj�|�dt}tj�|�r�t|���}dd�|D�}|g}x2|D]*}tj�tj�	|�|�}|�
t�|��qPW|r�gtdd�<xX|D]P}ddl
m}|||�r�td||�tj�|�}	t�||	|	f�|r�t�|�q�WdS)N�_test_filesrcSsg|]}|���qSr)�strip)r'�dependrrr	r*�sz'handle_dependencies.<locals>.<listcomp>)�newerzRebuilding %s because of %s)�globalsr#r$r+�
PYXDEP_EXTr-r0�	readlinesr%r&�extend�globr7�distutils.dep_utilr:r�getmtime�utime�append)
rZtestingZ
dependfile�depends�filesr9�fullpath�filer:Zfiletimerrr	�handle_dependencies�s(



rHc	Cstj�|�std|��t|�t|||�\}}tj}tj�	�}|�
|�|�d|�}ddlm
}	|	j||||||tjd�}
tj�|
�s�td|
��tj�tj�|
�|d�}t�|�}xB|D]:}
|
|
kr�yt�|
�Wq�tk
r�td|
�Yq�Xq�W|
S)	NzPath does not exist: %s�
build_in_temp�)�pyxbuild)rI�pyxbuild_dirr�inplace�reload_supportzCannot find: %sz_*zCouldn't remove %s)r#r$r-r2rHr �pyxargsrIr�copy�update�pop�rKZ
pyx_to_dllrNr%r&r?�remove�IOErrorr
)rrrLrMrrrrIZsargsrK�so_pathZjunkpathZ	junkstuffr$rrr	�build_module�s0




rWc
Cs4yr|dkr.|r|d}n|}t|||||d�}t�||�}|rXt|d�sXtj�|�g|_|j|kspt	|j|f��Wn�t
k
�r.tjr�|�
d�r�t�||�}|j||d|dfks�t	|j|f��nbt��d}	ddl}
td	||
jt��dd��f�}tjdd
k�r|�|	��ntd||	d��YnX|S)
Nz	.__init__)rMr�__path__z.py�c�o�rzBuilding module %s failed: %s�zraise exc, None, tb)�exc�tb)rWr.Zload_dynamic�hasattrr#r$r&rX�__file__r2�	ExceptionrO� load_py_module_on_import_failure�endswithr/r�exc_info�	traceback�ImportError�format_exception_only�version_info�with_traceback�exec)rrrL�
is_package�
build_inplacerrV�module_namer6r^rer]rrr	�load_module�s.

(rnc@s,eZdZdZedddfdd�Zddd�ZdS)	�PyxImporterz)A meta-path importer for .pyx files.
    NFcCs||_||_||_||_dS)N)�	extensionrLrMr)�selfrprLrMrrrr	�__init__�szPyxImporter.__init__cCsx|tjkrtjsdSy�t�||�\}}\}}}|r:|��|r�|tjkr�tj	�
|d|j�}tj	�|�r�t
||||j|j|jd�S|r�|�|j�r�t
|||j|j|jd�S|tjkr�dStj	�|�d|j}	tj	�|	�r�t
||	|j|j|jd�SWntk
�r
YnX|�d�}
|
d}||j}|�p2tj	}
�x0|
D�]&}d}|�sVt��}nhtj	�|��r�yt|�}|�|�}Wn tttfk
�r��w<YnX|j}ntj	�|��s�tj	�|�}tj	�
||�}|dk	�r<tj	�|��syt�|�Wn&tk
�rtj	�|��s�YnXt |d��}|�!|�WdQRXntj	�|��sN�q<t
|||j|j|jd�SWt"d|�dS)	Nrr)�	init_pathrLrMr)rLrMrr�.����wbz%s not found)#r�modulesrOrNr.�find_module�close�
PKG_DIRECTORYr#r$r%rp�isfile�	PyxLoaderrLrMrrc�C_EXTENSIONr+rf�split�getcwdr�get_datarrU�OSError�isabs�abspathr-�makedirsr0�writer)rq�fullname�package_path�fp�pathnamer5�mode�tyZpkg_fileZpyxpathZ	mod_partsrmZpyx_module_name�pathsr$Zpyx_dataZziZpyx_module_path�frrr	rx�s�







zPyxImporter.find_module)N)�__name__�
__module__�__qualname__�__doc__�PYX_EXTrrrxrrrr	ro�srocs,eZdZdZd�fdd�	Zd	dd�Z�ZS)
�
PyImporterz/A meta-path importer for normal .py files.
    NFcsL|dkrtjd}tt|�|_|jjd|||d�i|_dddddg|_dS)	Nrz.py)rprLrMr�CythonrKzpyximport.pyxbuildzdistutils.extensionzdistutils.sysconfig)rrh�superr�rr�uncompilable_modules�blocked_modules)rqrLrMr)�	__class__rr	rrUs
zPyImporter.__init__c
Cs�|tjkrdS|�d�rdS||jkr*dSt�|�r8tStd|�||jkr�|j|\}}yt�	|�j
}||krtdSWntk
r�YnX|j�|�z�|j
�||�}|dk	�r~|jr�|j}|d}n
|j}|}td||�y4t|||j|j|jd�}tj|||t|j�d�tStk
�r|t�r:ddl}	|	��yt�	|�j
}Wntk
�rdd}YnX||f|j|<d}YnXWd|j��X|S)NzCython.ztrying import of module '%s'z	.__init__z$importer found path %s for module %s)rLrrM)rkr)rrw�
startswithr��_lib_loader�knowsrr�r#�stat�st_mtimer�rCr�rxrsr$rWrLrrM�add_lib�boolrarre�	print_excrR)
rqr�r�r$Z
last_modifiedZnew_last_modified�importerZ	real_namerVrerrr	rx_s`










zPyImporter.find_module)NFN)N)r�r�r�r�rrrx�
__classcell__rr)r�r	r�Rs
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�	LibLoadercCs
i|_dS)N)�_libs)rqrrr	rr�szLibLoader.__init__cCsRy|j|\}}}Wn tk
r4td|��YnXtd||�t||||d�S)Nzinvalid module %sz*Loading shared library module '%s' from %s)rVrk)r��KeyError�
ValueErrorrrn)rqr��source_pathrVrkrrr	rn�szLibLoader.load_modulecCs|||f|j|<dS)N)r�)rqr�r$rVrkrrr	r��szLibLoader.add_libcCs
||jkS)N)r�)rqr�rrr	r��szLibLoader.knowsN)r�r�r�rrrnr�r�rrrr	r��sr�c@seZdZddd�Zdd�ZdS)r|NFcCs8td|||�||_|||_|_||_||_||_dS)Nz8PyxLoader created for loading %s from %s (init path: %s))rr�r$rsrLrMr)rqr�r$rsrLrMrrrr	rr�s
zPyxLoader.__init__cCsh|j|kstd|j|f��|jrJt||j|jd|j|jd�}|jg|_nt||j|j|j|jd�}|S)Nz#invalid module, expected %s, got %sT)rkrlr)rlr)	r�r2rsrnrLrMrr$rX)rqr��modulerrr	rn�s

zPyxLoader.load_module)NNFN)r�r�r�rrrnrrrr	r|�s
	r|c@seZdZdZdZiZdS)�PyxArgsTN)r�r�r��	build_dirrIrrrrr	r��sr�cCs>d}d}x,tjD]"}t|t�rt|t�r.d}qd}qW||fS)NFT)r�	meta_pathrror�)�has_py_importer�has_pyx_importerr�rrr	�_have_importers�s

r�Tc	Cs�|dkri}|s&tj�tj�d�d�}t�a|t_|t_|p>i��t_	|t_
|t_t�\}	}
d\}}|r�|	s�t
|||d�}ddl}
ddl}
ddl}
tj�d|�|r�|
s�t|||d�}tj�|�||fS)amMain entry point. Call this to install the .pyx import hook in
    your meta-path for a single Python process.  If you want it to be
    installed whenever you use Python, add it to your sitecustomize
    (as described above).

    You can pass ``pyimport=True`` to also install the .py import hook
    in your meta-path.  Note, however, that it is highly experimental,
    will not work for most .py files, and will therefore only slow
    down your imports.  Use at your own risk.

    By default, compiled modules will end up in a ``.pyxbld``
    directory in the user's home directory.  Passing a different path
    as ``build_dir`` will override this.

    ``build_in_temp=False`` will produce the C files locally. Working
    with complex dependencies and debugging becomes more easy. This
    can principally interfere with existing files of the same name.
    build_in_temp can be overridden by <modulename>.pyxbld/make_setup_args()
    by a dict item of 'build_in_temp'

    ``setup_args``: dict of arguments for Distribution - see
    distutils.core.setup() . They are extended/overridden by those of
    <modulename>.pyxbld/make_setup_args()

    ``reload_support``:  Enables support for dynamic
    reload(<pyxmodulename>), e.g. after a change in the Cython code.
    Additional files <so_path>.reloadNN may arise on that account, when
    the previously loaded module file cannot be overwritten.

    ``load_py_module_on_import_failure``: If the compilation of a .py
    file succeeds, but the subsequent import fails for some reason,
    retry the import with the normal .py module instead of the
    compiled module.  Note that this may lead to unpredictable results
    for modules that change the system state during their import, as
    the second import will rerun these modifications in whatever state
    the system was left after the import of the compiled module
    failed.

    ``inplace``: Install the compiled module next to the source file.

    ``language_level``: The source language level to use: 2 or 3.
    The default is to use the language level of the current Python
    runtime for .py files and Py2 for .pyx files.
    N�~z.pyxbld)NN)rLrMrr)r#r$r%�
expanduserr�rOr�rIrPrrNrbr�r��Cython.Compiler.MainZCython.Compiler.PipelineZCython.Compiler.Optimizerr��insertrorC)rZpyimportr�rIrrNrbrMrr�r��py_importer�pyx_importerr�rrr	�install�s,0
r�cCsPytj�|�Wntk
r$YnXytj�|�Wntk
rJYnXdS)z#
    Uninstall an import hook.
    N)rr�rTr�)r�r�rrr	�	uninstall3sr�c
Cs`ddl}t|_xDt|�D]8}t||�}yt|dt�Wqttfk
rNYqXqWt|�dS)Nrr�)	�__main__�mod_namer��dirr1�setattr�AttributeError�	TypeError�help)r�r�itemrrr	�	show_docsDs

r�r�)N)NFN)NFFNN)	TFNTNFFFN)"r�r?r.r#r�	zipimportrrr�r�r<r,rr
rr
rr rrHrWrn�objectror�r�r�r|r�r�r�r�r�r�rrrr	�<module>0sF
&

 cG!

L