Skip to content

Commit eabf9d5

Browse files
committed
Raise error if both version_file and version_callback are set
1 parent 3a80023 commit eabf9d5

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Changelog
1212

1313
``version_callback`` option is used even if there are some tags in the current branch
1414

15+
.. change::
16+
:tags: core, feature
17+
18+
Raise exception if both ``version_file`` and ``version_callback`` options are set
19+
1520
1.9
1621
----
1722

docs/options/version_callback.rst

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Callback to be used for getting a version number.
77

88
Used by :ref:`version-callback` versioning schema.
99

10+
.. note::
11+
12+
This option conflicts with :ref:`version-file-option`, only one of them can be set.
13+
1014
Type
1115
^^^^^^^^^^^^^^
1216

docs/options/version_file.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ Version file path template for :ref:`version-file` versioning schema.
77

88
.. note::
99

10-
This option is completely ignored if :ref:`version-callback` or :ref:`tag-release` schemas are used.
10+
This option is completely ignored if :ref:`tag-release` schema is used.
11+
12+
.. note::
13+
14+
This option conflicts with :ref:`version-callback-option`, only one of them can be set.
1115

1216
Type
1317
^^^^^

setuptools_git_versioning.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,10 @@ def version_from_git(
385385
tag = get_tag(sort_by=sort_by)
386386

387387
if version_callback is not None:
388-
# TODO: raise exception if both version_callback and version_file are set
388+
if version_file is not None:
389+
raise ValueError(
390+
"Either `version_file` or `version_callback` can be passed, but not both at the same time",
391+
)
389392
return get_version_from_callback(version_callback, package_name)
390393

391394
if tag is None:

tests/test_integration/test_version_callback.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ def test_version_callback_has_more_priority_than_tag(repo, create_config):
160160
assert get_version(repo) == version
161161

162162

163-
def test_version_callback_has_more_priority_than_version_file(repo, create_config):
164-
create_file(repo, "VERSION.txt", "1.2.3")
165-
version = "1.0.0"
166-
167-
create_file(repo, "version.py", VERSION_PY.format(version=version), commit=False)
163+
def test_version_callback_conflicts_with_version_file(repo, create_config):
168164
create_config(
169165
repo,
170166
{
@@ -173,7 +169,8 @@ def test_version_callback_has_more_priority_than_version_file(repo, create_confi
173169
},
174170
)
175171

176-
assert get_version(repo) == version
172+
with pytest.raises(subprocess.CalledProcessError):
173+
get_version(repo)
177174

178175

179176
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)