o
    Ni<                     @   s*  d Z ddlmZ ddlmZ ddl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mZ ddlmZ ddlZddlmZ ddlZdd	lmZ d
Zdd dD ZdZdd Zdd Zdd Zdd Zdd Zd*ddZd+ddZdd Zd d! Zd"d# Z d+d$d%Z!d&d' Z"d+d(d)Z#ej$j%Z%dS ),z4
Utilities with minimum-depends for use in setup.py
    )absolute_import)print_function)unicode_literalsN)log)urlparse)git)version)zrequirements.txtztools/pip-requiresc                 C   s   g | ]	}|t jd   qS )r   )sysversion_info).0x r   A/home/ubuntu/.local/lib/python3.10/site-packages/pbr/packaging.py
<listcomp>)   s    r   )zrequirements-py%d.txtztools/pip-requires-py%d)ztest-requirements.txtztools/test-requiresc                  C   s4   t jd} | rtdd | dD S ttt S )NPBR_REQUIREMENTS_FILESc                 s   s    | ]}|  V  qd S Nstripr   fr   r   r   	<genexpr>3   s    z)get_requirements_files.<locals>.<genexpr>,)osenvirongettuplesplitPY_REQUIREMENTS_FILESlistREQUIREMENTS_FILES)filesr   r   r   get_requirements_files0   s   r!   c                 C   s:   g }|  |d}|r|| || d|| |< dS )z5Append a 
 separated list to possibly existing value. 
N)r   appendextendjoin)configkey	text_list	new_valuecurrent_valuer   r   r   append_text_list<   s   

r,   c                 C   s   dd | D S )Nc                 S   s   g | ]
}t j|r|qS r   )r   pathexistsr   r   r   r   r   G   s    z!_any_existing.<locals>.<listcomp>r   )	file_listr   r   r   _any_existingF   s   r0   c              	   C   s   t | }dd |D }|rtd| t dd |D }|D ] }t|d}| dW  d      S 1 s9w   Y  qg S )Nc                 S   s   g | ]}|t v r|qS r   r   r   r   r   r   r   O       z'get_reqs_from_files.<locals>.<listcomp>zSupport for '-pyN'-suffixed requirements files is removed in pbr 5.0 and these files are now ignored. Use environment markers instead. Conflicting files: %rc                 S   s   g | ]}|t vr|qS r   r1   r   r   r   r   r   Y   r2   rr#   )r0   warningswarnDeprecationWarningopenreadr   )requirements_filesexisting
deprecatedrequirements_filefilr   r   r   get_reqs_from_filesK   s   &r>   c                 C   s   t dd|  d S )Na  (?P<PackageName>[\w.-]+)-(?P<GlobalVersion>(?P<VersionTripple>(?P<Major>0|[1-9][0-9]*)\.(?P<Minor>0|[1-9][0-9]*)\.(?P<Patch>0|[1-9][0-9]*)){1}(?P<Tags>(?:\-(?P<Prerelease>(?:(?=[0]{1}[0-9A-Za-z-]{0})(?:[0]{1})|(?=[1-9]{1}[0-9]*[A-Za-z]{0})(?:[0-9]+)|(?=[0-9]*[A-Za-z-]+[0-9A-Za-z-]*)(?:[0-9A-Za-z-]+)){1}(?:\.(?=[0]{1}[0-9A-Za-z-]{0})(?:[0]{1})|\.(?=[1-9]{1}[0-9]*[A-Za-z]{0})(?:[0-9]+)|\.(?=[0-9]*[A-Za-z-]+[0-9A-Za-z-]*)(?:[0-9A-Za-z-]+))*){1}){0,1}(?:\+(?P<Meta>(?:[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))){0,1}))z"\g<PackageName>>=\g<GlobalVersion>)resubgroups)matchr   r   r   egg_fragmenta   s
   
rD   Fc           
      C   s0  | d u rt  } g }t| D ]}| r|drqtd|r q|dr6|dd }|t|g|d7 }qtj	j
|}td|rNtd|}|d	}t|}|jr^td
t|j}n
td|rhd }d}|d urtdd|}|r|d}	|	dk rd }	|d |	 }|| qtd||f  q|S )N#z5^\s*(-i|--index-url|--extra-index-url|--find-links).*z-r    )strip_markersz\s*-e\s+z\s*-e\s+(.*)$   zegg=([^&]+).*$z\s*-f\s+zIndex Locationz#.*$r"   ;r   z[pbr] Excluding %s: %s)r!   r>   r   
startswithr@   rC   	partitionparse_requirementspbr_compat	packagingextract_project_namegroupr   schemerA   rD   fragmentfindr$   r   info)
r9   rH   requirementslinereq_fileproject_nameextracteggreasonsemi_posr   r   r   rM   w   sH   


