Skip to content

Commit ed7e038

Browse files
committed
Use setuptools-scm for single-source version management
1 parent a903594 commit ed7e038

3 files changed

Lines changed: 43 additions & 23 deletions

File tree

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "rehline"
3-
version = "0.1.2"
3+
dynamic = ["version"]
44
description = "Regularized Composite ReLU-ReHU Loss Minimization with Linear Computation and Linear Convergence"
55
authors = [
66
{name = "Ben Dai", email = "bendai@cuhk.edu.hk"},
@@ -18,6 +18,9 @@ dependencies = [
1818
"scikit-learn >= 1.2.2"
1919
]
2020

21+
[tool.setuptools_scm]
22+
tag_prefix = "v"
23+
2124
[pyproject.urls]
2225
homepage = "https://rehline.github.io/"
2326
repository = "https://github.com/softmin/ReHLine-python"
@@ -40,5 +43,5 @@ python_classes = ["Test*"]
4043
python_functions = ["test_*"]
4144

4245
[build-system]
43-
requires = ["requests ~= 2.31.0", "pybind11 ~= 3.0.0", "setuptools >= 80.0.0", "wheel >= 0.42.0"]
46+
requires = ["requests ~= 2.31.0", "pybind11 ~= 3.0.0", "setuptools >= 80.0.0", "wheel >= 0.42.0", "setuptools-scm >= 8.0"]
4447
build-backend = "setuptools.build_meta"

rehline/__init__.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1+
from importlib.metadata import version, PackageNotFoundError
2+
3+
try:
4+
__version__ = version("rehline")
5+
except PackageNotFoundError:
6+
__version__ = "0.0.0.dev0"
7+
18
# Import from internal C++ module
2-
from ._base import (ReHLine_solver, _BaseReHLine,
3-
_make_constraint_rehline_param, _make_loss_rehline_param)
9+
from ._base import (
10+
ReHLine_solver,
11+
_BaseReHLine,
12+
_make_constraint_rehline_param,
13+
_make_loss_rehline_param,
14+
)
415
from ._class import CQR_Ridge, ReHLine, plqERM_Ridge, plqERM_ElasticNet
516
from ._internal import rehline_internal, rehline_result
617
from ._path_sol import plqERM_Ridge_path_sol
718
from ._sklearn_mixin import plq_Ridge_Classifier, plq_Ridge_Regressor
819
from ._mf_class import plqMF_Ridge
9-
from ._data import make_mf_dataset
20+
from ._data import make_mf_dataset
1021
from ._loss import ReHLoss
1122

12-
__all__ = ("_BaseReHLine",
13-
"ReHLine_solver",
14-
"ReHLine",
15-
"plqERM_Ridge",
16-
"CQR_Ridge",
17-
"plqERM_ElasticNet",
18-
"plqMF_Ridge",
19-
"plqERM_Ridge_path_sol",
20-
"plq_Ridge_Classifier",
21-
"plq_Ridge_Regressor",
22-
"_make_loss_rehline_param",
23-
"_make_constraint_rehline_param",
24-
"make_mf_dataset")
23+
__all__ = (
24+
"_BaseReHLine",
25+
"ReHLine_solver",
26+
"ReHLine",
27+
"plqERM_Ridge",
28+
"CQR_Ridge",
29+
"plqERM_ElasticNet",
30+
"plqMF_Ridge",
31+
"plqERM_Ridge_path_sol",
32+
"plq_Ridge_Classifier",
33+
"plq_Ridge_Regressor",
34+
"_make_loss_rehline_param",
35+
"_make_constraint_rehline_param",
36+
"make_mf_dataset",
37+
)

setup.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import requests
66
from pybind11.setup_helpers import Pybind11Extension, build_ext
77
from setuptools import setup
8+
from setuptools_scm import get_version
89

9-
__version__ = "0.1.2"
10+
__version__ = get_version(root=".", relative_to=__file__)
1011

1112
# The main interface is through Pybind11Extension.
1213
# * You can add cxx_std=11/14/17, and then build_ext can be removed.
@@ -20,6 +21,7 @@
2021
# The directory that contains setup.py
2122
SETUP_DIRECTORY = Path(__file__).resolve().parent
2223

24+
2325
# Download Eigen source files
2426
# Modified from https://github.com/tohtsky/irspack/blob/main/setup.py
2527
class get_eigen_include(object):
@@ -51,14 +53,16 @@ def __str__(self) -> str:
5153

5254
return target_dir.name
5355

56+
5457
ext_modules = [
55-
Pybind11Extension("rehline._internal",
58+
Pybind11Extension(
59+
"rehline._internal",
5660
["src/rehline.cpp"],
5761
include_dirs=[get_eigen_include(), "src"],
5862
depends=["src/rehline.h"],
5963
# Example: passing in the version to the compiled code
60-
define_macros=[('VERSION_INFO', __version__)],
61-
),
64+
define_macros=[("VERSION_INFO", __version__)],
65+
),
6266
]
6367

6468
setup(
@@ -80,4 +84,4 @@ def __str__(self) -> str:
8084
)
8185

8286
## build .so file
83-
## $ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) ./src/rehline.cpp -o _internal$(python3-config --extension-suffix)
87+
## $ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) ./src/rehline.cpp -o _internal$(python3-config --extension-suffix)

0 commit comments

Comments
 (0)