Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python SDK version updater #159

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading