setuptools-git-versioning 2.1.0__tar.gz → 3.0.1__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.1}/PKG-INFO +38 -48
  2. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.1}/README.rst +32 -28
  3. setuptools_git_versioning-3.0.1/pyproject.toml +173 -0
  4. setuptools_git_versioning-3.0.1/setup.cfg +4 -0
  5. setuptools_git_versioning-3.0.1/setuptools_git_versioning/__init__.py +41 -0
  6. setuptools_git_versioning-3.0.1/setuptools_git_versioning/__main__.py +3 -0
  7. setuptools_git_versioning-3.0.1/setuptools_git_versioning/cli.py +36 -0
  8. setuptools_git_versioning-3.0.1/setuptools_git_versioning/defaults.py +26 -0
  9. setuptools_git_versioning-3.0.1/setuptools_git_versioning/factories.py +160 -0
  10. setuptools_git_versioning-3.0.1/setuptools_git_versioning/git.py +93 -0
  11. setuptools_git_versioning-3.0.1/setuptools_git_versioning/log.py +18 -0
  12. setuptools_git_versioning-3.0.1/setuptools_git_versioning/setup.py +150 -0
  13. setuptools_git_versioning-3.0.1/setuptools_git_versioning/subst.py +71 -0
  14. setuptools_git_versioning-3.0.1/setuptools_git_versioning/version.py +213 -0
  15. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.1/setuptools_git_versioning.egg-info}/PKG-INFO +38 -48
  16. setuptools_git_versioning-3.0.1/setuptools_git_versioning.egg-info/SOURCES.txt +19 -0
  17. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.1}/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.1}/LICENSE +0 -0
  26. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.1}/setuptools_git_versioning.egg-info/dependency_links.txt +0 -0
  27. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.1}/setuptools_git_versioning.egg-info/requires.txt +0 -0
  28. {setuptools_git_versioning-2.1.0 → setuptools_git_versioning-3.0.1}/setuptools_git_versioning.egg-info/top_level.txt +0 -0
@@ -1,15 +1,13 @@
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.1
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
12
- Project-URL: Coverage, https://app.codecov.io/gh/dolfinus/setuptools-git-versioning
13
11
  Project-URL: Tracker, https://github.com/dolfinus/setuptools-git-versioning/issues
14
12
  Keywords: setuptools,git,versioning,pep-440
15
13
  Classifier: Framework :: Setuptools Plugin
@@ -22,7 +20,6 @@ Classifier: Programming Language :: Python :: 3.10
22
20
  Classifier: Programming Language :: Python :: 3.11
23
21
  Classifier: Programming Language :: Python :: 3.12
24
22
  Classifier: Programming Language :: Python :: 3.13
25
- Classifier: License :: OSI Approved :: MIT License
26
23
  Classifier: Operating System :: OS Independent
27
24
  Requires-Python: >=3.7
28
25
  Description-Content-Type: text/x-rst
@@ -30,18 +27,7 @@ License-File: LICENSE
30
27
  Requires-Dist: packaging
31
28
  Requires-Dist: setuptools
32
29
  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
30
+ Dynamic: license-file
45
31
 
46
32
  *************************
47
33
  setuptools-git-versioning
@@ -63,13 +49,14 @@ setuptools-git-versioning
63
49
  :target: https://setuptools-git-versioning.readthedocs.io
64
50
  .. |Build| image:: https://github.com/dolfinus/setuptools-git-versioning/workflows/Tests/badge.svg
65
51
  :target: https://github.com/dolfinus/setuptools-git-versioning/actions
66
- .. |Coverage| image:: https://codecov.io/gh/dolfinus/setuptools-git-versioning/branch/master/graph/badge.svg?token=GIMVHUTNW4
67
- :target: https://codecov.io/gh/dolfinus/setuptools-git-versioning
52
+ .. |Coverage| image:: https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/
53
+ dolfinus/38b81533c2b8c389db378e3bae7df034/raw/setuptools_git_versioning_badge.json
54
+ :target: https://github.com/dolfinus/setuptools-git-versioning/actions
68
55
  .. |pre-commit.ci| image:: https://results.pre-commit.ci/badge/github/dolfinus/setuptools-git-versioning/master.svg
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
 
@@ -106,13 +93,6 @@ Documentation
106
93
 
107
94
  See https://setuptools-git-versioning.readthedocs.io/en/stable/
108
95
 
109
- .. contribution
110
-
111
- Contribution Guide
112
- ------------------
113
-
114
- See ./CONTRIBUTING.rst
115
-
116
96
  .. installation
117
97
 
118
98
  Install
@@ -128,7 +108,7 @@ add a section ``tool.setuptools-git-versioning`` with config options, and mark t
128
108
  .. code:: toml
129
109
 
130
110
  [build-system]
131
- requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=2.0,<3", ]
111
+ requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=3.0,<4", ]
132
112
  build-backend = "setuptools.build_meta"
133
113
 
134
114
  [tool.setuptools-git-versioning]
