Scripts become much easier to read and understand (#1918)

* Being nice to the user

* Front-end builder, CircleCI runner, and Gradio installer updated

* The testing scripts updated

* Front-end runner and the website launcher updated

* The formatters updated

* GitHub Actions and PyPI uploader scripts updated

* Updating the URLs

* Removing commented codes

* Delete a blank line
This commit is contained in:
Artin Mohammadi 2022-08-02 02:47:03 +04:30 committed by GitHub
parent db1ff439a7
commit bdced314bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 224 additions and 136 deletions

View File

@ -1,10 +1,11 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Building the frontend"
cd ui
pnpm i --frozen-lockfile
pnpm build
fi
cd "$(dirname ${0})/.."
source scripts/helpers.sh
pnpm_required
echo "Building the frontend..."
cd ui
pnpm i --frozen-lockfile
pnpm build

View File

@ -1,10 +1,12 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Creating requirements under test/requirements.txt using requirements.in. Please run this script from unix or wsl in a python3.7 env!"
cd test
pip install --upgrade pip-tools
pip-compile --output-file requirements.txt
fi
cd "$(dirname ${0})/.."
source scripts/helpers.sh
pip_required
echo "Creating test requirements...
It's recommended to run this script from a Unix-like system in Python 3.7 (or higher) environment."
cd test
pip install --upgrade pip-tools
pip-compile --output-file requirements.txt

View File

@ -1,10 +1,8 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Formatting backend and tests with black and isort, also checking for standards with flake8"
python -m black gradio test
python -m isort --profile=black gradio test
python -m flake8 --ignore=E731,E501,E722,W503,E126,F401,E203,F403 gradio test
fi
cd "$(dirname ${0})/.."
echo "Formatting the backend... Our style follows the Black code style."
python -m black gradio test
python -m isort --profile=black gradio test
python -m flake8 --ignore=E731,E501,E722,W503,E126,F401,E203,F403 gradio test

View File

@ -1,11 +1,12 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Formatting frontend with prettier, also type checking with TypeScript"
cd ui
pnpm i
pnpm format:write
pnpm ts:check
fi
cd "$(dirname ${0})/.."
source scripts/helpers.sh
pnpm_required
echo "Formatting the frontend... Also we'll do type checking with TypeScript."
cd ui
pnpm i
pnpm format:write
pnpm ts:check

View File

@ -1,24 +1,25 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
old_version=$(grep -Po "(?<=version=\")[^\"]+(?=\")" setup.py)
read -r new_version < gradio/version.txt
sed -i "s/version=\"$old_version\"/version=\"$new_version\"/g" setup.py
rm -rf gradio/templates/frontend
rm -rf gradio/templates/cdn
cd ui
pnpm i
pnpm build
GRADIO_VERSION=$new_version pnpm build:cdn
cd ..
aws s3 cp gradio/templates/cdn s3://gradio/$new_version/ --recursive
cp gradio/templates/cdn/index.html gradio/templates/frontend/share.html
cd "$(dirname ${0})/.."
source scripts/helpers.sh
rm -r dist/*
rm -r build/*
python3 setup.py sdist bdist_wheel
fi
pnpm_required
aws_required
# You should first run `upload_to_pypi.sh` to update the version number and
# pull the latest version of the code.
new_version="$(cat gradio/version.txt)"
rm -rf gradio/templates/frontend
rm -rf gradio/templates/cdn
cd ui
pnpm i
pnpm build
pnpm build:cdn
cd ..
aws s3 cp gradio/templates/cdn "s3://gradio/${new_version}/" --recursive
cp gradio/templates/cdn/index.html gradio/templates/frontend/share.html
rm -r dist/*
rm -r build/*
python3 setup.py sdist bdist_wheel

85
scripts/helpers.sh Normal file
View File

@ -0,0 +1,85 @@
#!/bin/bash
#######################################
# Tell the user what programs to install for a specific task.
# Arguments:
# Name of the program or actual command, a string.
# External link for easier installation help.
# Outputs:
# Prints the required program name and the external link (if given).
#######################################
function program_required() {
if [ ! -x "$(command -v ${1})" ]; then
echo "${1} is not installed in the computer..."
if [ "${2}" ]; then
echo "Check out this link: ${2}"
fi
exit 1
fi
}
#######################################
# Check for the PIP program.
# Arguments:
# None
# Outputs:
# None
#######################################
function pip_required() {
program_required "pip" "https://pip.pypa.io/en/stable/installation/"
}
#######################################
# Check for the NPM program.
# Arguments:
# None
# Outputs:
# None
#######################################
function npm_required() {
program_required "npm" "https://nodejs.org/en/download/"
}
#######################################
# Check for the PNPM program.
# Arguments:
# None
# Outputs:
# None
#######################################
function pnpm_required() {
program_required "pnpm" "https://pnpm.io/6.x/installation"
}
#######################################
# Check for the CircleCI program.
# Arguments:
# None
# Outputs:
# None
#######################################
function circleci_required() {
program_required "circleci" "https://circleci.com/docs/1.0/local-cli/"
}
#######################################
# Check for the AWS CLI program.
# Arguments:
# None
# Outputs:
# None
#######################################
function aws_required() {
program_required "aws" "https://aws.amazon.com/cli/"
}
#######################################
# Check for the Git program.
# Arguments:
# None
# Outputs:
# None
#######################################
function git_required() {
program_required "git" "https://git-scm.com/downloads"
}

View File

@ -1,8 +1,9 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Installing gradio"
pip install -e .
fi
cd "$(dirname ${0})/.."
source scripts/helpers.sh
pip_required
echo "Installing Gradio..."
pip install -e .

View File

@ -1,11 +1,11 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Installing requirements for tests"
pip install --upgrade pip
pip install -r requirements.txt
pip install -r test/requirements.txt
fi
cd "$(dirname ${0})/.."
source scripts/helpers.sh
pip_required
echo "Installing requirements before running tests..."
pip install --upgrade pip
pip install -r requirements.txt
pip install -r test/requirements.txt

View File

@ -1,13 +1,14 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Building the website"
set -e
cd website/homepage
npm install
npm run build
cd build
python -m http.server
fi
cd "$(dirname ${0})/.."
source scripts/helpers.sh
npm_required
echo "Building the website..."
set -e
cd website/homepage
npm install
npm run build
cd build
python -m http.server

View File

@ -1,8 +1,6 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Running the tests"
python -m pytest --cov=gradio --durations=20 --durations-min=1 test
fi
cd "$(dirname ${0})/.."
echo "Running the tests..."
python -m pytest --cov=gradio --durations=20 --durations-min=1 test

View File

@ -1,11 +1,9 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Running circleci locally"
circleci local execute
fi
cd "$(dirname ${0})/.."
source scripts/helpers.sh
circleci_required
echo "Running CircleCI locally..."
circleci local execute

View File

@ -1,10 +1,11 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Running the frontend"
cd ui
pnpm i
pnpm dev
fi
cd "$(dirname ${0})/.."
source scripts/helpers.sh
pnpm_required
echo "Running the frontend..."
cd ui
pnpm i
pnpm dev

View File

@ -1,32 +1,33 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Uploading to pypi"
set -e
git pull origin main
old_version=$(grep -Po "(?<=version=\")[^\"]+(?=\")" setup.py)
echo "Current version is $old_version. New version?"
read new_version
sed -i "s/version=\"$old_version\"/version=\"$new_version\"/g" setup.py
echo -n $new_version > gradio/version.txt
rm -rf gradio/templates/frontend
rm -rf gradio/templates/cdn
cd ui
pnpm i
pnpm build
GRADIO_VERSION=$new_version pnpm build:cdn
cd ..
aws s3 cp gradio/templates/cdn s3://gradio/$new_version/ --recursive # requires aws cli (contact maintainers for credentials)
cp gradio/templates/cdn/index.html gradio/templates/frontend/share.html
cd "$(dirname ${0})/.."
source scripts/helpers.sh
rm -r dist/*
rm -r build/*
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
git add -A
git commit -m "updated PyPi version to $new_version"
fi
git_required
pnpm_required
aws_required
echo "Uploading to PyPI..."
set -e
git pull origin main
old_version="$(cat gradio/version.txt)"
read -p "Current version is ${old_version}. What is the new version? " new_version
echo "So you want to release version ${new_version}. Updating gradio/version.txt..."
echo "${new_version}" > gradio/version.txt
rm -rf gradio/templates/frontend
rm -rf gradio/templates/cdn
cd ui
pnpm i
pnpm build
pnpm build:cdn
cd ..
aws s3 cp gradio/templates/cdn "s3://gradio/${new_version}/" --recursive # Contact maintainers for credentials
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 twine upload dist/*
git add -A
git commit -m "Updated version to ${new_version}"