Skip to content

Commit

Permalink
Avoid passing an emptry string as the tag_regex parameter to `setup…
Browse files Browse the repository at this point in the history
…tools_scm.get_version` (#68)
  • Loading branch information
edgarrmondragon authored Jul 2, 2024
1 parent e186a8b commit 48e8aba
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cov = [
]

[[envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[envs.lint]
detached = true
Expand All @@ -28,7 +28,7 @@ dependencies = [
[envs.lint.scripts]
typing = "mypy --install-types --non-interactive {args:hatch_vcs tests}"
style = [
"ruff {args:.}",
"ruff check {args:.}",
"black --check --diff {args:.}",
]
fmt = [
Expand Down
4 changes: 3 additions & 1 deletion hatch_vcs/version_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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['tag_regex'] = self.config_tag_pattern

# Only set for non-empty strings
if self.config_fallback_version:
Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ skip-string-normalization = true
[tool.ruff]
target-version = "py38"
line-length = 120

[tool.ruff.lint]
select = [
"A",
"B",
Expand Down Expand Up @@ -89,16 +91,16 @@ ignore = [
"FBT002",
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["hatch_vcs"]

[tool.ruff.flake8-quotes]
[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"

[tool.ruff.flake8-tidy-imports]
[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# Tests can use relative imports and assertions
"tests/**/*" = ["TID252", "S101"]

Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def create_project(directory, metadata, *, setup_vcs=True, nested=False):
git('config', '--local', 'user.email', '[email protected]')
git('add', '.')
git('commit', '-m', 'test')
git('tag', '1.2.3')
# TODO: Confirm that creating a tag without a message locally causes tests to hang
git('tag', '1.2.3', '-m', 'test')

if nested:
os.chdir(project_dir)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_version_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-FileCopyrightText: 2022-present Ofek Lev <[email protected]>
#
# SPDX-License-Identifier: MIT
import warnings

import pytest

from hatch_vcs.version_source import VCSVersionSource
Expand All @@ -20,6 +22,23 @@ 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():
warnings.simplefilter('error')
_ = version_source.get_version_data()

def test_custom_tag_pattern_get_version(self, new_project_basic):
config = {'tag-pattern': '(?P<version>.+)'}
version_source = VCSVersionSource(new_project_basic, config)

assert version_source.get_version_data() == {'version': '1.2.3'}


class TestFallbackVersion:
def test_correct(self, new_project_basic):
Expand Down

0 comments on commit 48e8aba

Please sign in to comment.