Skip to content

Commit 3ef897a

Browse files
Merge pull request #316 from 1ucian0/303
adds git describe command option fixes #303 fixes #283
2 parents b72e868 + f79598b commit 3ef897a

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ v3.1.0
44
* fix #297 - correct the invocation in version_from_scm and deprecate it as its exposed by accident
55
* fix #298 - handle git file listing on empty repositories
66
* fix #268 - deprecate ScmVersion.extra
7+
* fix #303 and #283 by adding the option `git_describe_command` to allow the user to control the
8+
way that `git describe` is called.
79

810
v3.0.6
911
======

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ The currently supported configuration keys are:
210210
defaults to the value of ``setuptools_scm.config.DEFAULT_TAG_REGEX``
211211
(see `config.py <src/setuptools_scm/config.py>`_).
212212

213+
:git_describe_command:
214+
This command will be used instead the default `git describe` command.
215+
Use with caution, this is a function for advanced use, and you should be
216+
familiar with the setuptools_scm internals to use it.
217+
218+
The default value is set by ``setuptools_scm.git.DEFAULT_DESCRIBE``
219+
(see `git.py <src/setuptools_scm/git.py>`_).
213220

214221
To use setuptools_scm in other Python code you can use the
215222
``get_version`` function:

src/setuptools_scm/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def get_version(
121121
relative_to=None,
122122
tag_regex=None,
123123
parse=None,
124+
git_describe_command=None,
124125
):
125126
"""
126127
If supplied, relative_to should be a file from which root may
@@ -138,6 +139,7 @@ def get_version(
138139
config.relative_to = relative_to
139140
config.tag_regex = tag_regex
140141
config.parse = parse
142+
config.git_describe_command = git_describe_command
141143

142144
parsed_version = _do_parse(config)
143145

src/setuptools_scm/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(self, relative_to=None, root="."):
6161
self.write_to_template = None
6262
self.parse = None
6363
self.tag_regex = DEFAULT_TAG_REGEX
64+
self.git_describe_command = None
6465

6566
@property
6667
def absolute_root(self):

src/setuptools_scm/git.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ def parse(
101101
if pre_parse:
102102
pre_parse(wd)
103103

104+
if config.git_describe_command:
105+
describe_command = config.git_describe_command
106+
104107
out, unused_err, ret = wd.do_ex(describe_command)
105108
if ret:
106-
# If 'git describe' failed, try to get the information otherwise.
109+
# If 'git git_describe_command' failed, try to get the information otherwise.
107110
rev_node = wd.node()
108111
dirty = wd.is_dirty()
109112

testing/test_git.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,18 @@ def test_git_feature_branch_increments_major(wd):
191191
wd("git checkout -b feature/fun")
192192
wd.commit_testfile()
193193
assert wd.get_version(version_scheme="python-simplified-semver").startswith("1.1.0")
194+
195+
196+
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/303")
197+
def test_not_matching_tags(wd):
198+
wd.commit_testfile()
199+
wd("git tag apache-arrow-0.11.1")
200+
wd.commit_testfile()
201+
wd("git tag apache-arrow-js-0.9.9")
202+
wd.commit_testfile()
203+
assert wd.get_version(
204+
tag_regex=r"^apache-arrow-([\.0-9]+)$",
205+
git_describe_command="git describe --dirty --tags --long --exclude *js* ",
206+
).startswith(
207+
"0.11.2"
208+
)

0 commit comments

Comments
 (0)