diff --git a/.github/workflows/deploy-client-pypi.yml b/.github/workflows/deploy-client-pypi.yml new file mode 100644 index 0000000000000..8dce76aa5a85d --- /dev/null +++ b/.github/workflows/deploy-client-pypi.yml @@ -0,0 +1,40 @@ +# This workflow will upload a Python Package when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Gradio Client Python Package + +on: + workflow_dispatch: + pull_request: + types: closed + branches: + - main + paths: + - 'client/python/gradio_client/version.txt' + +jobs: + deploy: + if: github.event.pull_request.merged == true || github.event.action == '' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Check new pypi version + run: python client/python/scripts/check_pypi.py + - name: Build pypi package + run: | + client/python/scripts/build_pypi.sh + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: aabid93 + password: ${{ secrets.PYPI_GRADIO_CLIENT_TOKEN }} + packages_dir: client/python/dist diff --git a/client/python/gradio_client/version.txt b/client/python/gradio_client/version.txt index 5c4511c36fd00..2c75c89249c95 100644 --- a/client/python/gradio_client/version.txt +++ b/client/python/gradio_client/version.txt @@ -1 +1 @@ -0.0.7 \ No newline at end of file +0.0.6b10 diff --git a/client/python/scripts/build_pypi.sh b/client/python/scripts/build_pypi.sh new file mode 100755 index 0000000000000..23e635237237d --- /dev/null +++ b/client/python/scripts/build_pypi.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +cd "$(dirname ${0})/.." + +python3 -m pip install build +rm -rf dist/* +rm -rf build/* +python3 -m build diff --git a/client/python/scripts/check_pypi.py b/client/python/scripts/check_pypi.py new file mode 100644 index 0000000000000..e8f588743b026 --- /dev/null +++ b/client/python/scripts/check_pypi.py @@ -0,0 +1,16 @@ +import json +import sys +import urllib.request +from pathlib import Path + +version_file = Path(__file__).parent.parent / "gradio_client" / "version.txt" +version = version_file.read_text(encoding="utf8").strip() + +with urllib.request.urlopen("https://pypi.org/pypi/gradio_client/json") as url: + releases = json.load(url)["releases"] + +if version in releases: + print(f"Version {version} already exists on PyPI") + sys.exit(1) +else: + print(f"Version {version} does not exist on PyPI") diff --git a/client/python/scripts/format.sh b/client/python/scripts/format.sh index 2f1bdbcdea100..17a469167508b 100644 --- a/client/python/scripts/format.sh +++ b/client/python/scripts/format.sh @@ -3,8 +3,8 @@ cd "$(dirname ${0})/.." echo "Formatting the client library.. Our style follows the Black code style." -ruff --fix test gradio_client -black test gradio_client +ruff --fix . +black . echo "Type checking the client library with pyright" -pyright gradio_client/*.py \ No newline at end of file +pyright gradio_client/*.py diff --git a/client/python/scripts/upload_pypi.sh b/client/python/scripts/upload_pypi.sh deleted file mode 100644 index 02b7ea57ca147..0000000000000 --- a/client/python/scripts/upload_pypi.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -cd "$(dirname ${0})/.." - -python -m pip install build twine -rm -rf dist/* -python -m build -twine upload dist/* \ No newline at end of file