setuptools-git-versioning 2.1.0__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {setuptools_git_versioning-2.1.0/setuptools_git_versioning.egg-info → setuptools_git_versioning-3.0.0}/PKG-INFO +35 -38
  2. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.0}/README.rst +29 -19
  3. setuptools_git_versioning-3.0.0/pyproject.toml +174 -0
  4. setuptools_git_versioning-3.0.0/setup.cfg +4 -0
  5. setuptools_git_versioning-3.0.0/setuptools_git_versioning/__init__.py +41 -0
  6. setuptools_git_versioning-3.0.0/setuptools_git_versioning/__main__.py +3 -0
  7. setuptools_git_versioning-3.0.0/setuptools_git_versioning/cli.py +36 -0
  8. setuptools_git_versioning-3.0.0/setuptools_git_versioning/defaults.py +26 -0
  9. setuptools_git_versioning-3.0.0/setuptools_git_versioning/factories.py +160 -0
  10. setuptools_git_versioning-3.0.0/setuptools_git_versioning/git.py +87 -0
  11. setuptools_git_versioning-3.0.0/setuptools_git_versioning/log.py +18 -0
  12. setuptools_git_versioning-3.0.0/setuptools_git_versioning/setup.py +150 -0
  13. setuptools_git_versioning-3.0.0/setuptools_git_versioning/subst.py +71 -0
  14. setuptools_git_versioning-3.0.0/setuptools_git_versioning/version.py +213 -0
  15. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.0/setuptools_git_versioning.egg-info}/PKG-INFO +35 -38
  16. setuptools_git_versioning-3.0.0/setuptools_git_versioning.egg-info/SOURCES.txt +19 -0
  17. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.0}/setuptools_git_versioning.egg-info/entry_points.txt +1 -1
  18. setuptools_git_versioning-2.1.0/MANIFEST.in +0 -10
  19. setuptools_git_versioning-2.1.0/requirements.txt +0 -3
  20. setuptools_git_versioning-2.1.0/setup.cfg +0 -14
  21. setuptools_git_versioning-2.1.0/setup.py +0 -68
  22. setuptools_git_versioning-2.1.0/setuptools_git_versioning.egg-info/SOURCES.txt +0 -14
  23. setuptools_git_versioning-2.1.0/setuptools_git_versioning.egg-info/not-zip-safe +0 -1
  24. setuptools_git_versioning-2.1.0/setuptools_git_versioning.py +0 -685
  25. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.0}/LICENSE +0 -0
  26. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.0}/setuptools_git_versioning.egg-info/dependency_links.txt +0 -0
  27. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.0}/setuptools_git_versioning.egg-info/requires.txt +0 -0
  28. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.0}/setuptools_git_versioning.egg-info/top_level.txt +0 -0
@@ -1,11 +1,10 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: setuptools-git-versioning
3
- Version: 2.1.0
4
- Summary: Use git repo data for building a version number according PEP-440
5
- Home-page: https://setuptools-git-versioning.readthedocs.io
6
- Author: dolfinus
7
- Author-email: martinov.m.s.8@gmail.com
3
+ Version: 3.0.0
4
+ Summary: Use git repo data for building a version number according to PEP-440
5
+ Author-email: dolfinus <martinov.m.s.8@gmail.com>
8
6
  License: MIT
7
+ Project-URL: Homepage, https://setuptools-git-versioning.readthedocs.io
9
8
  Project-URL: Documentation, https://setuptools-git-versioning.readthedocs.io
10
9
  Project-URL: Source, https://github.com/dolfinus/setuptools-git-versioning
11
10
  Project-URL: CI/CD, https://github.com/dolfinus/setuptools-git-versioning/actions
@@ -22,7 +21,6 @@ Classifier: Programming Language :: Python :: 3.10
22
21
  Classifier: Programming Language :: Python :: 3.11
23
22
  Classifier: Programming Language :: Python :: 3.12
24
23
  Classifier: Programming Language :: Python :: 3.13
25
- Classifier: License :: OSI Approved :: MIT License
26
24
  Classifier: Operating System :: OS Independent
27
25
  Requires-Python: >=3.7
28
26
  Description-Content-Type: text/x-rst
@@ -30,18 +28,7 @@ License-File: LICENSE
30
28
  Requires-Dist: packaging
31
29
  Requires-Dist: setuptools
32
30
  Requires-Dist: tomli>=2.0.1; python_version < "3.11"
