def get_commit_distance_version(repo_dir: str, version: Version, latest_tag: str) -> Optional[Version]:
    '\n  This function creates a string which describes the version of the\n  monorepo or package that includes the commit distance and SHA revision\n  number.\n\n  For a mono repository, the full commit distance is used. The same is true\n  for a single package. For a package inside a mono repository that does not\n  apply mono versioning, the packages\' local commit distance is used.\n\n  This is close to what `git describe --tags` does. An example version number\n  generated by this function is: `0.1.0+24.gd9ade3f`. If the working state is\n  dirty, `.dirty` will be appended to the local version.\n\n  Notes:\n\n  - If there is no commit distance from the *latest_tag* to the current\n    state of the repository, this function returns None.\n  - The version returned by this function is a PEP440 local version that\n    cannot be used for packages when submitting them to PyPI.\n  - If the tag for the version of *subject* does not exist on the repository,\n    it will fall back to 0.0.0 as the version number which is treated as\n    "the beginning of the repository", even if no tag for this version exists.\n\n    Todo: We could try to find the previous tag for this subject and use that.\n  '
    git = Git(repo_dir)
    dirty = git.has_diff()
    if git.rev_parse(latest_tag):
        distance = len(git.rev_list((latest_tag + '..HEAD')))
    else:
        logger.warning('tag "%s" does not exist', latest_tag)
        version = Version('0.0.0')
        distance = len(git.rev_list('HEAD'))
    if (distance == 0):
        if dirty:
            return parse_version((str(version) + '+dirty'))
        return None
    rev = git.rev_parse('HEAD')
    assert rev, git
    local = '+{}.g{}{}'.format(distance, rev[:7], ('.dirty' if dirty else ''))
    return parse_version((str(version) + local))
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`. If the working state is
dirty, `.dirty` will be appended to the local version.

Notes:

- If there is no commit distance from the *latest_tag* to the current
  state of the repository, this function returns None.
- The version returned by this function is a PEP440 local version that
  cannot be used for packages when submitting them to PyPI.
- 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.
def get_commit_distance_version(repo_dir: str, version: Version, latest_tag: str) -> Optional[Version]:
    '\n  This function creates a string which describes the version of the\n  monorepo or package that includes the commit distance and SHA revision\n  number.\n\n  For a mono repository, the full commit distance is used. The same is true\n  for a single package. For a package inside a mono repository that does not\n  apply mono versioning, the packages\' local commit distance is used.\n\n  This is close to what `git describe --tags` does. An example version number\n  generated by this function is: `0.1.0+24.gd9ade3f`. If the working state is\n  dirty, `.dirty` will be appended to the local version.\n\n  Notes:\n\n  - If there is no commit distance from the *latest_tag* to the current\n    state of the repository, this function returns None.\n  - The version returned by this function is a PEP440 local version that\n    cannot be used for packages when submitting them to PyPI.\n  - If the tag for the version of *subject* does not exist on the repository,\n    it will fall back to 0.0.0 as the version number which is treated as\n    "the beginning of the repository", even if no tag for this version exists.\n\n    Todo: We could try to find the previous tag for this subject and use that.\n  '
    git = Git(repo_dir)
    dirty = git.has_diff()
    if git.rev_parse(latest_tag):
        distance = len(git.rev_list((latest_tag + '..HEAD')))
    else:
        logger.warning('tag "%s" does not exist', latest_tag)
        version = Version('0.0.0')
        distance = len(git.rev_list('HEAD'))
    if (distance == 0):
        if dirty:
            return parse_version((str(version) + '+dirty'))
        return None
    rev = git.rev_parse('HEAD')
    assert rev, git
    local = '+{}.g{}{}'.format(distance, rev[:7], ('.dirty' if dirty else ))
    return parse_version((str(version) + local))