Skip to content

Commit 6c4d878

Browse files
Build: use setuptools_scm for dynamic versioning compatibility with pyproject.toml
1 parent d3ead1e commit 6c4d878

File tree

3 files changed

+9
-48
lines changed

3 files changed

+9
-48
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ jobs:
192192
python-version: ${{ matrix.python-version }}
193193
cache: pip
194194
- run: pip install build wheel
195-
# for now need to do the below instead of prior `python -m build .`, which didn't allow us to access git tags
196-
- run: python -m build --sdist && python -m build --wheel
195+
- run: python -m build .
197196
- name: Determine and Set Platform Tag, then Tag Wheel
198197
shell: bash
199198
run: |

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools >= 63.0.0"]
2+
requires = ["setuptools >= 63.0.0", "setuptools_scm >= 8.0"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -78,7 +78,11 @@ package-data = { "*" = ["libbitsandbytes*.*"] }
7878
include = ["bitsandbytes*"]
7979

8080
[tool.setuptools.dynamic]
81-
version = {attr = "bitsandbytes.__version__"}
81+
#version = {attr = "bitsandbytes.__version__"}
82+
83+
[tool.setuptools_scm]
84+
local_scheme = "no-local-version"
85+
version_file = "bitsandbytes/_version.py"
8286

8387
[tool.pytest.ini_options]
8488
addopts = "-rP"

setup.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,11 @@
1-
# Copyright (c) Facebook, Inc. and its affiliates.
2-
#
3-
# This source code is licensed under the MIT license found in the
4-
# LICENSE file in the root directory of this source tree.
5-
import glob
6-
import os
7-
import subprocess
8-
91
from setuptools import find_packages, setup
102
from setuptools.dist import Distribution
113

12-
libs = list(glob.glob("./bitsandbytes/libbitsandbytes*.*"))
13-
libs = [os.path.basename(p) for p in libs]
14-
print("libs:", libs)
15-
16-
17-
def get_git_commit_hash():
18-
return subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode("utf-8").strip()
19-
20-
21-
def is_git_tagged_commit():
22-
tags = subprocess.check_output(["git", "tag", "--points-at", "HEAD"]).decode("utf-8").strip()
23-
return bool(tags)
24-
25-
26-
def get_latest_semver_tag():
27-
tags = subprocess.check_output(["git", "tag"], text=True).splitlines()
28-
semver_tags = [tag for tag in tags if tag.count(".") == 2 and all(part.isdigit() for part in tag.split("."))]
29-
if not semver_tags:
30-
print("No valid semantic version tags found, use 1.0.0 defaultly")
31-
semver_tags = ["1.0.0"]
32-
return sorted(semver_tags, key=lambda s: list(map(int, s.split("."))))[-1]
33-
34-
35-
def write_version_file(version, filepath="bitsandbytes/_version.py"):
36-
with open(filepath, "w") as f:
37-
f.write(f'__version__ = "{version}"\n')
38-
39-
40-
def get_version_and_write_to_file():
41-
latest_semver_tag = get_latest_semver_tag()
42-
version = latest_semver_tag if is_git_tagged_commit() else f"{latest_semver_tag}.dev+{get_git_commit_hash()}"
43-
write_version_file(version)
44-
return version
45-
464

47-
# Tested with wheel v0.29.0
5+
# Tested with wheel v0.45.1
486
class BinaryDistribution(Distribution):
497
def has_ext_modules(self):
508
return True
519

5210

53-
setup(version=get_version_and_write_to_file(), packages=find_packages(), distclass=BinaryDistribution)
11+
setup(packages=find_packages(), distclass=BinaryDistribution)

0 commit comments

Comments
 (0)