33
- Dynamic: author
34
- Dynamic: author-email
35
- Dynamic: classifier
36
- Dynamic: description
37
- Dynamic: description-content-type
38
- Dynamic: home-page
39
- Dynamic: keywords
40
- Dynamic: license
41
- Dynamic: project-url
42
- Dynamic: requires-dist
43
- Dynamic: requires-python
44
- Dynamic: summary
31
+ Dynamic: license-file
45
32
 
46
33
  *************************
47
34
  setuptools-git-versioning
@@ -69,7 +56,7 @@ setuptools-git-versioning
69
56
  :target: https://results.pre-commit.ci/latest/github/dolfinus/setuptools-git-versioning/master
70
57
 
71
58
  Use git repo data (latest tag, current commit hash, etc) for building a
72
- version number according :pep:`440`.
59
+ version number according to :pep:`440`.
73
60
 
74
61
  **Features:**
75
62
 
@@ -128,7 +115,7 @@ add a section ``tool.setuptools-git-versioning`` with config options, and mark t
128
115
  .. code:: toml
129
116
 
130
117
  [build-system]
131
- requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=2.0,<3", ]
118
+ requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=3.0,<4", ]
132
119
  build-backend = "setuptools.build_meta"
133
120
 
134
121
  [tool.setuptools-git-versioning]
