Skip to content

Commit 1fae89f

Browse files
committed
build: add setuptools_scm for git version tracking
1 parent 6d88033 commit 1fae89f

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ htmlcov
4444
pyiceberg/avro/decoder_fast.c
4545
pyiceberg/avro/*.html
4646
pyiceberg/avro/*.so
47+
48+
# Generated version file
49+
pyiceberg/_version.py

build-module.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
allowed_to_fail = os.environ.get("CIBUILDWHEEL", "0") != "1"
2323

2424

25+
def generate_version_file() -> None:
26+
"""Generate the _version.py file using setuptools_scm."""
27+
try:
28+
from setuptools_scm import get_version # type: ignore[import-not-found]
29+
30+
version = get_version(root=".", relative_to=__file__)
31+
print(f"Generated version: {version}")
32+
except Exception as e:
33+
if not allowed_to_fail:
34+
raise
35+
print(f"Warning: Could not generate version file: {e}")
36+
37+
2538
def build_cython_extensions() -> None:
2639
import Cython.Compiler.Options
2740
from Cython.Build import build_ext, cythonize
@@ -65,6 +78,7 @@ def build_cython_extensions() -> None:
6578

6679

6780
try:
81+
generate_version_file()
6882
build_cython_extensions()
6983
except Exception:
7084
if not allowed_to_fail:

pyproject.toml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,38 @@ ignore_missing_imports = true
295295
pyiceberg = "pyiceberg.cli.console:run"
296296

297297
[build-system]
298-
requires = ["poetry-core>=1.0.0", "wheel", "Cython>=3.0.0", "setuptools"]
298+
requires = ["poetry-core>=1.0.0", "wheel", "Cython>=3.0.0", "setuptools", "setuptools-scm>=8.0"]
299299
build-backend = "poetry.core.masonry.api"
300300

301301
[tool.poetry.build]
302302
generate-setup-file = false
303303
script = "build-module.py"
304304

305+
[tool.setuptools_scm]
306+
write_to = "pyiceberg/_version.py"
307+
write_to_template = """# Licensed to the Apache Software Foundation (ASF) under one
308+
# or more contributor license agreements. See the NOTICE file
309+
# distributed with this work for additional information
310+
# regarding copyright ownership. The ASF licenses this file
311+
# to you under the Apache License, Version 2.0 (the
312+
# "License"); you may not use this file except in compliance
313+
# with the License. You may obtain a copy of the License at
314+
#
315+
# http://www.apache.org/licenses/LICENSE-2.0
316+
#
317+
# Unless required by applicable law or agreed to in writing,
318+
# software distributed under the License is distributed on an
319+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
320+
# KIND, either express or implied. See the License for the
321+
# specific language governing permissions and limitations
322+
# under the License.
323+
# Generated by setuptools_scm
324+
325+
__version__ = "{version}"
326+
__version_tuple__ = {version_tuple}
327+
"""
328+
git_describe_command = "git describe --dirty --tags --long --match '*[0-9]*'"
329+
305330
[tool.poetry.extras]
306331
pyarrow = ["pyarrow", "pyiceberg-core"]
307332
pandas = ["pandas", "pyarrow"]
@@ -535,5 +560,9 @@ ignore_missing_imports = true
535560
module = "pyroaring.*"
536561
ignore_missing_imports = true
537562

563+
[[tool.mypy.overrides]]
564+
module = "pyiceberg._version"
565+
ignore_missing_imports = true
566+
538567
[tool.coverage.run]
539568
source = ['pyiceberg/']

0 commit comments

Comments
 (0)