@@ -149,6 +129,31 @@ And check the package version generated (see `command help <https://setuptools-g
149
129
  $ setuptools-git-versioning
150
130
  0.0.1
151
131
 
132
+ When add a git tag:
133
+
134
+ .. code:: bash
135
+
136
+ $ git add .
137
+ $ git commit -m "Test tagged"
138
+ $ git tag 1.2.3
139
+
140
+ And now version is based on git tag:
141
+
142
+ .. code:: bash
143
+
144
+ $ setuptools-git-versioning
145
+ 1.2.3
146
+
147
+ $ echo 1 > uncommitted.change
148
+ $ git add .
149
+ $ setuptools-git-versioning
150
+ 1.2.3.post0+git.d2bc6516.dirty
151
+
152
+ $ git commit -m "Test committed"
153
+ $ setuptools-git-versioning
154
+ 1.2.3.post1+git.d452190b
155
+
156
+
152
157
  ``setup.py``
153
158
  ~~~~~~~~~~~~
154
159
 
@@ -164,22 +169,7 @@ and then add new argument ``setuptools_git_versioning`` with config options:
164
169
  setuptools_git_versioning={
165
170
  "enabled": True,
166
171
  },
167
- setup_requires=["setuptools-git-versioning>=2.0,<3"],
172
+ setup_requires=["setuptools-git-versioning>=3.0,<4"],
168
173
  )
169
174
 
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
175
+ Commands are the same as above, plus ``python -m setup.py`` returns the same version.
@@ -18,13 +18,14 @@ setuptools-git-versioning
18
18
  :target: https://setuptools-git-versioning.readthedocs.io
19
19
  .. |Build| image:: https://github.com/dolfinus/setuptools-git-versioning/workflows/Tests/badge.svg
20
20
  :target: https://github.com/dolfinus/setuptools-git-versioning/actions
21
- .. |Coverage| image:: https://codecov.io/gh/dolfinus/setuptools-git-versioning/branch/master/graph/badge.svg?token=GIMVHUTNW4
22
- :target: https://codecov.io/gh/dolfinus/setuptools-git-versioning
21
+ .. |Coverage| image:: https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/
22
+ dolfinus/38b81533c2b8c389db378e3bae7df034/raw/setuptools_git_versioning_badge.json
23
+ :target: https://github.com/dolfinus/setuptools-git-versioning/actions
23
24
  .. |pre-commit.ci| image:: https://results.pre-commit.ci/badge/github/dolfinus/setuptools-git-versioning/master.svg
24
25
  :target: https://results.pre-commit.ci/latest/github/dolfinus/setuptools-git-versioning/master
25
26
 
26
27
  Use git repo data (latest tag, current commit hash, etc) for building a
27
- version number according :pep:`440`.
28
+ version number according to :pep:`440`.
28
29
 
29
30
  **Features:**
30
31
 
@@ -61,13 +62,6 @@ Documentation
61
62
 
62
63
  See https://setuptools-git-versioning.readthedocs.io/en/stable/
63
64
 
64
- .. contribution
65
-
66
- Contribution Guide
67
- ------------------
68
-
69
- See ./CONTRIBUTING.rst
70
-
71
65
  .. installation
72
66
 
73
67
  Install
@@ -83,7 +77,7 @@ add a section ``tool.setuptools-git-versioning`` with config options, and mark t
83
77
  .. code:: toml
84
78
 
85
79
  [build-system]
86
- requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=2.0,<3", ]
80
+ requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=3.0,<4", ]
87
81
  build-backend = "setuptools.build_meta"
88
82
 
89
83
  [tool.setuptools-git-versioning]
@@ -104,6 +98,31 @@ And check the package version generated (see `command help <https://setuptools-g
104
98
  $ setuptools-git-versioning
105
99
  0.0.1
106
100
 
101
+ When add a git tag:
102
+
103
+ .. code:: bash
104
+
105
+ $ git add .
106
+ $ git commit -m "Test tagged"
107
+ $ git tag 1.2.3
108
+
109
+ And now version is based on git tag:
110
+
111
+ .. code:: bash
112
+
113
+ $ setuptools-git-versioning
114
+ 1.2.3
115
+
116
+ $ echo 1 > uncommitted.change
117
+ $ git add .
118
+ $ setuptools-git-versioning
119
+ 1.2.3.post0+git.d2bc6516.dirty
120
+
121
+ $ git commit -m "Test committed"
122
+ $ setuptools-git-versioning
123
+ 1.2.3.post1+git.d452190b
124
+
125
+
107
126
  ``setup.py``
108
127
  ~~~~~~~~~~~~
109
128
 
@@ -119,22 +138,7 @@ and then add new argument ``setuptools_git_versioning`` with config options:
119
138
  setuptools_git_versioning={
120
139
  "enabled": True,
121
140
  },
122
- setup_requires=["setuptools-git-versioning>=2.0,<3"],
141
+ setup_requires=["setuptools-git-versioning>=3.0,<4"],
123
142
  )