@@ -149,6 +136,31 @@ And check the package version generated (see `command help <https://setuptools-g
149
136
  $ setuptools-git-versioning
150
137
  0.0.1
151
138
 
139
+ When add a git tag:
140
+
141
+ .. code:: bash
142
+
143
+ $ git add .
144
+ $ git commit -m "Test tagged"
145
+ $ git tag 1.2.3
146
+
147
+ And now version is based on git tag:
148
+
149
+ .. code:: bash
150
+
151
+ $ setuptools-git-versioning
152
+ 1.2.3
153
+
154
+ $ echo 1 > uncommitted.change
155
+ $ git add .
156
+ $ setuptools-git-versioning
157
+ 1.2.3.post0+git.d2bc6516.dirty
158
+
159
+ $ git commit -m "Test committed"
160
+ $ setuptools-git-versioning
161
+ 1.2.3.post1+git.d452190b
162
+
163
+
152
164
  ``setup.py``
153
165
  ~~~~~~~~~~~~
154
166
 
@@ -164,22 +176,7 @@ and then add new argument ``setuptools_git_versioning`` with config options:
164
176
  setuptools_git_versioning={
165
177
  "enabled": True,
166
178
  },
167
- setup_requires=["setuptools-git-versioning>=2.0,<3"],
179
+ setup_requires=["setuptools-git-versioning>=3.0,<4"],
168
180
  )
169
181
 
170
- And check the package version generated (see `command help <https://setuptools-git-versioning.readthedocs.io/en/stable/command.html>`_):
171
-
172
- .. code:: bash
173
-
174
- $ python setup.py --version
175
- 0.0.1
176
-
177
- # or
178
-
179
- $ python -m setuptools_git_versioning
180
- 0.0.1
181
-
182
- # or
183
-
184
- $ setuptools-git-versioning
185
- 0.0.1
182
+ Commands are the same as above, plus ``python -m setup.py`` returns the same version.
@@ -24,7 +24,7 @@ setuptools-git-versioning
24
24
  :target: https://results.pre-commit.ci/latest/github/dolfinus/setuptools-git-versioning/master
25
25
 
26
26
  Use git repo data (latest tag, current commit hash, etc) for building a
27
- version number according :pep:`440`.
27
+ version number according to :pep:`440`.
28
28
 
29
29
  **Features:**
30
30
 
@@ -83,7 +83,7 @@ add a section ``tool.setuptools-git-versioning`` with config options, and mark t
83
83
  .. code:: toml
84
84
 
85
85
  [build-system]
86
- requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=2.0,<3", ]
86
+ requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=3.0,<4", ]
87
87
  build-backend = "setuptools.build_meta"
88
88
 
89
89
  [tool.setuptools-git-versioning]
@@ -104,6 +104,31 @@ And check the package version generated (see `command help <https://setuptools-g
104
104
  $ setuptools-git-versioning
105
105
  0.0.1
106
106
 
107
+ When add a git tag:
108
+
109
+ .. code:: bash
110
+
111
+ $ git add .
112
+ $ git commit -m "Test tagged"
113
+ $ git tag 1.2.3
114
+
115
+ And now version is based on git tag:
116
+
117
+ .. code:: bash
118
+
119
+ $ setuptools-git-versioning
120
+ 1.2.3
121
+
122
+ $ echo 1 > uncommitted.change
123
+ $ git add .
124
+ $ setuptools-git-versioning
125
+ 1.2.3.post0+git.d2bc6516.dirty
126
+
127
+ $ git commit -m "Test committed"
128
+ $ setuptools-git-versioning
129
+ 1.2.3.post1+git.d452190b
130
+
131
+
107
132
  ``setup.py``
108
133
  ~~~~~~~~~~~~
109
134
 
@@ -119,22 +144,7 @@ and then add new argument ``setuptools_git_versioning`` with config options:
119
144
  setuptools_git_versioning={
120
145
  "enabled": True,
121
146
  },
122
- setup_requires=["setuptools-git-versioning>=2.0,<3"],
147
+ setup_requires=["setuptools-git-versioning>=3.0,<4"],
123
148
  )
124
149
 
125
- And check the package version generated (see `command help <https://setuptools-git-versioning.readthedocs.io/en/stable/command.html>`_):
126
-
127
- .. code:: bash
128
-
129
- $ python setup.py --version
130
- 0.0.1
131
-
132
- # or
133
-
134
- $ python -m setuptools_git_versioning
135
- 0.0.1
136
-
137
- # or
138
-
139
- $ setuptools-git-versioning
140
- 0.0.1
150
+ Commands are the same as above, plus ``python -m setup.py`` returns the same version.
@@ -0,0 +1,174 @@
1
+ [build-system]
2
+ requires = [
3
+ "packaging",
4
+ "setuptools",
5
+ 'tomli>=2.0.1; python_version<"3.11"',
6
+ "wheel",
7
+ ]
8
+ build-backend = "setuptools.build_meta:__legacy__"
9
+
10
+ [project]
11
+ name = "setuptools-git-versioning"
12
+ version = "3.0.0"
13
+ authors = [{name = "dolfinus", email = "martinov.m.s.8@gmail.com"}]
14
+ license = {text = "MIT"}
15
+ description = "Use git repo data for building a version number according to PEP-440"
16
+ keywords = ["setuptools", "git", "versioning", "pep-440"]
17
+ classifiers = [
18
+ "Framework :: Setuptools Plugin",
19
+ "Intended Audience :: Developers",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.7",
22
+ "Programming Language :: Python :: 3.8",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Operating System :: OS Independent",
29
+ ]
30
+ requires-python = ">=3.7"
31
+ dependencies = [
32
+ "packaging",
33
+ "setuptools",
34
+ 'tomli>=2.0.1; python_version<"3.11"',
35
+ ]
36
+
37
+ [project.readme]
38
+ file = "README.rst"
39
+ content-type = "text/x-rst"
40
+
41
+ [project.urls]
42
+ Homepage = "https://setuptools-git-versioning.readthedocs.io"
43
+ Documentation = "https://setuptools-git-versioning.readthedocs.io"
44
+ Source = "https://github.com/dolfinus/setuptools-git-versioning"
45
+ "CI/CD" = "https://github.com/dolfinus/setuptools-git-versioning/actions"
46
+ Coverage = "https://app.codecov.io/gh/dolfinus/setuptools-git-versioning"
47
+ Tracker = "https://github.com/dolfinus/setuptools-git-versioning/issues"
48
+
49
+ [project.entry-points."distutils.setup_keywords"]
50
+ setuptools_git_versioning = "setuptools_git_versioning:parse_config"
51
+
52
+ [project.entry-points."setuptools.finalize_distribution_options"]
53
+ setuptools_git_versioning = "setuptools_git_versioning:infer_version"
54
+
55
+ [project.entry-points."console_scripts"]
56
+ setuptools-git-versioning = "setuptools_git_versioning.cli:main"
57
+
58
+ [tool.setuptools.packages.find]
59
+ include = ["setuptools_git_versioning*"]
60
+ exclude = ["docs*", "tests*"]
61
+
62
+ [tool.setuptools-git-versioning]
63
+ enabled = true
64
+ dev_template = "{tag}.post{ccount}"
65
+
66
+
67
+ [dependency-groups]
68
+ dev = [
69
+ "ruff~=0.14.11",
70
+ "prek~=0.2.28",
71
+ ]
72
+ test = [
73
+ "build>=1.1.1",
74
+ "coverage>=7.2.7",
75
+ "pytest>=7.4.4",
76
+ "pytest-rerunfailures>=13.0",
77
+ "pytest-xdist>=3.5.0",
78
+ # Some tests need to write TOML, but tomli and tomllib are read-only, and toml package is unmaintained
79
+ "tomli-w>=1.0.0",
80
+ "wheel>=0.42.0",
81
+ ]
82
+ docs = [
83
+ "furo~=2025.12.19",
84
+ "numpydoc~=1.10.0",
85
+ "sphinx~=8.2.3",
86
+ "sphinx-argparse~=0.5.2",
87
+ "sphinx-autodoc-typehints~=3.5.2",
88
+ "sphinx-copybutton~=0.5.2",
89
+ "sphinx-last-updated-by-git~=0.3.8",
90
+ "sphinx-tabs~=3.4.5",
91
+ "sphinxcontrib-towncrier~=0.5.0a0",
92
+ "towncrier~=25.8.0",
93
+ "sphinx-toolbox~=4.1.0",
94
+ ]
95
+
96
+ [tool.uv]
97
+ default-groups = []
98
+
99
+ [tool.uv.dependency-groups]
100
+ dev = {requires-python = ">=3.12"}
101
+ docs = {requires-python = ">=3.12"}
102
+
103
+ [tool.ruff]
104
+ target-version = "py37"
105
+ line-length = 120
106
+
107
+ [tool.ruff.lint]
108
+ select = ["ALL"]
109
+ ignore = ["ARG", "ANN", "A002", "COM812", "D", "TD", "FIX002", "PLC0415"]
110
+
111
+ [tool.ruff.lint.per-file-ignores]
112
+ "docs/conf.py" = ["INP001"]
113
+ "tests/*" = [
114
+ "S",
115
+ "EM101",
116
+ "PLR2004",
117
+ "TRY003",
118
+ "DTZ005",
119
+ ]
120
+
121
+ [tool.mypy]
122
+ follow_imports = "silent"
123
+ ignore_missing_imports = true
124
+ pretty = true
125
+ show_error_codes = true
126
+ strict_optional = true
127
+
128
+ [tool.towncrier]
129
+ name = "setuptools-git-versioning"
130
+ package = "setuptools_git_versioning"
131
+ filename = "docs/changelog/NEXT_RELEASE.rst"
132
+ directory = "docs/changelog/next_release/"
133
+ title_format = "{version} ({project_date})"
134
+ issue_format = ":github:pull:`{issue}`"
135
+
136
+ [[tool.towncrier.type]]
137
+ directory = "breaking"
138
+ name = "Breaking Changes"
139
+ showcontent = true
140
+
141
+ [[tool.towncrier.type]]
142
+ directory = "significant"
143
+ name = "Significant Changes"
144
+ showcontent = true
145
+
146
+ [[tool.towncrier.type]]
147
+ directory = "feature"
148
+ name = "Features"
149
+ showcontent = true
150
+
151
+ [[tool.towncrier.type]]
152
+ directory = "improvement"
153
+ name = "Improvements"
154
+ showcontent = true
155
+
156
+ [[tool.towncrier.type]]
157
+ directory = "bugfix"
158
+ name = "Bug Fixes"
159
+ showcontent = true
160
+
161
+ [[tool.towncrier.type]]
162
+ directory = "dependency"
163
+ name = "Dependencies"
164
+ showcontent = true
165
+
166
+ [[tool.towncrier.type]]
167
+ directory = "doc"
168
+ name = "Doc only Changes"
169
+ showcontent = true
170
+
171
+ [[tool.towncrier.type]]
172
+ directory = "misc"
173
+ name = "Misc"
174
+ showcontent = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,41 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any
4
+
5
+ from setuptools_git_versioning.git import (
6
+ count_since,
7
+ get_all_tags,
8
+ get_branch,
9
+ get_branches,
10
+ get_latest_file_commit,
11
+ get_sha,
12
+ get_tag,
13
+ get_tags,
14
+ is_dirty,
15
+ )
16
+ from setuptools_git_versioning.setup import get_version, infer_version
17
+ from setuptools_git_versioning.version import version_from_git
18
+
19
+ if TYPE_CHECKING:
20
+ from setuptools.dist import Distribution
21
+
22
+
23
+ def parse_config(dist: Distribution, attr: Any, value: Any) -> None:
24
+ "Dummy function used only to register in distutils"
25
+ return
26
+
27
+
28
+ __all__ = [
29
+ "count_since",
30
+ "get_all_tags",
31
+ "get_branch",
32
+ "get_branches",
33
+ "get_latest_file_commit",
34
+ "get_sha",
35
+ "get_tag",
36
+ "get_tags",
37
+ "get_version",
38
+ "infer_version",
39
+ "is_dirty",
40
+ "version_from_git",
41
+ ]
@@ -0,0 +1,3 @@
1
+ from setuptools_git_versioning.cli import main
2
+
3
+ main()
@@ -0,0 +1,36 @@
1
+ import argparse
2
+ import logging
3
+ import sys
4
+
5
+ from setuptools_git_versioning.log import DEBUG, LOG_FORMAT, VERBOSITY_LEVELS
6
+ from setuptools_git_versioning.setup import get_version
7
+
8
+
9
+ def get_parser() -> argparse.ArgumentParser:
10
+ parser = argparse.ArgumentParser(
11
+ prog="setuptools-git-versioning",
12
+ description="Get version based on git information and 'setup.py' or 'pyproject.toml' config",
13
+ )
14
+ parser.add_argument(
15
+ "root",
16
+ type=str,
17
+ default=None,
18
+ nargs="?",
19
+ help="Path to folder containing 'setup.py' or 'pyproject.toml' file. Default: current dir",
20
+ )
21
+ parser.add_argument(
22
+ "--verbose",
23
+ "-v",
24
+ action="count",
25
+ default=0,
26
+ help="Increase verbosity level. Can be used multiple times: -v for INFO messages, -vv for DEBUG",
27
+ )
28
+ return parser
29
+
30
+
31
+ def main():
32
+ parser = get_parser()
33
+ namespace = parser.parse_args()
34
+ log_level = VERBOSITY_LEVELS.get(namespace.verbose, DEBUG)
35
+ logging.basicConfig(level=log_level, format=LOG_FORMAT, stream=sys.stderr)
36
+ print(str(get_version(root=namespace.root))) # noqa: T201
@@ -0,0 +1,26 @@
1
+ from __future__ import annotations
2
+
3
+ DEFAULT_TEMPLATE = "{tag}"
4
+ DEFAULT_DEV_TEMPLATE = "{tag}.post{ccount}+git.{sha}"
5
+ DEFAULT_DIRTY_TEMPLATE = "{tag}.post{ccount}+git.{sha}.dirty"
6
+ DEFAULT_STARTING_VERSION = "0.0.1"
7
+ DEFAULT_SORT_BY = "creatordate"
8
+ DEFAULT_CONFIG = {
9
+ "template": DEFAULT_TEMPLATE,
10
+ "dev_template": DEFAULT_DEV_TEMPLATE,
11
+ "dirty_template": DEFAULT_DIRTY_TEMPLATE,
12
+ "starting_version": DEFAULT_STARTING_VERSION,
13
+ "version_callback": None,
14
+ "version_file": None,
15
+ "count_commits_from_version_file": False,
16
+ "tag_formatter": None,
17
+ "branch_formatter": None,
18
+ "tag_filter": None,
19
+ "sort_by": DEFAULT_SORT_BY,
20
+ }
21
+
22
+
23
+ def set_default_options(config: dict):
24
+ for key, value in DEFAULT_CONFIG.items():
25
+ config.setdefault(key, value)
26
+ return config
@@ -0,0 +1,160 @@
1
+ from __future__ import annotations
2
+
3
+ import importlib
4
+ import inspect
5
+ import logging
6
+ import os
7
+ import re
8
+ import sys
9
+ from typing import Any, Callable
10
+
11
+ from setuptools_git_versioning.log import DEBUG, INFO
12
+
13
+ log = logging.getLogger(__name__)
14
+
15
+
16
+ def add_to_sys_path(root: str | os.PathLike | None) -> None:
17
+ project_root = os.fspath(root) if root else os.getcwd() # noqa: PTH109
18
+ if project_root not in sys.path:
19
+ log.log(DEBUG, "Adding '%s' folder to sys.path", project_root)
20
+ sys.path.insert(0, project_root)
21
+
22
+
23
+ def import_reference(
24
+ ref: str,
25
+ package_name: str | None = None,
26
+ root: str | os.PathLike | None = None,
27
+ ) -> Any:
28
+ if ":" not in ref:
29
+ msg = f"Wrong reference name: {ref}"
30
+ raise NameError(msg)
31
+
32
+ add_to_sys_path(root)
33
+
34
+ module_name, attr = ref.split(":")
35
+ log.log(DEBUG, "Executing 'from %s.%s import %s'", package_name or "", module_name, attr)
36
+ module = importlib.import_module(module_name, package_name)
37
+
38
+ return getattr(module, attr)
39
+
40
+
41
+ def load_callable(
42
+ inp: str,
43
+ package_name: str | None = None,
44
+ root: str | os.PathLike | None = None,
45
+ ) -> Callable:
46
+ ref = import_reference(inp, package_name, root=root)
47
+ if not callable(ref):
48
+ msg = f"{ref} of type {type(ref)} is not callable"
49
+ raise TypeError(msg)
50
+
51
+ return ref
52
+
53
+
54
+ def _callable_factory(
55
+ callable_name: str,
56
+ regexp_or_ref: str | Callable,
57
+ callable_factory: Callable[[str], Callable],
58
+ package_name: str | None = None,
59
+ root: str | os.PathLike | None = None,
60
+ ) -> Callable:
61
+ log.log(INFO, "Parsing %s %r of type %r", callable_name, regexp_or_ref, type(regexp_or_ref).__name__)
62
+
63
+ if callable(regexp_or_ref):
64
+ log.log(DEBUG, "Value is callable with signature %s", inspect.Signature.from_callable(regexp_or_ref))
65
+ return regexp_or_ref
66
+
67
+ try:
68
+ return load_callable(regexp_or_ref, package_name, root=root)
69
+ except (ImportError, NameError) as e:
70
+ log.log(DEBUG, "%s is not a valid function reference: %s", callable_name, e)
71
+
72
+ try:
73
+ return callable_factory(regexp_or_ref)
74
+ except re.error as e:
75
+ log.exception("%s is not valid regexp neither a valid function reference", callable_name)
76
+ msg = f"Cannot parse {callable_name}"
77
+ raise ValueError(msg) from e
78
+
79
+
80
+ def branch_formatter_factory(regexp: str) -> Callable[[str], str]:
81
+ pattern = re.compile(regexp)
82
+
83
+ def branch_formatter(branch: str) -> str:
84
+ match = pattern.match(branch)
85
+ if match:
86
+ return match.group("branch")
87
+
88
+ msg = f"Branch name {branch} does not match regexp '{regexp}'"
89
+ raise ValueError(msg)
90
+
91
+ return branch_formatter
92
+
93
+
94
+ def create_branch_formatter(
95
+ branch_formatter: Callable[[str], str] | str,
96
+ package_name: str | None = None,
97
+ root: str | os.PathLike | None = None,
98
+ ):
99
+ return _callable_factory(
100
+ callable_name="branch_formatter",
101
+ regexp_or_ref=branch_formatter,
102
+ callable_factory=branch_formatter_factory,
103
+ package_name=package_name,
104
+ root=root,
105
+ )
106
+
107
+
108
+ def tag_formatter_factory(regexp: str) -> Callable[[str], str]:
109
+ pattern = re.compile(regexp)
110
+
111
+ def tag_formatter(tag: str) -> str:
112
+ match = pattern.match(tag)
113
+ if match:
114
+ return match.group("tag")
115
+
116
+ msg = f"Tag name {tag} does not match regexp '{regexp}'"
117
+ raise ValueError(msg)
118
+
119
+ return tag_formatter
120
+
121
+
122
+ def create_tag_formatter(
123
+ tag_formatter: Callable[[str], str] | str,
124
+ package_name: str | None = None,
125
+ root: str | os.PathLike | None = None,
126
+ ):
127
+ return _callable_factory(
128
+ callable_name="tag_formatter",
129
+ regexp_or_ref=tag_formatter,
130
+ callable_factory=tag_formatter_factory,
131
+ package_name=package_name,
132
+ root=root,
133
+ )
134
+
135
+
136
+ def tag_filter_factory(regexp: str) -> Callable[[str], str | None]:
137
+ pattern = re.compile(regexp)
138
+
139
+ def tag_filter(tag: str) -> str | None:
140
+ match = pattern.match(tag)
141
+ if match:
142
+ log.info("Matched %s", tag)
143
+ return tag
144
+ return None
145
+
146
+ return tag_filter
147
+
148
+
149
+ def create_tag_filter(
150
+ tag_filter: Callable[[str], str | None] | str,
151
+ package_name: str | None = None,
152
+ root: str | os.PathLike | None = None,
153
+ ):
154
+ return _callable_factory(
155
+ callable_name="tag_filter",
156
+ regexp_or_ref=tag_filter,
157
+ callable_factory=tag_filter_factory,
158
+ package_name=package_name,
159
+ root=root,
160
+ )