
    .Ph                         d Z ddlZddlZddlZddlZddlmZ dZdZefdZ	eedfdZ
ed	k    r; eej                  d
k    rej        d
         ZneZ e e
e                     dS dS )a  Determine last version string from tags.

Alternate to `Versioneer <https://pypi.python.org/pypi/versioneer/>`_ using
`Dulwich <https://pypi.python.org/pypi/dulwich>`_ to sort tags by time from
newest to oldest.

Copy the following into the package ``__init__.py`` module::

    from dulwich.contrib.release_robot import get_current_version
    __version__ = get_current_version()

This example assumes the tags have a leading "v" like "v0.3", and that the
``.git`` folder is in a project folder that contains the package folder.

EG::

    * project
    |
    * .git
    |
    +-* package
      |
      * __init__.py  <-- put __version__ here


    N   )Repo.z[ a-zA-Z_\-]*([\d\.]+[\-\w\.]*)c                    t          |           5 }|                                }i }|                                D ]J\  }}|                    d          }|                    |          }d|vr5|                    dd          \  }}	 |j        }	t          j        t          j	        |j
                  dd          |j                            d          |j                            d          f}
|                    |	d                   }	n# t          $ r |}	d}
Y nw xY wt          j        t          j	        |	j                  dd          |	j                            d          |	j                            d          |
g||<   L	 ddd           n# 1 swxY w Y   t!          |                                d d	          S )
a  Get list of tags in order from newest to oldest and their datetimes.

    Args:
      projdir: path to ``.git``
    Returns:
      list of tags sorted by commit time from newest to oldest

    Each tag in the list contains the tag name, commit time, commit id, author
    and any tag meta. If a tag isn't annotated, then its tag meta is ``None``.
    Otherwise the tag meta is a tuple containing the tag time, tag id and tag
    name. Time is in UTC.
    zutf-8tags/   N   c                     | d         d         S )Nr	   r    )tags    ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/contrib/release_robot.py<lambda>z!get_recent_tags.<locals>.<lambda>o   s    Aq	     T)keyreverse)r   get_refsitemsdecode
get_objectrsplitobjectdatetimetimegmtimetag_timeidnameAttributeErrorcommit_timeauthorsorted)projdirprojectrefsr   r   valueobj_r   committag_metas              r   get_recent_tagsr+   <   s    
g #'!!**,, 	 	JC**W%%C$$U++C S  ZZQ''FAs7 %t{3<'@'@!'DEFMM'**HOOG,,
 !++F1I66 "        !4;v/A#B#B2A2#FG	  ))$$W--	DII5		# # # # # # # # # # # # # # #L $**,,$9$94HHHHs8   A9F
DA<FDFDA)FFFc                 ,   t          |           }	 |d         d         }n# t          $ r Y dS w xY wt          j        ||          }	 |                    d          }n7# t          t
          f$ r#}|r|                    |           |cY d}~S d}~ww xY w|S )a/  Return the most recent tag, using an options regular expression pattern.

    The default pattern will strip any characters preceding the first semantic
    version. *EG*: "Release-0.2.1-rc.1" will be come "0.2.1-rc.1". If no match
    is found, then the most recent tag is return without modification.

    Args:
      projdir: path to ``.git``
      pattern: regular expression pattern with group that matches version
      logger: a Python logging instance to capture exception
    Returns:
      tag matching first group in regular expression pattern
    r   Nr	   )r+   
IndexErrorrematchgroupr   	exception)r#   patternloggerr   r   matchescurrent_versionerrs           r   get_current_versionr7   r   s     7##D1gaj   hw$$G!--**'    	"S!!!





 s*     
..A B.BBB__main__r	   )r#   )__doc__r   r.   sysr   repor   PROJDIRPATTERNr+   r7   __name__lenargv_PROJDIRprintr   r   r   <module>rC      s   * 6  				 



        
, $ 3I 3I 3I 3Il !(    : z
s38}}q8A;	E

h
/
/
/00000 r   