o
    “si·*  ã                   @   sÎ   d dl mZ d dlmZ d dlmZ d dlm  mZ d dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ dd	„ ZG d
d„ dejƒZdd„ ZG dd„ dƒZdS )é    )Úpartial)Úglob)Úconvert_pathN)ÚPath)ÚSetuptoolsDeprecationWarning)Úunique_everseenc                 C   s   t  | t  | ¡jtjB ¡ d S ©N)ÚosÚchmodÚstatÚst_modeÚS_IWRITE)Útarget© r   újC:\Users\PC\students\dividedattentionclub\venv\lib\python3.10\site-packages\setuptools/command/build_py.pyÚmake_writable   s   r   c                   @   s”   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zed d!„ ƒZd"S )#Úbuild_pyaX  Enhanced 'build_py' command that includes data files with packages

    The data files are specified via a 'package_data' argument to 'setup()'.
    See 'setuptools.dist.Distribution' for more details.

    Also, this version of the 'build_py' command allows you to specify both
    'py_modules' and 'packages' in the same setup operation.
    c                 C   s@   t j | ¡ | jj| _| jjpi | _d| jv r| jd= g | _d S )NÚ
data_files)Úorigr   Úfinalize_optionsÚdistributionÚpackage_dataÚexclude_package_dataÚ__dict__Ú_build_py__updated_files©Úselfr   r   r   r       s   


zbuild_py.finalize_optionsc                 C   sN   | j s| jsdS | j r|  ¡  | jr|  ¡  |  ¡  |  tjj| dd�¡ dS )z?Build modules, packages, and copy data files to build directoryNr   )Zinclude_bytecode)	Z
py_modulesÚpackagesZbuild_modulesZbuild_packagesÚbuild_package_dataÚbyte_compiler   r   Zget_outputsr   r   r   r   Úrun(   s   zbuild_py.runc                 C   s&   |dkr|   ¡ | _| jS tj | |¡S )zlazily compute data filesr   )Ú_get_data_filesr   r   r   Ú__getattr__)r   Úattrr   r   r   r"   8   s   
zbuild_py.__getattr__c                 C   s.   t j | |||¡\}}|r| j |¡ ||fS r   )r   r   Úbuild_moduler   Úappend)r   ÚmoduleZmodule_fileÚpackageÚoutfileÚcopiedr   r   r   r$   ?   s   zbuild_py.build_modulec                 C   s   |   ¡  tt| j| jpdƒƒS )z?Generate list of '(package,src_dir,build_dir,filenames)' tuplesr   )Úanalyze_manifestÚlistÚmapÚ_get_pkg_data_filesr   r   r   r   r   r!   E   s   zbuild_py._get_data_filesc                 C   s$   | j  di ¡ tt| j| jpdƒƒS )z¡
        Generate list of ``(package,src_dir,build_dir,filenames)`` tuples,
        but without triggering any attempt to analyze or build the manifest.
        Úmanifest_filesr   )r   Ú
setdefaultr+   r,   r-   r   r   r   r   r   Úget_data_files_without_manifestJ   s   z(build_py.get_data_files_without_manifestc                    sJ   |   |¡‰ tjj| jg| d¡ Ž }‡ fdd„|  |ˆ ¡D ƒ}|ˆ ||fS )NÚ.c                    s   g | ]	}t j |ˆ ¡‘qS r   )r	   ÚpathÚrelpath)Ú.0Úfile©Úsrc_dirr   r   Ú
<listcomp>\   s    ÿÿz0build_py._get_pkg_data_files.<locals>.<listcomp>)Úget_package_dirr	   r2   ÚjoinZ	build_libÚsplitÚfind_data_files)r   r'   Ú	build_dirÚ	filenamesr   r6   r   r-   T   s   


