o
    LK&h                     @   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_iterable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mkdtemptempdirsappend)selfd r   V/var/www/html/venv/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kwtmp_dir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   r1   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__)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   namer4   
executableendswithdebug	sysconfigget_config_varlibrary_dirsplatform	partitionsplitpathsep)cmd	runsharedrA   equalsvaluer   r   r   fixup_build_extV   s   




rP   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__rQ   )clsr   r   r   combine_markers{   s   rY   )r$   rU   r   r   r-   r4   rE   r   distutils.corer   pytestmore_itertoolsr   rT   usefixturesr   r%   r1   r/   rP   rY   r   r   r   r   <module>   s$    
'
%