Skip to content

Commit e16d0df

Browse files
committed
Fix versioning
1 parent aa87fa3 commit e16d0df

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

duckdb_packaging/_versioning.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@
1616

1717
def parse_version(version: str) -> tuple[int, int, int, int, int]:
1818
"""Parse a version string into its components.
19-
19+
2020
Args:
2121
version: Version string (e.g., "1.3.1", "1.3.2.rc3" or "1.3.1.post2")
22-
22+
2323
Returns:
2424
Tuple of (major, minor, patch, post, rc)
25-
25+
2626
Raises:
2727
ValueError: If version format is invalid
2828
"""
2929
match = VERSION_RE.match(version)
3030
if not match:
3131
raise ValueError(f"Invalid version format: {version} (expected X.Y.Z, X.Y.Z.rcM or X.Y.Z.postN)")
32-
32+
3333
major, minor, patch, rc, post = match.groups()
3434
return int(major), int(minor), int(patch), int(post or 0), int(rc or 0)
3535

3636

3737
def format_version(major: int, minor: int, patch: int, post: int = 0, rc: int = 0) -> str:
3838
"""Format version components into a version string.
39-
39+
4040
Args:
4141
major: Major version number
42-
minor: Minor version number
42+
minor: Minor version number
4343
patch: Patch version number
4444
post: Post-release number
4545
rc: RC number
46-
46+
4747
Returns:
4848
Formatted version string
4949
"""
@@ -59,31 +59,31 @@ def format_version(major: int, minor: int, patch: int, post: int = 0, rc: int =
5959

6060
def git_tag_to_pep440(git_tag: str) -> str:
6161
"""Convert git tag format to PEP440 format.
62-
62+
6363
Args:
6464
git_tag: Git tag (e.g., "v1.3.1", "v1.3.1-post1")
65-
65+
6666
Returns:
6767
PEP440 version string (e.g., "1.3.1", "1.3.1.post1")
6868
"""
6969
# Remove 'v' prefix if present
7070
version = git_tag[1:] if git_tag.startswith('v') else git_tag
71-
71+
7272
if "-post" in version:
7373
assert 'rc' not in version
7474
version = version.replace("-post", ".post")
7575
elif '-rc' in version:
7676
version = version.replace("-rc", "rc")
77-
77+
7878
return version
7979

8080

8181
def pep440_to_git_tag(version: str) -> str:
8282
"""Convert PEP440 version to git tag format.
83-
83+
8484
Args:
8585
version: PEP440 version string (e.g., "1.3.1.post1" or "1.3.1rc2")
86-
86+
8787
Returns:
8888
Git tag format (e.g., "v1.3.1-post1")
8989
"""
@@ -98,7 +98,7 @@ def pep440_to_git_tag(version: str) -> str:
9898

9999
def get_current_version() -> Optional[str]:
100100
"""Get the current version from git tags.
101-
101+
102102
Returns:
103103
Current version string or None if no tags exist
104104
"""
@@ -149,16 +149,21 @@ def strip_post_from_version(version: str) -> str:
149149
return re.sub(r"[\.-]post[0-9]+", "", version)
150150

151151

152-
def get_git_describe(repo_path: Optional[pathlib.Path] = None) -> Optional[str]:
152+
def get_git_describe(repo_path: Optional[pathlib.Path] = None, since_major=False, since_minor=False) -> Optional[str]:
153153
"""Get git describe output for version determination.
154-
154+
155155
Returns:
156156
Git describe output or None if no tags exist
157157
"""
158158
cwd = repo_path if repo_path is not None else None
159+
pattern="v*.*.*"
160+
if since_major:
161+
pattern="v*.0.0"
162+
elif since_minor:
163+
pattern="v*.*.0"
159164
try:
160165
result = subprocess.run(
161-
["git", "describe", "--tags", "--long", "--match", "v*.*.*"],
166+
["git", "describe", "--tags", "--long", "--match", pattern],
162167
capture_output=True,
163168
text=True,
164169
check=True,
@@ -167,4 +172,4 @@ def get_git_describe(repo_path: Optional[pathlib.Path] = None) -> Optional[str]:
167172
result.check_returncode()
168173
return result.stdout.strip()
169174
except FileNotFoundError:
170-
raise RuntimeError("git executable can't be found")
175+
raise RuntimeError("git executable can't be found")

duckdb_packaging/build_backend.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030

3131
from duckdb_packaging._versioning import create_git_tag, pep440_to_git_tag, get_git_describe, strip_post_from_version
32-
from duckdb_packaging.setuptools_scm_version import forced_version_from_env
32+
from duckdb_packaging.setuptools_scm_version import forced_version_from_env, MAIN_BRANCH_VERSIONING
3333

3434

3535
_DUCKDB_VERSION_FILENAME = "duckdb_version.txt"
@@ -41,7 +41,7 @@
4141

4242
def _log(msg: str, is_error: bool=False) -> None:
4343
"""Log a message with build backend prefix.
44-
44+
4545
Args:
4646
msg: The message to log.
4747
is_error: If True, log to stderr; otherwise log to stdout.
@@ -51,7 +51,7 @@ def _log(msg: str, is_error: bool=False) -> None:
5151

5252
def _in_git_repository() -> bool:
5353
"""Check if the current directory is inside a git repository.
54-
54+
5555
Returns:
5656
True if .git directory exists, False otherwise.
5757
"""
@@ -129,7 +129,7 @@ def _skbuild_config_add(
129129
key: str, value: Union[List, str], config_settings: Dict[str, Union[List[str],str]], fail_if_exists: bool=False
130130
):
131131
"""Add or modify a configuration setting for scikit-build-core.
132-
132+
133133
This function handles adding values to scikit-build-core configuration settings,
134134
supporting both string and list types with appropriate merging behavior.
135135
@@ -145,7 +145,7 @@ def _skbuild_config_add(
145145
146146
Behavior Rules:
147147
- String value + list setting: value is appended to the list
148-
- String value + string setting: existing value is overridden
148+
- String value + string setting: existing value is overridden
149149
- List value + list setting: existing list is extended
150150
- List value + string setting: raises RuntimeError
151151
@@ -180,18 +180,18 @@ def _skbuild_config_add(
180180

181181
def build_sdist(sdist_directory: str, config_settings: Optional[Dict[str, Union[List[str],str]]] = None) -> str:
182182
"""Build a source distribution using the DuckDB submodule.
183-
183+
184184
This function extracts the DuckDB version from either the git submodule and saves it
185185
to a version file before building the sdist with scikit-build-core. If _FORCED_PEP440_VERSION
186186
was set then we first create a tag on the submodule.
187-
187+
188188
Args:
189189
sdist_directory: Directory where the sdist will be created.
190190
config_settings: Optional build configuration settings.
191-
191+
192192
Returns:
193193
The filename of the created sdist.
194-
194+
195195
Raises:
196196
RuntimeError: If not in a git repository or DuckDB submodule issues.
197197
"""
@@ -201,7 +201,7 @@ def build_sdist(sdist_directory: str, config_settings: Optional[Dict[str, Union[
201201
if _FORCED_PEP440_VERSION is not None:
202202
duckdb_version = pep440_to_git_tag(strip_post_from_version(_FORCED_PEP440_VERSION))
203203
else:
204-
duckdb_version = get_git_describe(repo_path=submodule_path)
204+
duckdb_version = get_git_describe(repo_path=submodule_path, since_minor=MAIN_BRANCH_VERSIONING)
205205
_write_duckdb_long_version(duckdb_version)
206206
return skbuild_build_sdist(sdist_directory, config_settings=config_settings)
207207

@@ -212,19 +212,19 @@ def build_wheel(
212212
metadata_directory: Optional[str] = None,
213213
) -> str:
214214
"""Build a wheel from either git submodule or extracted sdist sources.
215-
215+
216216
This function builds a wheel using scikit-build-core, handling two scenarios:
217217
1. In a git repository: builds directly from the DuckDB submodule
218218
2. In an sdist: reads the saved DuckDB version and passes it to CMake
219-
219+
220220
Args:
221221
wheel_directory: Directory where the wheel will be created.
222222
config_settings: Optional build configuration settings.
223223
metadata_directory: Optional directory for metadata preparation.
224-
224+
225225
Returns:
226226
The filename of the created wheel.
227-
227+
228228
Raises:
229229
RuntimeError: If not in a git repository or sdist environment.
230230
"""
@@ -259,4 +259,4 @@ def build_wheel(
259259
"get_requires_for_build_editable",
260260
"prepare_metadata_for_build_wheel",
261261
"prepare_metadata_for_build_editable",
262-
]
262+
]

duckdb_packaging/setuptools_scm_version.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ def _main_branch_versioning():
2727
def version_scheme(version: Any) -> str:
2828
"""
2929
setuptools_scm version scheme that matches DuckDB's original behavior.
30-
30+
3131
Args:
3232
version: setuptools_scm version object
33-
33+
3434
Returns:
3535
PEP440 compliant version string
3636
"""
3737
print(f"[version_scheme] version object: {version}")
3838
print(f"[version_scheme] version.tag: {version.tag}")
3939
print(f"[version_scheme] version.distance: {version.distance}")
4040
print(f"[version_scheme] version.dirty: {version.dirty}")
41-
41+
4242
# Handle case where tag is None
4343
if version.tag is None:
4444
raise ValueError("Need a valid version. Did you set a fallback_version in pyproject.toml?")
45-
45+
4646
try:
4747
return _bump_version(str(version.tag), version.distance, version.dirty)
4848
except Exception as e:

0 commit comments

Comments
 (0)