From 8971d8af6d0a3c89b570ca2d201be98cc41e3934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Mon, 1 Jul 2024 14:29:32 -0600 Subject: [PATCH] Use default setuptools-scm value for `tag-pattern` instead of empty string Closes https://github.com/ofek/hatch-vcs/issues/67 --- hatch_vcs/version_source.py | 4 +++- tests/test_version_config.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hatch_vcs/version_source.py b/hatch_vcs/version_source.py index 3ad713e..53550f5 100644 --- a/hatch_vcs/version_source.py +++ b/hatch_vcs/version_source.py @@ -53,7 +53,9 @@ def construct_setuptools_scm_config(self): config = deepcopy(self.config_raw_options) config.setdefault('root', self.root) - config.setdefault('tag_regex', self.config_tag_pattern) + # Only set for non-empty strings + if self.config_tag_pattern: + config.setdefault('tag_regex', self.config_tag_pattern) # Only set for non-empty strings if self.config_fallback_version: diff --git a/tests/test_version_config.py b/tests/test_version_config.py index 782a541..2840476 100644 --- a/tests/test_version_config.py +++ b/tests/test_version_config.py @@ -1,6 +1,8 @@ # SPDX-FileCopyrightText: 2022-present Ofek Lev # # SPDX-License-Identifier: MIT +import warnings + import pytest from hatch_vcs.version_source import VCSVersionSource @@ -20,6 +22,17 @@ def test_not_string(self, new_project_basic): with pytest.raises(TypeError, match='option `tag-pattern` must be a string'): _ = version_source.config_tag_pattern + def test_no_tag_pattern(self, new_project_basic): + config = {} + version_source = VCSVersionSource(new_project_basic, config) + + assert version_source.config_tag_pattern == '' + + # Should not raise any deprecation warnings + with warnings.catch_warnings(category=DeprecationWarning): + warnings.simplefilter('error') + _ = version_source.get_version_data() + class TestFallbackVersion: def test_correct(self, new_project_basic):