þzbuild_py._get_pkg_data_filesc                 C   s`   |   | j||¡}tttdd�|ƒ}tj |¡}tt	j
j|ƒ}t | j |g ¡|¡}|  |||¡S )z6Return filenames for package's data files in 'src_dir'T)Ú	recursive)Ú_get_platform_patternsr   r,   r   r   Ú	itertoolsÚchainÚfrom_iterableÚfilterr	   r2   Úisfiler.   ÚgetÚexclude_data_files)r   r'   r7   ÚpatternsZglobs_expandedZglobs_matchesZ
glob_filesÚfilesr   r   r   r<   b   s   ýþzbuild_py.find_data_filesc           
      C   st   | j D ]4\}}}}|D ]+}tj ||¡}|  tj |¡¡ tj ||¡}|  ||¡\}}	t|ƒ tj |¡}qqdS )z$Copy data files into build directoryN)	r   r	   r2   r:   ZmkpathÚdirnameÚ	copy_filer   Úabspath)
r   r'   r7   r=   r>   Úfilenamer   ÚsrcfileÚoutfr)   r   r   r   r   s   s   úÿzbuild_py.build_package_datac                 C   s   i  | _ }| jjsd S i }| jpdD ]}||t|  |¡ƒ< q|  d¡ tƒ }|  d¡}|j	j
D ]^}tj t|ƒ¡\}}d }	|}
|rd||	krd||vrd|}	tj |¡\}}tj ||¡}|rd||	krd||vsI||v r�||
krs| |¡rrq/n| || |¡}|r‚| |¡ | || g ¡ |¡ q/d S )Nr   Úegg_info)r.   r   Zinclude_package_datar   Úassert_relativer9   Úrun_commandÚ_IncludePackageDataAbuseZget_finalized_commandÚfilelistrI   r	   r2   r;   r:   Ú	is_moduleÚimportable_subpackageÚwarnr/   r%   )r   ÚmfZsrc_dirsr'   ÚcheckZei_cmdr2   ÚdÚfÚprevZoldfZdfÚ
importabler   r   r   r*   ~   s:   


ý
ÿ
€ðzbuild_py.analyze_manifestc                 C   s   d S r   r   r   r   r   r   Úget_data_filesœ   s   zbuild_py.get_data_filesc                 C   sÈ   z| j | W S  ty   Y nw tj | ||¡}|| j |< |r#| jjs%|S | jjD ]}||ks6| |d ¡r8 nq)|S t 	|d¡�}| 
¡ }W d  ƒ n1 sPw   Y  d|vrbtj d|f ¡‚|S )z8Check namespace packages' __init__ for declare_namespacer1   ÚrbNs   declare_namespacezÁNamespace package problem: %s is a namespace package, but its
__init__.py does not call declare_namespace()! Please fix it.
(See the setuptools manual under "Namespace Packages" for details.)
")Úpackages_checkedÚKeyErrorr   r   Úcheck_packager   Únamespace_packagesÚ
startswithÚioÚopenÚreadÚ	distutilsÚerrorsZDistutilsError)r   r'   Zpackage_dirZinit_pyÚpkgr[   Úcontentsr   r   r   rb   Ÿ   s0   ÿ
ÿ
ÿýÿzbuild_py.check_packagec                 C   s   i | _ tj | ¡ d S r   )r`   r   r   Úinitialize_optionsr   r   r   r   rl   ½   s   zbuild_py.initialize_optionsc                 C   s0   t j | |¡}| jjd urtj | jj|¡S |S r   )r   r   r9   r   Zsrc_rootr	   r2   r:   )r   r'   Úresr   r   r   r9   Á   s   zbuild_py.get_package_dirc                    s\   t ˆƒ‰|  | j||¡}‡fdd„|D ƒ}tj |¡}t|ƒ‰ ‡ fdd„ˆD ƒ}t t|ƒƒS )z6Filter filenames for package's data files in 'src_dir'c                 3   s   � | ]	}t  ˆ |¡V  qd S r   )ÚfnmatchrD   ©r4   Úpattern)rI   r   r   Ú	<genexpr>Ï   ó   € z.build_py.exclude_data_files.<locals>.<genexpr>c                 3   s   � | ]	}|ˆ vr|V  qd S r   r   )r4   Úfn)Úbadr   r   rq   Ó   rr   )r+   r@   r   rA   rB   rC   Úsetr   )r   r'   r7   rI   rH   Zmatch_groupsÚmatchesZkeepersr   )rt   rI   r   rG   Ç   s   ýzbuild_py.exclude_data_filesc                    s.   t  |  dg ¡|  |g ¡¡}‡ fdd„|D ƒS )zÜ
        yield platform-specific path patterns (suitable for glob
        or fn_match) from a glob-based spec (such as
        self.package_data or self.exclude_package_data)
        matching package in src_dir.
        Ú c                 3   s"   � | ]}t j ˆ t|ƒ¡V  qd S r   )r	   r2   r:   r   ro   r6   r   r   rq   ã   s
   € ÿ
