o
    =Abz                     @   s   d dl Z d dlZd dlZd dlmZ d dlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ e Zi Zedd	 Zd
d ZG dd deZdS )    N)contextmanager   )
RepositoryRepositoryError)PyGIWarning)get_introspection_module)load_overridesc                 c   s`    t | }dV  |rdS | dv rdS t| durdS t | }tjd| |d t|d dS )aO  A context manager which tries to give helpful warnings
    about missing gi.require_version() which could potentially
    break code if only an older version than expected is installed
    or a new version gets introduced.

    ::

        with _check_require_version("Gtk", stacklevel):
            load_namespace_and_overrides()
    N)GLibGObjectGioz%(namespace)s was imported without specifying a version first. Use gi.require_version('%(namespace)s', '%(version)s') before import to ensure that the right version gets loaded.)	namespaceversion
stacklevel)
repositoryis_registeredgiget_required_versionget_versionwarningswarnr   )r   r   
was_loadedr    r   -/usr/lib/python3/dist-packages/gi/importer.py_check_require_version*   s    


r   c                 C   sV   t jdd }|dkr| rdS dS |dkr| rdS dS |dkr%| r#dS dS | r)dS dS )	a2  Returns the stacklevel value for warnings.warn() for when the warning
    gets emitted by an imported module, but the warning should point at the
    code doing the import.

    Pass import_hook=True if the warning gets generated by an import hook
    (warn() gets called in load_module(), see PEP302)
    N   )   r      )r   r      
   )r   r   )sysversion_info)import_hook
py_versionr   r   r   get_import_stacklevelQ   s   	r$   c                   @   s8   e Zd Zdd Zdd ZdddZddd	Zd
d ZdS )DynamicImporterc                 C   s
   || _ d S N)path)selfr'   r   r   r   __init__k   s   
zDynamicImporter.__init__c                 C   s*   | | jsdS |dd\}}|| jkS )NF.r   )
startswithr'   rsplit)r(   fullnamer'   r   r   r   r   _find_module_checkn   s   
z"DynamicImporter._find_module_checkNc                 C   s   |  |rtj|| S d S r&   )r.   	importlibutilspec_from_loader)r(   r-   r'   targetr   r   r   	find_specu   s   
zDynamicImporter.find_specc                 C   s   |  |r| S d S r&   )r.   )r(   r-   r'   r   r   r   find_moduley   s   
zDynamicImporter.find_modulec           	      C   s   |t jv r
t j| S |dd\}}t|s"t|s"td| tdd}t||d7 zt	|}W n t
yD } zt|d }~ww t|D ]}td|dd	   qJt|}W d    n1 sgw   Y  d
| |_| |_|t j|< |S )Nr*   r   z6cannot import name %s, introspection typelib not foundT)r"   r   zgi.repository.-r   z<%s>)r    modulesr,   r   r   enumerate_versionsImportErrorr$   r   r   r   get_immediate_dependenciesr/   import_modulesplitr   __file__
__loader__)	r(   r-   r'   r   r   introspection_moduleedepdynamic_moduler   r   r   load_module}   s2   






zDynamicImporter.load_module)NNr&   )__name__
__module____qualname__r)   r.   r3   r4   rB   r   r   r   r   r%   g   s    

r%   )r    r   r/   
contextlibr   r   _gir   r   r   moduler   	overridesr   get_defaultr   r6   r   r$   objectr%   r   r   r   r   <module>   s   
&