rM   c                 C   sj   | d u rt  } g }t| D ]%}td|rqtd|r'|tdd| qtd|r2|| q|S )Nz(\s*#)|(\s*$)z\s*-[ef]\s+r"   z+^\s*(https?|git(\+(https|ssh))?|svn|hg)\S*:)r!   r>   r@   rC   r$   rA   )r9   dependency_linksrX   r   r   r   parse_dependency_links   s   
r`   c           
         s   i  |r	|d }nd}t dd|g| }t }d}|dD ])}|  }|  |s0q|t|d  d}|d	d
 |D  q fdd}|d|d |d|d |d|d |d|d |D ]	}	t	
d|	  qh dd  S )a  Calculate the sort of semver increment needed from git history.

    Every commit from HEAD to tag is consider for Sem-Ver metadata lines.
    See the pbr docs for their syntax.

    :return: a dict of kwargs for passing into SemanticVersion.increment.
    z..HEADHEADr   z--pretty=%Bzsem-ver:r#   Nr   c                 S   s   g | ]}|  qS r   r   )r   symbolr   r   r   r      s    z)_get_increment_kwargs.<locals>.<listcomp>c                    s"   | |v rd |< | |  d S d S )NT)discard)rb   symbolsimpactresultr   r   _handle_symbol   s   z-_get_increment_kwargs.<locals>._handle_symbolbugfixpatchfeatureminordeprecationz	api-breakmajorz[pbr] Unknown Sem-Ver symbol %r)r   _run_git_commandsetr   lowerr   rK   lenupdater   rV   pop)
git_dirtagversion_spec	changelogrd   headerrX   new_symbolsrh   rb   r   rf   r   _get_increment_kwargs   s0   

r{   c           	   
   C   s   t j| d}d}t|D ]9\}\}}}t }i }t|D ]}ztj|}|||< || W q t	y8   Y qw |rE|t
| |f  S qd|fS )zReturn the commit data about the most recent tag.

    We use git-describe to find this out, but if there are no
    tags then we fall back to counting commits since the beginning
    of time.
    )ru   r   r"   )r   _iter_log_oneline	enumeraterp   r   r   SemanticVersionfrom_pip_stringadd	Exceptionmax)	ru   rx   	row_countignoredtag_setversion_tagssemver_to_tagrv   semverr   r   r   _get_revno_and_last_tag   s"   r   c                 C   s   t | \}}tj|pd}|dkr|}n|jdi t| |}|dur1||kr1td||d |dkr7|S ||}|durK||}||krK|S |S )a  Calculate a version from a target version in git_dir.

    This is used for untagged versions only. A new version is calculated as
    necessary based on git metadata - distance to tags, current hash, contents
    of commit messages.

    :param git_dir: The git directory we're working from.
    :param target_version: If None, the last tagged version (or 0 if there are
        no tags yet) is incremented as needed to produce an appropriate target
        version following semver rules. Otherwise target_version is used as a
        constraint - if semver rules would result in a newer version then an
        exception is raised.
    :return: A semver version object.
    0r   NzRgit history requires a target version of %(new)s, but target version is %(target)s)newtargetr   )r   r   r~   r   	incrementr{   
ValueErrorto_dev)ru   target_versionrv   distancelast_semvernew_versionnew_dev
target_devr   r   r   _get_version_from_git_target  s*   

r   c                 C   s   t  }|r:zt jddg|dddd}tj|}W n ty0   | r,tj| }nd}Y nw t||}|	 S zt
 W S  tyH   Y dS w )	a  Calculate a version string from git.

    If the revision is tagged, return that. Otherwise calculate a semantic
    version description of the tree.

    The number of revisions since the last tag is included in the dev counter
    in the version for untagged versions.

    :param pre_version: If supplied use this as the target version rather than
        inferring one from the last tag + commit messages.
    describez--exact-matchT)throw_on_error-.Nr"   )r   _run_git_functionsro   replacer   r~   r   r   r   release_stringunicode	NameError)pre_versionru   taggedr   rg   r   r   r   _get_version_from_git:  s0   

	r   c                 C   s   ddg}i }|D ],}zt |d}t|}W d   n1 s w   Y  W q tttjjfy4   Y qw |dd| kr?dS |ddS )zGet the version from package metadata if present.

    This looks for PKG-INFO if present (for sdists), and if not looks
    for METADATA (for wheels) and failing that will return None.
    zPKG-INFOMETADATAr3   NNameVersion)r7   emailmessage_from_fileIOErrorOSErrorerrorsMessageErrorr   )package_namepkg_metadata_filenamespkg_metadatafilenamepkg_metadata_filer   r   r   _get_version_from_pkg_metadataa  s   r   c                 C   sh   t jdt jdd}|r|S t| }|r|S t|}tjd dkr(|d}|r,|S tdj	| d)	a  Get the version of the project.

    First, try getting it from PKG-INFO or METADATA, if it exists. If it does,
    that means we're in a distribution tarball or that install has happened.
    Otherwise, if there is no PKG-INFO or METADATA file, pull the version
    from git.

    We do not support setup.py version sanity in git archive tarballs, nor do
    we support packagers directly sucking our git repo into theirs. We expect
    that a source tarball be made from our git repo - or that if someone wants
    to make a source tarball from a fork of our repo with additional tags in it
    that they understand and desire the results of doing that.

    :param pre_version: The version field from setup.cfg - if set then this
        version will be the next release.
    PBR_VERSIONOSLO_PACKAGE_VERSIONNr   rG   zutf-8a(  Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name {name} was given, but was not able to be found.)name)
r   r   r   r   r   r	   r
   encoder   format)r   r   r   r   r   r   get_versionv  s$   
r   )NFr   )&__doc__
__future__r   r   r   r   email.errorsr   r@   r	   r4   	distutilsr   pbr._compat.fiver   pbr._compat.packagingrN   r   pbr.pbr_jsonr   r   r   TEST_REQUIREMENTS_FILESr!   r,   r0   r>   rD   rM   r`   r{   r   r   r   r   r   pbr_jsonwrite_pbr_jsonr   r   r   r   <module>   sF   


@.
''
0