diff --git a/.github/workflows/upload_pypi.yml b/.github/workflows/upload_pypi.yml new file mode 100644 index 0000000..528a634 --- /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: $GITHUB_WORKSPACE/CompilerInterface/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..75d3288 --- /dev/null +++ b/.github/workflows/wheel.yml @@ -0,0 +1,29 @@ +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 + + - name: List files in dist directory + run: ls -l $GITHUB_WORKSPACE/CompilerInterface/dist + + - uses: actions/upload-artifact@v3 + with: + path: $GITHUB_WORKSPACE/CompilerInterface/dist 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",