o
    DDi                     @   sj   d dl mZ d dlmZmZmZmZmZ d dlZ	d dl
mZ d dlmZ er,d dlmZ G dd dZdS )	    )Path)
CollectionDictListMappingTYPE_CHECKINGN)StrPath)MetadataWrapper)	ProviderTc                   @   s   e Zd Z		ddedee ded deded	d
fddZe	d	e
deeef f fddZdddZded	edef fddZded	efddZd
S )FullRepoManager   Frepo_root_dirpaths	providersr
   timeoutuse_pyproject_tomlreturnNc                 C   s0   t || _i | _|| _|| _|| _t|| _dS )a$  
        Given project root directory with pyre and watchman setup, :class:`~libcst.metadata.FullRepoManager`
        handles the inter process communication to read the required full repository cache data for
        metadata provider like :class:`~libcst.metadata.TypeInferenceProvider`.

        :param paths: a collection of paths to access full repository data.
        :param providers: a collection of metadata provider classes require accessing full repository data, currently supports
            :class:`~libcst.metadata.TypeInferenceProvider` and
            :class:`~libcst.metadata.FullyQualifiedNameProvider`.
        :param timeout: number of seconds. Raises `TimeoutExpired <https://docs.python.org/3/library/subprocess.html#subprocess.TimeoutExpired>`_
            when timeout.
        N)r   	root_path_cache_timeout_use_pyproject_toml
_providerslist_paths)selfr   r   r   r   r    r   Z/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/metadata/full_repo_manager.py__init__   s   
zFullRepoManager.__init__c                 C   s   |    | jS )z
        The full repository cache data for all metadata providers passed in the ``providers`` parameter when
        constructing :class:`~libcst.metadata.FullRepoManager`. Each provider is mapped to a mapping of path to cache.
        )resolve_cacher   )r   r   r   r   cache.   s   zFullRepoManager.cachec                 C   sJ   | j s#i }| jD ]}|j}|r|| j| j| j| jd||< q|| _ dS dS )aq  
        Resolve cache for all providers that require it. Normally this is called by
        :meth:`~FullRepoManager.get_cache_for_path` so you do not need to call it
        manually. However, if you intend to do a single cache resolution pass before
        forking, it is a good idea to call this explicitly to control when cache
        resolution happens.
        )r   r   N)r   r   	gen_cacher   r   r   r   )r   r   providerhandlerr   r   r   r   8   s   


zFullRepoManager.resolve_cachepathc                    s2    | j vr	td|    fdd| j D S )aq  
        Retrieve cache for a source file. The file needs to appear in the ``paths`` parameter when
        constructing :class:`~libcst.metadata.FullRepoManager`.

        .. code-block:: python

            manager = FullRepoManager(".", {"a.py", "b.py"}, {TypeInferenceProvider})
            MetadataWrapper(module, cache=manager.get_cache_for_path("a.py"))
        ziThe path needs to be in paths parameter when constructing FullRepoManager for efficient batch processing.c                    s0   i | ]\}}|  D ]\}}| kr
||q
qS r   )items).0r!   files_pathdatar#   r   r   
<dictcomp>^   s    z6FullRepoManager.get_cache_for_path.<locals>.<dictcomp>)r   	Exceptionr   r   r$   )r   r#   r   r)   r   get_cache_for_pathM   s   


z"FullRepoManager.get_cache_for_pathc                 C   s*   t | j|  }| |}t|d|S )a  
        Create a :class:`~libcst.metadata.MetadataWrapper` given a source file path.
        The path needs to be a path relative to project root directory.
        The source code is read and parsed as :class:`~libcst.Module` for
        :class:`~libcst.metadata.MetadataWrapper`.

        .. code-block:: python

            manager = FullRepoManager(".", {"a.py", "b.py"}, {TypeInferenceProvider})
            wrapper = manager.get_metadata_wrapper_for_path("a.py")
        T)cstparse_moduler   	read_textr,   r	   )r   r#   moduler   r   r   r   get_metadata_wrapper_for_pathe   s   
z-FullRepoManager.get_metadata_wrapper_for_path)r   F)r   N)__name__
__module____qualname__r   r   strintboolr   propertyr   r   objectr   r   r,   r	   r1   r   r   r   r   r      s*    
 
	r   )pathlibr   typingr   r   r   r   r   libcstr-   libcst._typesr   libcst.metadata.wrapperr	   libcst.metadata.base_providerr
   r   r   r   r   r   <module>   s   