From d83bb705a73afea78094251a16a5ee0782415250 Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Thu, 29 Aug 2024 16:10:47 +0300 Subject: [PATCH 1/3] Add semantic versioning --- handle_versioning.py | 45 ++++++++++++++++ poetry.lock | 28 +++++++++- pyproject.toml | 126 ++++++++++++++----------------------------- 3 files changed, 113 insertions(+), 86 deletions(-) create mode 100644 handle_versioning.py diff --git a/handle_versioning.py b/handle_versioning.py new file mode 100644 index 0000000..1150942 --- /dev/null +++ b/handle_versioning.py @@ -0,0 +1,45 @@ +import semantic_version +import toml + + +def read_version(): + with open("pyproject.toml", "r") as file: + pyproject = toml.load(file) + return semantic_version.Version(pyproject["tool"]["poetry"]["version"]) + + +def write_version(version): + with open("pyproject.toml", "r") as file: + pyproject = toml.load(file) + pyproject["tool"]["poetry"]["version"] = str(version) + with open("pyproject.toml", "w") as file: + toml.dump(pyproject, file) + + +def bump_version(part): + version = read_version() + if part == "major": + new_version = version.next_major() + elif part == "minor": + new_version = version.next_minor() + elif part == "patch": + new_version = version.next_patch() + else: + raise ValueError("Invalid part: choose 'major', 'minor', or 'patch'") + write_version(new_version) + print(f"Updated version to {new_version}") + + +if __name__ == "__main__": + import sys + + if len(sys.argv) < 2 or sys.argv[1] not in ["read", "major", "minor", "patch"]: + raise ValueError("Missing command: choose 'read', 'major', 'minor', or 'patch") + + command = sys.argv[1] + if command == "read": + current_version = read_version() + print(f"Current version is {current_version}") + + else: + bump_version(command) diff --git a/poetry.lock b/poetry.lock index cf9709b..7459adf 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2126,6 +2126,21 @@ dev = ["cython-lint (>=0.12.2)", "doit (>=0.36.0)", "mypy", "pycodestyle", "pyde doc = ["jupyterlite-pyodide-kernel", "jupyterlite-sphinx (>=0.12.0)", "jupytext", "matplotlib (>=3.5)", "myst-nb", "numpydoc", "pooch", "pydata-sphinx-theme (>=0.15.2)", "sphinx (>=5.0.0)", "sphinx-design (>=0.4.0)"] test = ["array-api-strict", "asv", "gmpy2", "hypothesis (>=6.30)", "mpmath", "pooch", "pytest", "pytest-cov", "pytest-timeout", "pytest-xdist", "scikit-umfpack", "threadpoolctl"] +[[package]] +name = "semantic-version" +version = "2.10.0" +description = "A library implementing the 'SemVer' scheme." +optional = false +python-versions = ">=2.7" +files = [ + {file = "semantic_version-2.10.0-py2.py3-none-any.whl", hash = "sha256:de78a3b8e0feda74cabc54aab2da702113e33ac9d9eb9d2389bcf1f58b7d9177"}, + {file = "semantic_version-2.10.0.tar.gz", hash = "sha256:bdabb6d336998cbb378d4b9db3a4b56a1e3235701dc05ea2690d9a997ed5041c"}, +] + +[package.extras] +dev = ["Django (>=1.11)", "check-manifest", "colorama (<=0.4.1)", "coverage", "flake8", "nose2", "readme-renderer (<25.0)", "tox", "wheel", "zest.releaser[recommended]"] +doc = ["Sphinx", "sphinx-rtd-theme"] + [[package]] name = "shellingham" version = "1.5.4" @@ -2307,6 +2322,17 @@ webencodings = ">=0.4" doc = ["sphinx", "sphinx_rtd_theme"] test = ["pytest", "ruff"] +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] + [[package]] name = "tomli" version = "2.0.1" @@ -2476,4 +2502,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "9e3a34739af99a4c092686e888146b803669b4386c2d44f39680c6b68727d3dc" +content-hash = "608e89b569d110e0ca49063cde4d915ed83b59b633806f5190f219f5218ed69c" diff --git a/pyproject.toml b/pyproject.toml index c32b1a3..e3133d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,119 +1,66 @@ -# https://python-poetry.org/docs/pyproject -# minimal required information - [project] name = "osipi" version = "0.1.2" -dependencies = [ - "numpy", - "scipy" -] - -# optional information - +dependencies = [ "numpy", "scipy",] description = "The authorative python package for perfusion MRI" readme = "README.md" -authors = [ - { name = "Luis Torres", email = "luistorres@flywheel.io" }, - { name = "Steven Sourbron", email = "s.sourbron@sheffield.ac.uk" }, - ] -license = { file = "LICENSE" } -classifiers = [ - # How mature is this project? Common values are - # 3 - Alpha - # 4 - Beta - # 5 - Production/Stable - 'Development Status :: 3 - Alpha', - - # Indicate who your project is intended for - 'Intended Audience :: Developers', - 'Intended Audience :: Science/Research', - 'Topic :: Scientific/Engineering', - 'Operating System :: OS Independent', +classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Topic :: Scientific/Engineering", "Operating System :: OS Independent", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3",] +keywords = [ "python", "medical imaging", "perfusion", "MRI",] +requires-python = ">=3.6" +[[project.authors]] +name = "Luis Torres" +email = "luistorres@flywheel.io" - 'License :: OSI Approved :: Apache Software License', - "Programming Language :: Python", - "Programming Language :: Python :: 3" -] -keywords = ['python', "medical imaging", "perfusion", "MRI"] +[[project.authors]] +name = "Steven Sourbron" +email = "s.sourbron@sheffield.ac.uk" -requires-python = ">=3.6" +[project.license] +file = "LICENSE" [project.urls] -"Homepage" = "https://osipi.github.io/pypi" - -[tool.setuptools.packages.find] -where = ["src"] +Homepage = "https://osipi.github.io/pypi" [project.optional-dependencies] -tests = [ - "pytest", - "matplotlib", -] -docs = [ - "sphinx", - "pydata-sphinx-theme", - "myst-parser", - "sphinx-copybutton", - "sphinx-design", - "sphinx-remove-toctrees", - "autodocsumm", - "docutils", - "sphinxcontrib-applehelp", - "sphinxcontrib-devhelp", - "sphinxcontrib-htmlhelp", - "sphinxcontrib-jsmath", - "sphinxcontrib-qthelp", - "sphinxcontrib-serializinghtml", - "sphinx-gallery", -] +tests = [ "pytest", "matplotlib",] +docs = [ "sphinx", "pydata-sphinx-theme", "myst-parser", "sphinx-copybutton", "sphinx-design", "sphinx-remove-toctrees", "autodocsumm", "docutils", "sphinxcontrib-applehelp", "sphinxcontrib-devhelp", "sphinxcontrib-htmlhelp", "sphinxcontrib-jsmath", "sphinxcontrib-qthelp", "sphinxcontrib-serializinghtml", "sphinx-gallery",] [tool.ruff] -# Exclude a variety of commonly ignored directories. -exclude = [ - ".direnv", ".eggs", ".git", ".git-rewrite","__init__.py", - ".mypy_cache", ".nox", ".pants.d", ".pyenv", ".pytest_cache", ".pytype", - ".ruff_cache", ".svn", ".venv", ".vscode", "__pypackages__", "_build", - "buck-out", "build", "dist", "site-packages", "venv", -] - +exclude = [ ".direnv", ".eggs", ".git", ".git-rewrite", "__init__.py", ".mypy_cache", ".nox", ".pants.d", ".pyenv", ".pytest_cache", ".pytype", ".ruff_cache", ".svn", ".venv", ".vscode", "__pypackages__", "_build", "buck-out", "build", "dist", "site-packages", "venv",] line-length = 100 +[tool.poetry] +name = "osipi" +version = "0.1.2" +description = "The authorative python package for perfusion MRI" +authors = [ "Luis Torres ", "Steven Sourbron ",] +readme = "README.md" [tool.ruff.lint] -# Enable Pyflakes (`F`), a subset of the pycodestyle (`E`) codes, and isort (`I`). -select = ["E4", "E7", "E9", "F", "I"] +select = [ "E4", "E7", "E9", "F", "I",] ignore = [] -fixable = ["ALL"] +fixable = [ "ALL",] unfixable = [] [tool.ruff.format] -# Like Black, use double quotes for strings. quote-style = "double" - indent-style = "space" - skip-magic-trailing-comma = false - line-ending = "auto" - docstring-code-format = false - docstring-code-line-length = "dynamic" -[tool.poetry] -name = "osipi" -version = "0.1.2" -description = "The authorative python package for perfusion MRI" -authors = ["Luis Torres ", "Steven Sourbron "] -readme = "README.md" - [tool.poetry.dependencies] python = "^3.9" numpy = "^1.21.2" scipy = "^1.7.3" matplotlib = "3.9.0" requests = "^2.32.3" +semantic-version = "^2.10.0" +toml = "^0.10.2" + +[tool.setuptools.packages.find] +where = [ "src",] [tool.poetry.group.dev.dependencies] flake8 = "^7.0.0" @@ -125,8 +72,17 @@ pytest-cov = "^5.0.0" autodocsumm = "^0.2.12" docutils = "^0.21.2" myst-parser = "^3.0.1" -rstcheck = {extras = ["sphinx"], version = "^6.2.1"} mkdocs = "^1.6.0" -mkdocs-material = {extras = ["imaging"], version = "^9.5.27"} mkdocs-gallery = "^0.10.1" -mkdocstrings = {extras = ["crystal", "python"], version = "^0.25.1"} + +[tool.poetry.group.docs.dependencies.rstcheck] +extras = [ "sphinx",] +version = "^6.2.1" + +[tool.poetry.group.docs.dependencies.mkdocs-material] +extras = [ "imaging",] +version = "^9.5.27" + +[tool.poetry.group.docs.dependencies.mkdocstrings] +extras = [ "crystal", "python",] +version = "^0.25.1" From 04b199f84fb0f9e97d6c52f05984a2997f863a6a Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Thu, 29 Aug 2024 16:31:19 +0300 Subject: [PATCH 2/3] Adding release workflow --- .github/workflows/release.yaml | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..c47ab06 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,53 @@ +name: Publish to PyPI + + +on: + workflow_dispatch: + inputs: + version: + description: 'Version to release' + required: true + default: 'patch' + type: choice + options: + - 'major' + - 'minor' + - 'patch' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install Poetry + uses: Gr1N/setup-poetry@v8 + with: + poetry-version: '1.8.3' + + - name: Install dependencies + run: poetry install + + - name: Bump version + run: | + python handle_versioning.py ${{ github.event.inputs.version }} + git add pyproject.toml + git commit -m "Bump version to ${{ github.event.inputs.version }}" + git push + + - name: Create tag + run: | + current_version=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])") + git tag current_version + git push origin current_version + + - name: Publish to PyPI + env: + POETRY_PYPI_TOKEN: ${{ secrets.POETRY_PYPI_TOKEN }} + run: poetry publish --build From bcd0dd872bbc4c6ec6a97e583e212d065045a274 Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Thu, 29 Aug 2024 17:13:57 +0300 Subject: [PATCH 3/3] Added main branch as default --- .github/workflows/release.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c47ab06..d40a512 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,6 +3,8 @@ name: Publish to PyPI on: workflow_dispatch: + branches: + - main inputs: version: description: 'Version to release' @@ -19,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install Python 3.10 uses: actions/setup-python@v4 @@ -44,8 +46,8 @@ jobs: - name: Create tag run: | current_version=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])") - git tag current_version - git push origin current_version + git tag $current_version + git push origin $current_version - name: Publish to PyPI env: