123 lines
4.3 KiB
Diff
123 lines
4.3 KiB
Diff
From f79598b7acc17b8d6c05d7a9fec502f41b7e8be5 Mon Sep 17 00:00:00 2001
|
|
From: Luciano Bello <luciano@debian.org>
|
|
Date: Sat, 27 Oct 2018 16:11:55 -0400
|
|
Subject: [PATCH] Add option git_describe_command
|
|
|
|
The option git_describe_command is added to allow the user to manipulate how `git describe` is called.
|
|
|
|
Fixes #303
|
|
Fixes #283
|
|
---
|
|
CHANGELOG.rst | 2 ++
|
|
README.rst | 7 +++++++
|
|
src/setuptools_scm/__init__.py | 2 ++
|
|
src/setuptools_scm/config.py | 1 +
|
|
src/setuptools_scm/git.py | 5 ++++-
|
|
testing/test_git.py | 15 +++++++++++++++
|
|
6 files changed, 31 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
|
|
index 75ba683f..daa64e6e 100644
|
|
--- a/CHANGELOG.rst
|
|
+++ b/CHANGELOG.rst
|
|
@@ -4,6 +4,8 @@ v3.1.0
|
|
* fix #297 - correct the invocation in version_from_scm and deprecate it as its exposed by accident
|
|
* fix #298 - handle git file listing on empty repositories
|
|
* fix #268 - deprecate ScmVersion.extra
|
|
+* fix #303 and #283 by adding the option `git_describe_command` to allow the user to control the
|
|
+way that `git describe` is called.
|
|
|
|
v3.0.6
|
|
======
|
|
diff --git a/README.rst b/README.rst
|
|
index 4765803b..dc7a4d7d 100644
|
|
--- a/README.rst
|
|
+++ b/README.rst
|
|
@@ -210,6 +210,13 @@ The currently supported configuration keys are:
|
|
defaults to the value of ``setuptools_scm.config.DEFAULT_TAG_REGEX``
|
|
(see `config.py <src/setuptools_scm/config.py>`_).
|
|
|
|
+:git_describe_command:
|
|
+ This command will be used instead the default `git describe` command.
|
|
+ Use with caution, this is a function for advanced use, and you should be
|
|
+ familiar with the setuptools_scm internals to use it.
|
|
+
|
|
+ The default value is set by ``setuptools_scm.git.DEFAULT_DESCRIBE``
|
|
+ (see `git.py <src/setuptools_scm/git.py>`_).
|
|
|
|
To use setuptools_scm in other Python code you can use the
|
|
``get_version`` function:
|
|
diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py
|
|
index 1a39ac0b..f49cce40 100644
|
|
--- a/src/setuptools_scm/__init__.py
|
|
+++ b/src/setuptools_scm/__init__.py
|
|
@@ -121,6 +121,7 @@ def get_version(
|
|
relative_to=None,
|
|
tag_regex=None,
|
|
parse=None,
|
|
+ git_describe_command=None,
|
|
):
|
|
"""
|
|
If supplied, relative_to should be a file from which root may
|
|
@@ -138,6 +139,7 @@ def get_version(
|
|
config.relative_to = relative_to
|
|
config.tag_regex = tag_regex
|
|
config.parse = parse
|
|
+ config.git_describe_command = git_describe_command
|
|
|
|
parsed_version = _do_parse(config)
|
|
|
|
diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py
|
|
index f62f467d..796dd0ba 100644
|
|
--- a/src/setuptools_scm/config.py
|
|
+++ b/src/setuptools_scm/config.py
|
|
@@ -61,6 +61,7 @@ def __init__(self, relative_to=None, root="."):
|
|
self.write_to_template = None
|
|
self.parse = None
|
|
self.tag_regex = DEFAULT_TAG_REGEX
|
|
+ self.git_describe_command = None
|
|
|
|
@property
|
|
def absolute_root(self):
|
|
diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py
|
|
index 8a91ff3c..91644c7f 100644
|
|
--- a/src/setuptools_scm/git.py
|
|
+++ b/src/setuptools_scm/git.py
|
|
@@ -101,9 +101,12 @@ def parse(
|
|
if pre_parse:
|
|
pre_parse(wd)
|
|
|
|
+ if config.git_describe_command:
|
|
+ describe_command = config.git_describe_command
|
|
+
|
|
out, unused_err, ret = wd.do_ex(describe_command)
|
|
if ret:
|
|
- # If 'git describe' failed, try to get the information otherwise.
|
|
+ # If 'git git_describe_command' failed, try to get the information otherwise.
|
|
rev_node = wd.node()
|
|
dirty = wd.is_dirty()
|
|
|
|
diff --git a/testing/test_git.py b/testing/test_git.py
|
|
index 11e2d7b5..a889293b 100644
|
|
--- a/testing/test_git.py
|
|
+++ b/testing/test_git.py
|
|
@@ -191,3 +191,18 @@ def test_git_feature_branch_increments_major(wd):
|
|
wd("git checkout -b feature/fun")
|
|
wd.commit_testfile()
|
|
assert wd.get_version(version_scheme="python-simplified-semver").startswith("1.1.0")
|
|
+
|
|
+
|
|
+@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/303")
|
|
+def test_not_matching_tags(wd):
|
|
+ wd.commit_testfile()
|
|
+ wd("git tag apache-arrow-0.11.1")
|
|
+ wd.commit_testfile()
|
|
+ wd("git tag apache-arrow-js-0.9.9")
|
|
+ wd.commit_testfile()
|
|
+ assert wd.get_version(
|
|
+ tag_regex=r"^apache-arrow-([\.0-9]+)$",
|
|
+ git_describe_command="git describe --dirty --tags --long --exclude *js* ",
|
|
+ ).startswith(
|
|
+ "0.11.2"
|
|
+ )
|