Skip to content

Commit

Permalink
Update Versioneer (#164)
Browse files Browse the repository at this point in the history
* [Bot] Update Versioneer

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: martinfleis <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 13, 2023
1 parent 64d726c commit 215317b
Show file tree
Hide file tree
Showing 2 changed files with 326 additions and 149 deletions.
68 changes: 52 additions & 16 deletions mapclassify/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
# directories (produced by setup.py build) will contain a much shorter file
# that just contains the computed version number.

# This file is released into the public domain. Generated by
# versioneer-0.20 (https://github.com/python-versioneer/python-versioneer)
# This file is released into the public domain.
# Generated by versioneer-0.28
# https://github.com/python-versioneer/python-versioneer

"""Git implementation of _version.py."""

import errno
import functools
import os
import re
import subprocess
import sys
from typing import Callable, Dict


def get_keywords():
Expand All @@ -29,7 +32,7 @@ def get_keywords():
return keywords


class VersioneerConfig: # pylint: disable=too-few-public-methods
class VersioneerConfig:
"""Container for Versioneer configuration parameters."""


Expand All @@ -51,8 +54,8 @@ class NotThisMethod(Exception):
"""Exception raised if a method is not valid for the current scenario."""


LONG_VERSION_PY = {}
HANDLERS = {}
LONG_VERSION_PY: Dict[str, str] = {}
HANDLERS: Dict[str, Dict[str, Callable]] = {}


def register_vcs_handler(vcs, method): # decorator
Expand All @@ -68,11 +71,18 @@ def decorate(f):
return decorate


# pylint:disable=too-many-arguments,consider-using-with # noqa
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
"""Call the given command(s)."""
assert isinstance(commands, list)
process = None

popen_kwargs = {}
if sys.platform == "win32":
# This hides the console window if pythonw.exe is used
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
popen_kwargs["startupinfo"] = startupinfo

for command in commands:
try:
dispcmd = str([command] + args)
Expand All @@ -83,9 +93,10 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr else None),
**popen_kwargs,
)
break
except EnvironmentError:
except OSError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
Expand Down Expand Up @@ -159,7 +170,7 @@ def git_get_keywords(versionfile_abs):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["date"] = mo.group(1)
except EnvironmentError:
except OSError:
pass
return keywords

Expand Down Expand Up @@ -247,7 +258,14 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]

_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
# GIT_DIR can interfere with correct operation of Versioneer.
# It may be intended to be passed to the Versioneer-versioned project,
# but that should not change where we get our version from.
env = os.environ.copy()
env.pop("GIT_DIR", None)
runner = functools.partial(runner, env=env)

_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=not verbose)
if rc != 0:
if verbose:
print("Directory %s not under git control" % root)
Expand All @@ -264,7 +282,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
"--always",
"--long",
"--match",
"%s*" % tag_prefix,
f"{tag_prefix}[[:digit:]]*",
],
cwd=root,
)
Expand Down Expand Up @@ -330,7 +348,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
# TAG-NUM-gHEX
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
if not mo:
# unparseable. Maybe git-describe is misbehaving?
# unparsable. Maybe git-describe is misbehaving?
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
return pieces

Expand All @@ -356,8 +374,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
else:
# HEX: no tags
pieces["closest-tag"] = None
count_out, rc = runner(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
pieces["distance"] = int(count_out) # total number of commits
out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root)
pieces["distance"] = len(out.split()) # total number of commits

# commit date: see ISO-8601 comment in git_versions_from_keywords()
date = runner(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip()
Expand Down Expand Up @@ -429,16 +447,34 @@ def render_pep440_branch(pieces):
return rendered


def pep440_split_post(ver):
"""Split pep440 version string at the post-release segment.
Returns the release segments before the post-release and the
post-release version number (or -1 if no post-release segment is present).
"""
vc = str.split(ver, ".post")
return vc[0], int(vc[1] or 0) if len(vc) == 2 else None


def render_pep440_pre(pieces):
"""TAG[.post0.devDISTANCE] -- No -dirty.
"""TAG[.postN.devDISTANCE] -- No -dirty.
Exceptions:
1: no tags. 0.post0.devDISTANCE
"""
if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
if pieces["distance"]:
rendered += ".post0.dev%d" % pieces["distance"]
# update the post release segment
tag_version, post_version = pep440_split_post(pieces["closest-tag"])
rendered = tag_version
if post_version is not None:
rendered += ".post%d.dev%d" % (post_version + 1, pieces["distance"])
else:
rendered += ".post0.dev%d" % (pieces["distance"])
else:
# no commits, use the tag as the version
rendered = pieces["closest-tag"]
else:
# exception #1
rendered = "0.post0.dev%d" % pieces["distance"]
Expand Down
Loading

0 comments on commit 215317b

Please sign in to comment.