Skip to content

Commit

Permalink
Python SDK version updater (#159)
Browse files Browse the repository at this point in the history
Add `python/set-version.py` to update versions of Python SDK and
adapters. To update specific version (with `uv`):

```shell
uv run python/set-version.py 1.4.2
```

To bump up patch version:

```shell
uv run python/set-version.py
```
  • Loading branch information
termoshtt authored Nov 26, 2024
1 parent 0e82b9d commit 786622c
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/actions/setup-test-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ runs:
run: |
pip install "ruff >= 0.7.0, < 0.8.0"
pip install pytest-github-actions-annotate-failures
- name: Install uv
uses: astral-sh/setup-uv@v3
25 changes: 24 additions & 1 deletion .github/workflows/release_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Build wheel
run: |
python -m pip install --upgrade pip build
Expand Down Expand Up @@ -129,3 +129,26 @@ jobs:

- name: Upload wheels to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

next_version:
runs-on: ubuntu-latest
needs: publish
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup-test-environment
with:
python-version: "3.8"

- name: Bump version
run: |
echo "NEW_VERSION=$(uv run python/set-version.py)" >> $GITHUB_ENV
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
title: "Start developing OMMX Python SDK ${{ env.NEW_VERSION }}"
branch: "python-version-update/${{ env.NEW_VERSION }}"
base: "main"
15 changes: 15 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ tasks:
- markdown-code-runner python/ommx-pyscipopt-adapter/README.md
- pyright python/ommx-pyscipopt-adapter/

doc_python:
cmds:
- task: doc_python_sdk
- task: doc_python_mip_adapter

doc_python_sdk:
cmds:
- sphinx-build -b html source build
dir: python/ommx/docs

doc_python_mip_adapter:
cmds:
- sphinx-build -b html source build
dir: python/ommx-python-mip-adapter/docs

stubgen:
cmds:
- cargo run --bin stub_gen --features=stub_gen
6 changes: 5 additions & 1 deletion python/ommx-python-mip-adapter/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import sphinx_rtd_theme
import tomlkit
from pathlib import Path

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
Expand All @@ -12,7 +14,9 @@
copyright = "2024, Jij Inc."
author = "Jij Inc."

version = "1.4.2"
here = Path(__file__).parent
pyproject_toml = tomlkit.loads((here.parent.parent / "pyproject.toml").read_text())
version = str(pyproject_toml["project"]["version"]) # type: ignore
release = version

# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion python/ommx-python-mip-adapter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Issues = "https://github.com/Jij-Inc/ommx-python-mip-adapter/issues"
[project.optional-dependencies]
dev = [
"markdown-code-runner",
"mypy",
"numpy",
"pyright",
"pytest",
Expand All @@ -46,4 +45,5 @@ dev = [
"sphinx-autoapi",
"sphinx_fontawesome",
"sphinx_rtd_theme",
"tomlkit",
]
6 changes: 5 additions & 1 deletion python/ommx/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# -- Path setup --------------------------------------------------------------
import sphinx_rtd_theme
import tomlkit
from pathlib import Path

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
Expand All @@ -13,7 +15,9 @@
copyright = "2024, Jij Inc."
author = "Jij Inc."

version = "1.4.2"
here = Path(__file__).parent
pyproject_toml = tomlkit.loads((here.parent.parent / "pyproject.toml").read_text())
version = str(pyproject_toml["project"]["version"]) # type: ignore
release = version

# -- General configuration ---------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions python/ommx/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dev = [
"sphinx-autoapi",
"sphinx_fontawesome",
"sphinx_rtd_theme",
"tomlkit",
"types-protobuf>=0.1.14",
]

Expand Down
77 changes: 77 additions & 0 deletions python/set-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# /// script
# requires-python = ">=3.8"
# dependencies = [
# "tomlkit"
# ]
# ///

# Bump up versions of OMMX Python SDK and adapters
#
# Usage
# ------
#
# Set the version of the OMMX Python SDK and adapters to the specified version.
#
# ```shell
# uv run python/set-version.py 0.1.0
# ```
#
# Bump up patch version of the OMMX Python SDK and adapters
#
# ```shell
# uv run python/set-version.py
# ```
#

from pathlib import Path
import tomlkit
import argparse


def update_version(pyproject_path: Path, new_version: str):
with open(pyproject_path, "r") as file:
pyproject_data = tomlkit.parse(file.read())

pyproject_data["project"]["version"] = new_version # type: ignore

with open(pyproject_path, "w") as file:
file.write(tomlkit.dumps(pyproject_data))


def generrate_next_version(sdk: Path) -> str:
with open(sdk, "r") as file:
pyproject_data = tomlkit.parse(file.read())
current = str(pyproject_data["project"]["version"]) # type: ignore
major, minor, patch = current.split(".")
return f"{major}.{minor}.{int(patch) + 1}"


def main():
parser = argparse.ArgumentParser()
parser.add_argument("version", help="New version to set", default=None, nargs="?")

args = parser.parse_args()

here = Path(__file__).parent
sdk = here / "ommx" / "pyproject.toml"
adapters = [
here / name / "pyproject.toml"
for name in [
"ommx-pyscipopt-adapter",
"ommx-python-mip-adapter",
# Add new adapter here
]
]

if args.version:
new_version = args.version
else:
new_version = generrate_next_version(sdk)
print(new_version)

for pyproject in [sdk] + adapters:
update_version(pyproject, new_version)


if __name__ == "__main__":
main()

0 comments on commit 786622c

Please sign in to comment.