o
    Zh                     @   s   d 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
Z
ddlmZ e
jdG dd dZG dd	 d	Zd
d Zdd Zdd Zdd ZdS )z&Support code for distutils test cases.    N)Distribution)always_iterableZdistutils_managed_tempdirc                   @   s,   e Zd ZdZdd ZdddZddd	Zd
S )TempdirManagerzI
    Mix-in class that handles temporary directories for test cases.
    c                 C   s   t  }| j| |S )zjCreate a temporary directory that will be cleaned up.

        Returns the path of the directory.
        )tempfilemkdtempZtempdirsappend)selfd r
   Z/var/www/html/lang_env/lib/python3.10/site-packages/setuptools/_distutils/tests/support.pyr      s   zTempdirManager.mkdtempxxxc                 C   s   t jt| j|dd dS )zVWrites a file in the given path.

        path can be a string or a sequence.
        zutf-8)encodingN)pathlibPathr   
write_text)r   pathcontentr
   r
   r   
write_file   s   zTempdirManager.write_filefooc                 K   s2   |   }tj||}t| t|d}||fS )a  Will generate a test environment.

        This function creates:
         - a Distribution instance using keywords
         - a temporary directory with a package structure

        It returns the package directory and the distribution
        instance.
        )attrs)r   osr   joinmkdirr   )r   pkg_namekwZtmp_dirZpkg_dirdistr
   r
   r   create_dist&   s
   


zTempdirManager.create_distN)r   )r   )__name__
__module____qualname____doc__r   r   r   r
   r
   r
   r   r      s
    
	r   c                   @   s    e Zd ZdZdd Zdd ZdS )DummyCommandzAClass to store options for retrieval via set_undefined_options().c                 K   s   t | | d S N)varsupdate)r   kwargsr
   r
   r   __init__;   s   zDummyCommand.__init__c                 C   s   d S r"   r
   )r   r
   r
   r   ensure_finalized>   s   zDummyCommand.ensure_finalizedN)r   r   r   r    r&   r'   r
   r
   r
   r   r!   8   s    r!   c                 C   s   t t tj| d dS )ak  Helper for tests that need the xxmodule.c source file.

    Example use:

        def test_compile(self):
            copy_xxmodule_c(self.tmpdir)
            self.assertIn('xxmodule.c', os.listdir(self.tmpdir))

    If the source file can be found, it will be copied to *directory*.  If not,
    the test will be skipped.  Errors during copy are not caught.
    
xxmodule.cN)shutilcopy_get_xxmodule_pathr   r   r   )	directoryr
   r
   r   copy_xxmodule_cB   s   r-   c                  C   s(   t jdkrdnd} tjtjt| S )N)   	   r(   zxxmodule-3.8.c)sysversion_infor   r   r   dirname__file__)Zsource_namer
   r
   r   r+   Q   s   r+   c                 C   s   t jdkrtjd| _dS tdrBtd}|du r"dg| _dS tj	dkr,g | _dS |
d\}}}d	d
 |t jD | _dS dS )a  Function needed to make build_ext tests pass.

    When Python was built with --enable-shared on Unix, -L. is not enough to
    find libpython<blah>.so, because regrtest runs in a tempdir, not in the
    source directory where the .so lives.

    When Python was built with in debug mode on Windows, build_ext commands
    need their debug attribute set, and it is not done automatically for
    some reason.

    This function handles both of these things.  Example use:

        cmd = build_ext(dist)
        support.fixup_build_ext(cmd)
        cmd.ensure_finalized()

    Unlike most other Unix platforms, Mac OS X embeds absolute paths
    to shared libraries into executables, so the fixup is not needed there.
    ntz_d.exePy_ENABLE_SHARED	RUNSHAREDN.darwin=c                 S   s   g | ]}|r|qS r
   r
   ).0r	   r
   r
   r   
<listcomp>x   s    z#fixup_build_ext.<locals>.<listcomp>)r   namer0   
executableendswithdebug	sysconfigget_config_varZlibrary_dirsplatform	partitionsplitpathsep)cmdZ	runsharedr<   equalsvaluer
   r
   r   fixup_build_extV   s   




rI   c                 C   s    dd t | g| jD | _| S )z
    pytest will honor markers as found on the class, but when
    markers are on multiple subclasses, only one appears. Use
    this decorator to combine those markers.
    c                 S   s"   g | ]}t |d g D ]}|q
qS )
pytestmark)getattr)r:   basemarkr
   r
   r   r;      s    
z#combine_markers.<locals>.<listcomp>)	itertoolschain	__bases__rJ   )clsr
   r
   r   combine_markers{   s   rR   )r    rN   r   r   r)   r0   r@   r   Zdistutils.corer   ZpytestZmore_itertoolsr   rM   Zusefixturesr   r!   r-   r+   rI   rR   r
   r
   r
   r   <module>   s$    
'
%