Skip to content

Commit fac9a7e

Browse files
authored
Modernize build versioning (#79)
1 parent 6a78143 commit fac9a7e

7 files changed

Lines changed: 51 additions & 16 deletions

File tree

.bumpversion.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches:
77
- master
88
tags:
9-
- '*'
9+
- 'v*'
1010

1111
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
1212
# Only cancels-in-progress on PRs (head_ref only defined in PR, fallback run_id always unique)
@@ -21,6 +21,8 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0 # setuptools-scm needs tags to compute the version
2426

2527
- uses: actions/setup-python@v5
2628
with:
@@ -45,6 +47,8 @@ jobs:
4547

4648
steps:
4749
- uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0 # setuptools-scm needs tags to compute the version
4852

4953
- name: Build wheels
5054
uses: pypa/cibuildwheel@v2.22.0
@@ -64,6 +68,8 @@ jobs:
6468
runs-on: ubuntu-latest
6569
steps:
6670
- uses: actions/checkout@v4
71+
with:
72+
fetch-depth: 0 # setuptools-scm needs tags to compute the version
6773

6874
- name: Build sdist
6975
run: pipx run build --sdist
@@ -80,7 +86,7 @@ jobs:
8086
environment: pypi
8187
permissions:
8288
id-token: write
83-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
89+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
8490
steps:
8591
- uses: actions/download-artifact@v4
8692
with:
@@ -101,4 +107,3 @@ jobs:
101107
- uses: pypa/gh-action-pypi-publish@release/v1
102108
with:
103109
verbose: true
104-
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ share/python-wheels/
2727
.installed.cfg
2828
*.egg
2929
MANIFEST
30+
src/diffcp/_version.py
3031

3132
# PyInstaller
3233
# Usually these files are written by a python script from a template

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ python_add_library(_diffcp MODULE cpp/src/wrapper.cpp cpp/src/deriv.cpp cpp/src/
2020
target_link_libraries(_diffcp PRIVATE pybind11::headers)
2121
target_include_directories(_diffcp PRIVATE cpp/external/eigen/)
2222
target_include_directories(_diffcp PRIVATE cpp/include/)
23-
24-
23+
set_target_properties(_diffcp PROPERTIES
24+
CXX_STANDARD 11
25+
CXX_STANDARD_REQUIRED ON
26+
CXX_EXTENSIONS OFF)
2527

2628
# This is passing in the version as a define just as an example
2729
target_compile_definitions(_diffcp PRIVATE VERSION_INFO=${PROJECT_VERSION})

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
develop:
2-
rm -f *.so
3-
python setup.py clean --all
4-
python setup.py develop
2+
uv sync --extra test

pyproject.toml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11

22
[project]
33
name = "diffcp"
4-
version = "1.1.8"
4+
dynamic = ["version"]
55
description = "A library to compute gradients for convex optimization problems"
66
requires-python = ">= 3.10"
77

88
readme = "README.md"
99

1010
dependencies = [
11-
"cvxpy>=1.6.3",
11+
"numpy >= 2.0",
12+
"scipy >= 1.10",
13+
"scs >= 3.0.0",
1214
"threadpoolctl >= 1.1",
1315
]
1416
urls = {Homepage = "https://github.com/cvxgrp/diffcp/"}
@@ -17,13 +19,24 @@ license = {text = "Apache License, Version 2.0"}
1719
[build-system]
1820
requires = [
1921
"scikit-build-core",
22+
"setuptools-scm >= 8",
2023
"pybind11>=2.4",
2124
]
2225
build-backend = "scikit_build_core.build"
2326

2427
[project.optional-dependencies]
28+
cvxpy = [
29+
"cvxpy >= 1.6.3",
30+
]
31+
clarabel = [
32+
"clarabel >= 0.5.1",
33+
]
34+
ecos = [
35+
"ecos >= 2.0.10",
36+
]
2537
test = [
2638
"clarabel >= 0.5.1",
39+
"cvxpy >= 1.6.3",
2740
"scs >= 3.0.0",
2841
"pytest>=8.3.5",
2942
"ecos >= 2.0.10",
@@ -33,3 +46,16 @@ test = [
3346
wheel.expand-macos-universal-tags = true
3447
wheel.packages = ["src/diffcp"]
3548

49+
[tool.scikit-build.sdist]
50+
include = ["src/diffcp/_version.py"]
51+
52+
[tool.scikit-build.metadata.version]
53+
provider = "scikit_build_core.metadata.setuptools_scm"
54+
55+
[tool.setuptools_scm]
56+
version_file = "src/diffcp/_version.py"
57+
version_scheme = "semver-pep440-release-branch"
58+
fallback_version = "0.0.0"
59+
60+
[tool.setuptools_scm.scm.git]
61+
describe_command = ["git", "describe", "--dirty", "--tags", "--long", "--match", "v*"]

src/diffcp/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
__version__ = "1.1.8"
1+
try:
2+
from diffcp._version import version as __version__
3+
except ImportError:
4+
from importlib.metadata import PackageNotFoundError, version
5+
6+
try:
7+
__version__ = version("diffcp")
8+
except PackageNotFoundError:
9+
__version__ = "0.0.0+unknown"
210

311
from diffcp.cone_program import solve_and_derivative, \
412
solve_and_derivative_batch, \

0 commit comments

Comments
 (0)