From f43481c18ac6468fbf30bf9a80981b7eab453961 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Wed, 14 Sep 2022 17:39:46 -0400 Subject: [PATCH] Update package metadata (#2226) * Update package metadata * address review --- .circleci/config.yml | 6 ++- .github/workflows/deploy-pypi.yml | 8 ++-- .github/workflows/deploy-spaces.yml | 6 +-- MANIFEST.in | 6 --- pyproject.toml | 60 +++++++++++++++++++++++++++++ scripts/gh_action_pypi.sh | 2 +- setup.py | 39 ------------------- website/demos/Dockerfile | 3 +- website/homepage/Dockerfile | 4 +- 9 files changed, 75 insertions(+), 59 deletions(-) delete mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 480f4cdd5e..b308cf1adb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,10 +24,14 @@ jobs: command: | sudo apt update sudo apt install ffmpeg -y + - run: + name: Upgrade virtual environment tools + command: | + python -m pip install --upgrade pip virtualenv - run: name: Install Python deps in a venv command: | - python -m venv venv + python -m virtualenv venv . venv/bin/activate bash scripts/install_gradio.sh bash scripts/install_test_requirements.sh diff --git a/.github/workflows/deploy-pypi.yml b/.github/workflows/deploy-pypi.yml index aeb72bbfe8..fae1cdec80 100644 --- a/.github/workflows/deploy-pypi.yml +++ b/.github/workflows/deploy-pypi.yml @@ -28,15 +28,15 @@ jobs: with: python-version: '3.x' - name: Check new pypi version - run: python scripts/check_pypi.py + run: python scripts/check_pypi.py - name: Install pnpm uses: pnpm/action-setup@v2.2.2 with: version: 7 - - name: Install pip - run: python -m pip install pip wheel + - name: Install build tool dependencies + run: python -m pip install build - name: Build pypi package - run: | + run: | export AWS_ACCESS_KEY_ID=${{ secrets.AWSACCESSKEYID }} export AWS_SECRET_ACCESS_KEY=${{ secrets.AWSSECRETKEY }} export AWS_DEFAULT_REGION=us-west-2 diff --git a/.github/workflows/deploy-spaces.yml b/.github/workflows/deploy-spaces.yml index b2fd57b9e1..453a358d0b 100644 --- a/.github/workflows/deploy-spaces.yml +++ b/.github/workflows/deploy-spaces.yml @@ -19,14 +19,14 @@ jobs: with: version: 7 - name: Install pip - run: python -m pip install pip wheel requests + run: python -m pip install build requests - name: Get PR Number run: | python -c "import os;print(os.environ['GITHUB_REF'].split('/')[2])" > pr_number.txt echo "PR_NUMBER=$(cat pr_number.txt)" >> $GITHUB_ENV echo "GRADIO_VERSION=$(python -c 'import requests;print(requests.get("https://pypi.org/pypi/gradio/json").json()["info"]["version"])')" >> $GITHUB_ENV - name: Build and publish pr package - run: | + run: | export AWS_ACCESS_KEY_ID=${{ secrets.PR_DEPLOY_KEY }} export AWS_SECRET_ACCESS_KEY=${{ secrets.PR_DEPLOY_SECRET }} export AWS_DEFAULT_REGION=us-east-1 @@ -35,7 +35,7 @@ jobs: pnpm i pnpm build cd .. - python3 setup.py bdist_wheel + python3 -m build -w aws s3 cp dist/gradio-${{ env.GRADIO_VERSION }}-py3-none-any.whl s3://gradio-builds/${{ github.sha }}/ - name: Install Hub Client Library run: pip install huggingface-hub==0.8.1 diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index d62b06eb02..0000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,6 +0,0 @@ -recursive-include gradio/templates * -recursive-include gradio/test_data * -recursive-include test/test_files * -include gradio/version.txt -include requirements.txt -include test/requirements.txt \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..46208502e7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,60 @@ +[build-system] +requires = ["hatchling", "hatch-requirements-txt", "hatch-fancy-pypi-readme>=22.5.0"] +build-backend = "hatchling.build" + +[project] +name = "gradio" +dynamic = ["version", "dependencies", "readme"] +description = "Python library for easily interacting with trained machine learning models" +license = "Apache-2.0" +requires-python = ">=3.7" +authors = [ + { name = "Abubakar Abid", email = "team@gradio.app" }, + { name = "Ali Abid", email = "team@gradio.app" }, + { name = "Ali Abdalla", email = "team@gradio.app" }, + { name = "Dawood Khan", email = "team@gradio.app" }, + { name = "Ahsen Khaliq", email = "team@gradio.app" }, + { name = "Pete Allen", email = "team@gradio.app" }, + { name = "Ömer Faruk Özdemir", email = "team@gradio.app" }, +] +keywords = ["machine learning", "reproducibility", "visualization"] + +[project.scripts] +gradio = "gradio.reload:run_in_reload_mode" + +[project.urls] +Homepage = "https://github.com/gradio-app/gradio" + +[tool.hatch.version] +path = "gradio/version.txt" +pattern = "(?P.+)" + +[tool.hatch.metadata.hooks.requirements_txt] +filename = "requirements.txt" + +[tool.hatch.metadata.hooks.fancy-pypi-readme] +content-type = "text/markdown" +fragments = [ + { path = "README.md" }, +] + +[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]] +pattern = "(website/homepage|readme_files)/" +replacement = 'https://raw.githubusercontent.com/gradio-app/gradio/main/\g<1>/' + +[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]] +pattern = 'demo/([\S]*.gif)' +replacement = 'https://raw.githubusercontent.com/gradio-app/gradio/main/demo/\g<1>' + +[tool.hatch.build] +artifacts = [ + "/gradio/templates", +] + +[tool.hatch.build.targets.sdist] +include = [ + "/gradio", + "/test", + "/README.md", + "/requirements.txt", +] diff --git a/scripts/gh_action_pypi.sh b/scripts/gh_action_pypi.sh index 5d06e3e66d..61f08ab7d2 100755 --- a/scripts/gh_action_pypi.sh +++ b/scripts/gh_action_pypi.sh @@ -22,4 +22,4 @@ cp gradio/templates/cdn/index.html gradio/templates/frontend/share.html rm -r dist/* rm -r build/* -python3 setup.py sdist bdist_wheel +python3 -m build diff --git a/setup.py b/setup.py deleted file mode 100644 index 41721725ad..0000000000 --- a/setup.py +++ /dev/null @@ -1,39 +0,0 @@ -try: - from setuptools import setup -except ImportError: - from distutils.core import setup -from pathlib import Path -import re - -this_directory = Path(__file__).parent - -long_description = (this_directory / "README.md").read_text(encoding='utf8') -# Replace relative paths to images with absolute paths -long_description = re.sub("website/homepage/", "https://raw.githubusercontent.com/gradio-app/gradio/main/website/homepage/", long_description) -long_description = re.sub(r"demo/([\S]*.gif)", r"https://raw.githubusercontent.com/gradio-app/gradio/main/demo/\g<1>", long_description) - -version = (this_directory / "gradio" / "version.txt").read_text( - encoding='utf8').strip() - -with open("requirements.txt") as reqs: - requirements = reqs.readlines() - -setup( - name="gradio", - version=version, - include_package_data=True, - description="Python library for easily interacting with trained machine learning models", - long_description=long_description, - long_description_content_type='text/markdown', - author="Abubakar Abid, Ali Abid, Ali Abdalla, Dawood Khan, Ahsen Khaliq, Pete Allen, Ömer Faruk Özdemir", - author_email="team@gradio.app", - url="https://github.com/gradio-app/gradio", - packages=["gradio", "gradio.test_data", "test.test_files"], - license="Apache License 2.0", - keywords=["machine learning", "visualization", "reproducibility"], - install_requires=requirements, - entry_points={ - 'console_scripts': ['gradio=gradio.reload:run_in_reload_mode'] - }, - python_requires='>=3.7', -) diff --git a/website/demos/Dockerfile b/website/demos/Dockerfile index 8864a0f102..da8e6030f4 100644 --- a/website/demos/Dockerfile +++ b/website/demos/Dockerfile @@ -7,8 +7,7 @@ RUN pip install numpy matplotlib WORKDIR /gradio COPY ./gradio ./gradio COPY ./requirements.txt ./requirements.txt -COPY ./setup.py ./setup.py -COPY ./MANIFEST.in ./MANIFEST.in +COPY ./pyproject.toml ./pyproject.toml COPY ./README.md ./README.md COPY ./test ./test RUN pip install . diff --git a/website/homepage/Dockerfile b/website/homepage/Dockerfile index f911829c30..a08fa1bb08 100644 --- a/website/homepage/Dockerfile +++ b/website/homepage/Dockerfile @@ -19,8 +19,7 @@ RUN pnpm build:website WORKDIR /gradio COPY ./gradio ./gradio COPY ./requirements.txt ./requirements.txt -COPY ./setup.py ./setup.py -COPY ./MANIFEST.in ./MANIFEST.in +COPY ./pyproject.toml ./pyproject.toml COPY ./README.md ./README.md COPY ./test ./test RUN pip install . @@ -42,4 +41,3 @@ RUN ASSETS_FILE=$(grep -oE index.[a-z0-9]+.js /gradio/gradio/templates/cdn/index RUN cp /gradio/website/homepage/nginx.conf /etc/nginx/conf.d/default.conf ENTRYPOINT ["nginx", "-g", "daemon off;"] -