U
    @vg                     @   s   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZmZ d dlmZ d dlmZ erd dlmZmZmZ d	d
 Zdd ZedddddgZdd ZdS )    )absolute_importN)
namedtuple)sixtoml)InvalidRequirementRequirement)InstallationError)MYPY_CHECK_RUNNING)AnyOptionalListc                 C   s   t | totdd | D S )Nc                 s   s   | ]}t |tjV  qd S )N)
isinstancer   string_types).0item r   ;/tmp/pip-unpacked-wheel-gw11q0wt/pip/_internal/pyproject.py	<genexpr>   s     z"_is_list_of_str.<locals>.<genexpr>)r   listall)objr   r   r   _is_list_of_str   s    
r   c                 C   s2   t j| d}tjr.t|tjr.|t	 }|S )Nzpyproject.toml)
ospathjoinr   PY2r   	text_typeencodesysgetfilesystemencoding)unpacked_source_directoryr   r   r   r   make_pyproject_path   s    r!   BuildSystemDetailsrequiresbackendcheckbackend_pathc              
   C   s  t j|}t j|}|rLtj|dd}t|}W 5 Q R X |d}nd}|rr|sr| dk	rl| sltdd} n<|rd|kr| dk	r| std	|d d} n| dkr|} | dk	st
| sdS |dkrd	d
gdd}|dk	st
d}	d|krt|	j	|dd|d }
t|
s(t|	j	|dd|
D ]B}zt| W n. tk
rj   t|	j	|d	|dY nX q,|d}|dg }g }|dkrd}d	d
g}t|
|||S )aB  Load the pyproject.toml file.

    Parameters:
        use_pep517 - Has the user requested PEP 517 processing? None
                     means the user hasn't explicitly specified.
        pyproject_toml - Location of the project's pyproject.toml file
        setup_py - Location of the project's setup.py file
        req_name - The name of the requirement we're processing (for
                   error reporting)

    Returns:
        None if we should use the legacy code path, otherwise a tuple
        (
            requirements from pyproject.toml,
            name of PEP 517 backend,
            requirements we should check are installed after setting
                up the build environment
            directory paths to import the backend from (backend-path),
                relative to the project root.
        )
    zutf-8)encodingzbuild-systemNzIDisabling PEP 517 processing is invalid: project does not have a setup.pyTbuild-backendzbDisabling PEP 517 processing is invalid: project specifies a build backend of {} in pyproject.tomlzsetuptools>=40.8.0wheelz setuptools.build_meta:__legacy__)r#   r(   zO{package} has a pyproject.toml file that does not comply with PEP 518: {reason}r#   z]it has a 'build-system' table but not 'build-system.requires' which is mandatory in the table)packagereasonz1'build-system.requires' is not a list of strings.z='build-system.requires' contains an invalid requirement: {!r}zbackend-path)r   r   isfileioopenr   loadgetr   formatAssertionErrorr   r   r   r"   )
use_pep517pyproject_tomlsetup_pyreq_namehas_pyproject	has_setupfpp_tomlbuild_systemerror_templater#   requirementr$   r&   r%   r   r   r   load_pyproject_toml*   s    
	




r>   )
__future__r   r-   r   r   collectionsr   pip._vendorr   r   "pip._vendor.packaging.requirementsr   r   pip._internal.exceptionsr   pip._internal.utils.typingr	   typingr
   r   r   r   r!   r"   r>   r   r   r   r   <module>   s&      