124
143
 
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
144
+ Commands are the same as above, plus ``python -m setup.py`` returns the same version.
@@ -0,0 +1,173 @@
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.1"
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
+ Tracker = "https://github.com/dolfinus/setuptools-git-versioning/issues"
47
+
48
+ [project.entry-points."distutils.setup_keywords"]
49
+ setuptools_git_versioning = "setuptools_git_versioning:parse_config"
50
+
51
+ [project.entry-points."setuptools.finalize_distribution_options"]
52
+ setuptools_git_versioning = "setuptools_git_versioning:infer_version"
53
+
54
+ [project.entry-points."console_scripts"]
55
+ setuptools-git-versioning = "setuptools_git_versioning.cli:main"
56
+
57
+ [tool.setuptools.packages.find]
58
+ include = ["setuptools_git_versioning*"]
59
+ exclude = ["docs*", "tests*"]
60
+
61
+ [tool.setuptools-git-versioning]
62
+ enabled = true
63
+ dev_template = "{tag}.post{ccount}"
64
+
65
+
66
+ [dependency-groups]
67
+ dev = [
68
+ "ruff~=0.14.11",
69
+ "prek~=0.2.28",
70
+ ]
71
+ test = [
72
+ "build>=1.1.1",
73
+ "coverage>=7.2.7",
74
+ "pytest>=7.4.4",
75
+ "pytest-rerunfailures>=13.0",
76
+ "pytest-xdist>=3.5.0",
77
+ # Some tests need to write TOML, but tomli and tomllib are read-only, and toml package is unmaintained
78
+ "tomli-w>=1.0.0",
79
+ "wheel>=0.42.0",
80
+ ]
81
+ docs = [
82
+ "furo~=2025.12.19",
83
+ "numpydoc~=1.10.0",
84
+ "sphinx~=8.2.3",
85
+ "sphinx-argparse~=0.5.2",
86
+ "sphinx-autodoc-typehints~=3.5.2",
87
+ "sphinx-copybutton~=0.5.2",
88
+ "sphinx-last-updated-by-git~=0.3.8",
89
+ "sphinx-tabs~=3.4.5",
90
+ "sphinxcontrib-towncrier~=0.5.0a0",
91
+ "towncrier~=25.8.0",
92
+ "sphinx-toolbox~=4.1.0",
93
+ ]
94
+
95
+ [tool.uv]
96
+ default-groups = []
97
+
98
+ [tool.uv.dependency-groups]
99
+ dev = {requires-python = ">=3.12"}
100
+ docs = {requires-python = ">=3.12"}
101
+
102
+ [tool.ruff]
103
+ target-version = "py37"
104
+ line-length = 120
105
+
106
+ [tool.ruff.lint]
107
+ select = ["ALL"]
108
+ ignore = ["ARG", "ANN", "A002", "COM812", "D", "TD", "FIX002", "PLC0415"]
109
+
110
+ [tool.ruff.lint.per-file-ignores]
111
+ "docs/conf.py" = ["INP001"]
112
+ "tests/*" = [
113
+ "S",
114
+ "EM101",
115
+ "PLR2004",
116
+ "TRY003",
117
+ "DTZ005",
118
+ ]
119
+
120
+ [tool.mypy]
121
+ follow_imports = "silent"
122
+ ignore_missing_imports = true
123
+ pretty = true
124
+ show_error_codes = true
125
+ strict_optional = true
126
+
127
+ [tool.towncrier]
128
+ name = "setuptools-git-versioning"
129
+ package = "setuptools_git_versioning"
130
+ filename = "docs/changelog/NEXT_RELEASE.rst"
131
+ directory = "docs/changelog/next_release/"
132
+ title_format = "{version} ({project_date})"
133
+ issue_format = ":github:pull:`{issue}`"
134
+
135
+ [[tool.towncrier.type]]
136
+ directory = "breaking"
137
+ name = "Breaking Changes"
138
+ showcontent = true
139
+
140
+ [[tool.towncrier.type]]
141
+ directory = "significant"
142
+ name = "Significant Changes"
143
+ showcontent = true
144
+
145
+ [[tool.towncrier.type]]
146
+ directory = "feature"
147
+ name = "Features"
148
+ showcontent = true
149
+
150
+ [[tool.towncrier.type]]
151
+ directory = "improvement"
152
+ name = "Improvements"
153
+ showcontent = true
154
+
155
+ [[tool.towncrier.type]]
156
+ directory = "bugfix"
157
+ name = "Bug Fixes"
158
+ showcontent = true
159
+
160
+ [[tool.towncrier.type]]
161
+ directory = "dependency"
162
+ name = "Dependencies"
163
+ showcontent = true
164
+
165
+ [[tool.towncrier.type]]
166
+ directory = "doc"
167
+ name = "Doc only Changes"
168
+ showcontent = true
169
+
170
+ [[tool.towncrier.type]]
171
+ directory = "misc"
172
+ name = "Misc"
173
+ 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
+ )