@ -36,7 +36,7 @@ from shore.util import git as _git
from shore.util.classifiers import get_classifiers
from shore.util.license import get_license_metadata , wrap_license_text
from shore.util.resources import walk_package_resources
from shore.util.version import parse_version , bump_version , Version
from shore.util.version import get_commit_distance_version , parse_version , bump_version , Version
from termcolor import colored
from typing import Any , Dict , Iterable , List , Optional , Union
import click
@ -65,43 +65,13 @@ def _get_author_info_from_git():
def _commit_distance_version ( subject : [ Monorepo , Package ] ) - > Version :
""" This function creates a string which describes the version of the
monorepo or package that includes the commit distance and SHA revision
number .
For a mono repository , the full commit distance is used . The same is true
for a single package . For a package inside a mono repository that does not
apply mono versioning , the packages ' local commit distance is used.
This is close to what `git describe --tags` does . An example version number
generated by this function is : `0.1.0-24-gd9ade3f`
Notes :
- The produced version string is not compatible with PEP440 .
- If the tag for the version of * subject * does not exist on the repository ,
it will fall back to 0.0 . 0 as the version number which is treated as
" the beginning of the repository " , even if no tag for this version exists .
- Todo : We could try to find the previous tag for this subject and use
that .
"""
if isinstance ( subject , Package ) and subject . monorepo \
and subject . monorepo . mono_versioning :
subject = subject . monorepo
tag = subject . get_tag ( subject . version )
if _git . rev_parse ( tag ) :
version = subject . version
distance = len ( _git . rev_list ( tag + ' ..HEAD ' , subject . directory ) )
else :
logger . warning ( ' tag " %s " does not exist ' , tag )
version = Version ( ' 0.0.0 ' )
distance = len ( _git . rev_list ( ' HEAD ' , subject . directory ) )
rev = _git . rev_parse ( ' HEAD ' )
return parse_version ( str ( version ) + ' +{}.g{} ' . format ( distance , rev [ : 7 ] ) )
return get_commit_distance_version (
subject . directory ,
subject . version ,
subject . get_tag ( subject . version ) ) or subject . version
def _load_subject ( ) - > Union [ Monorepo , Package , None ] :
@ -611,12 +581,12 @@ def status():
@cli.command ( )
@click.option ( ' --tag ' , ' -t ' , is_flag = True )
@click.option ( ' --gi t ' , ' -g ' , is_flag = True )
def version ( gi t, tag ) :
@click.option ( ' --snapsho t ' , ' -s ' , is_flag = True )
def version ( tag , snapsho t) :
""" Print the current package or repository version. """
subject = _load_subject ( )
version = _commit_distance_version ( subject ) if gi t else subject . version
version = _commit_distance_version ( subject ) if snapsho t else subject . version
if tag :
print ( subject . get_tag ( version ) )
else :