From ce914a6f009e55a957e678ad2f5f13e33169e334 Mon Sep 17 00:00:00 2001 From: Rajiv Chitale Date: Sat, 24 Feb 2024 16:28:27 +0530 Subject: [PATCH] Fetch version, pip install in workflow --- .github/workflows/upload_pypi.yml | 46 ++++++++++++++++++++++++++++++ .github/workflows/wheel.yml | 26 +++++++++++++++++ CompilerInterface/fetch_version.py | 27 ++++++++++++++++++ CompilerInterface/pyproject.toml | 4 +-- 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/upload_pypi.yml create mode 100644 .github/workflows/wheel.yml create mode 100644 CompilerInterface/fetch_version.py diff --git a/.github/workflows/upload_pypi.yml b/.github/workflows/upload_pypi.yml new file mode 100644 index 0000000..4ff9fe8 --- /dev/null +++ b/.github/workflows/upload_pypi.yml @@ -0,0 +1,46 @@ +name: Upload to PyPI + +on: + release: + types: + - published + push: + branches: + - pip-package # or + workflow_dispatch: + inputs: + pypi_repo: + description: 'Repo to upload to (testpypi or pypi)' + default: 'testpypi' + required: true + type: choice + options: + - testpypi + - pypi + +jobs: + build_wheels: + uses: ./.github/workflows/wheel.yml + + upload_pypi: + permissions: + id-token: write + needs: [build_wheels] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + + - name: Publish package to TestPyPI + uses: pypa/gh-action-pypi-publish@v1.8.5 + with: + repository-url: https://test.pypi.org/ + if: ${{ github.event.inputs.pypi_repo != 'pypi' }} + + # - name: Publish package to PyPI + # uses: pypa/gh-action-pypi-publish@v1.8.5 + # with: + # repository-url: https://upload.pypi.org/legacy/ + # if: ${{ github.event.inputs.pypi_repo == 'pypi' }} diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml new file mode 100644 index 0000000..60a8cc3 --- /dev/null +++ b/.github/workflows/wheel.yml @@ -0,0 +1,26 @@ +name: Build wheels + +on: [push, workflow_dispatch, workflow_call] + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04] + + steps: + - uses: actions/checkout@v3 + + - name: Build wheels + run: | + cd $GITHUB_WORKSPACE/CompilerInterface + python fetch_version.py + cp ../README.md ./ + pip wheel . -w dist + pip install dist/cinter*.whl + + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl diff --git a/CompilerInterface/fetch_version.py b/CompilerInterface/fetch_version.py new file mode 100644 index 0000000..e85f2e5 --- /dev/null +++ b/CompilerInterface/fetch_version.py @@ -0,0 +1,27 @@ +import subprocess as sp +import pathlib as pl +import re + +version_regex = re.compile(r"^project\(MLCompilerBridge VERSION (?P[^)]+)\)$") +toml_field_regex = r'version[ ]*=[ ]*"(.*)"' + +VERSION = "" +with open("../CMakeLists.txt", "r") as f: + for line in f: + vmatch = version_regex.match(line) # Not using walrus because Python3.6 + if vmatch: + VERSION = vmatch.group("version") + break + +print("Version detected =", VERSION) +lines = [] +with open("./pyproject.toml", "r") as f: + lines = f.readlines() + +with open("./pyproject.toml", "w") as f: + for line in lines: + if re.search(toml_field_regex, line): + new_text = f'version = "{VERSION}"\n' + f.write(new_text) + else: + f.write(line) diff --git a/CompilerInterface/pyproject.toml b/CompilerInterface/pyproject.toml index f0e6eb2..b66bf08 100644 --- a/CompilerInterface/pyproject.toml +++ b/CompilerInterface/pyproject.toml @@ -1,10 +1,10 @@ [project] -name = "compilerinterface" +name = "cinter" version = "0.0.1" authors = [ {name = "The authors of \"The Next 700 ML-Enabled Compiler Optimizations\"" }] description = "Communication framework for ML-Enabled Compiler Optimizations." license = { text= "Apache License v2.0 with LLVM Exceptions"} -readme = "../README.md" +readme = "README.md" requires-python = ">=3.7" classifiers = [ "Programming Language :: Python :: 3",