þz2build_py._get_platform_patterns.<locals>.<genexpr>)rA   rB   rF   )Úspecr'   r7   Zraw_patternsr   r6   r   r@   ×   s   

þ
ýzbuild_py._get_platform_patternsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r"   r$   r!   r0   r-   r<   r   r*   r^   rb   rl   r9   rG   Ústaticmethodr@   r   r   r   r   r      s&    	
r   c                 C   s6   t j | ¡s| S ddlm} t d¡ ¡ |  }||ƒ‚)Nr   )ÚDistutilsSetupErrorzÓ
        Error: setup script specifies an absolute path:

            %s

        setup() arguments must *always* be /-separated paths relative to the
        setup.py directory, *never* absolute paths.
        )r	   r2   ÚisabsÚdistutils.errorsr~   ÚtextwrapÚdedentÚlstrip)r2   r~   Úmsgr   r   r   rQ   ê   s   ÿ	öÿrQ   c                   @   s4   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )rS   z>Inform users that package or module is included as 'data file'a­      Installing {importable!r} as data is deprecated, please list it in `packages`.
    !!


    ############################
    # Package would be ignored #
    ############################
    Python recognizes {importable!r} as an importable package,
    but it is not listed in the `packages` configuration of setuptools.

    {importable!r} has been automatically added to the distribution only
    because it may contain data files, but this behavior is likely to change
    in future versions of setuptools (and therefore is considered deprecated).

    Please make sure that {importable!r} is included as a package by using
    the `packages` configuration field or the proper discovery methods
    (for example by using `find_namespace_packages(...)`/`find_namespace:`
    instead of `find_packages(...)`/`find:`).

    You can read more about "package discovery" and "data files" on setuptools
    documentation page.
    

!!
    c                 C   s   t ƒ | _d S r   )ru   Ú_already_warnedr   r   r   r   Ú__init__  s   z!_IncludePackageDataAbuse.__init__c                 C   s    |  d¡o|d tdƒ …  ¡ S )Nz.py)ÚendswithÚlenÚisidentifier)r   r5   r   r   r   rU     s    z"_IncludePackageDataAbuse.is_modulec                 C   s6   t |ƒj}tt tj|j¡ƒ}|rd |g|¢¡S d S )Nr1   )	r   Úparentr+   rA   Ú	takewhileÚstrr‰   Úpartsr:   )r   rŠ   r5   rj   r�   r   r   r   rV     s
   
z._IncludePackageDataAbuse.importable_subpackagec                 C   sB   || j vrt | j¡j|d�}tj|tdd� | j  |¡ d S d S )N)r]   é   )Ú
stacklevel)	r…   r�   r‚   ÚMESSAGEÚformatÚwarningsrW   r   Úadd)r   r]   r„   r   r   r   rW   &  s
   
ýz_IncludePackageDataAbuse.warnN)	ry   rz   r{   r|   r�   r†   rU   rV   rW   r   r   r   r   rS   ÿ   s    rS   )Ú	functoolsr   r   Zdistutils.utilr   Zdistutils.command.build_pyÚcommandr   r   r	   rn   r�   re   r€   rh   rA   r   r’   Úpathlibr   Zsetuptools._deprecation_warningr   Z setuptools.extern.more_itertoolsr   r   rQ   rS   r   r   r   r   Ú<module>   s(     U