mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-25 12:10:31 +08:00
refactor: Use package.json for version management (#5514)
* refactor: Use package.json for version management - uses package.json file for version management. - updated the regex pattern. - removed the logic that creates or updates the version.txt file * load version through package.json * fix code duplication * add changeset * add changeset * fixes * fix * package version * fix * typing * typing * changes * add changeset --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
99e87a45df
commit
52f7831751
@ -82,7 +82,6 @@ ${current_changelog.replace(`# ${pkg_name}`, "").trim()}
|
||||
});
|
||||
|
||||
if (python) {
|
||||
writeFileSync(join(dirs[0], "version.txt"), version);
|
||||
bump_local_dependents(pkg_name, version);
|
||||
}
|
||||
}
|
||||
|
7
.changeset/smart-birds-drop.md
Normal file
7
.changeset/smart-birds-drop.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
"@gradio/app": patch
|
||||
"gradio": patch
|
||||
"gradio_client": patch
|
||||
---
|
||||
|
||||
feat:refactor: Use package.json for version management
|
@ -11,7 +11,7 @@ import { join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||
const version_path = join(__dirname, "..", "gradio", "version.txt");
|
||||
const version_path = join(__dirname, "..", "gradio", "package.json");
|
||||
const theme_token_path = join(
|
||||
__dirname,
|
||||
"..",
|
||||
@ -21,9 +21,7 @@ const theme_token_path = join(
|
||||
"tokens.css"
|
||||
);
|
||||
|
||||
const version = readFileSync(version_path, { encoding: "utf-8" })
|
||||
.trim()
|
||||
.replace(/\./g, "-");
|
||||
const version = JSON.parse(readFileSync(version_path, { encoding: 'utf-8' })).version.trim().replace(/\./g, '-');
|
||||
|
||||
//@ts-ignore
|
||||
export default defineConfig(({ mode }) => {
|
||||
|
1
.github/workflows/build-pr.yml
vendored
1
.github/workflows/build-pr.yml
vendored
@ -47,7 +47,6 @@ jobs:
|
||||
fi
|
||||
- name: Build pr package
|
||||
run: |
|
||||
echo ${{ steps.get_pr_number.outputs.GRADIO_VERSION }} > gradio/version.txt
|
||||
pnpm i --frozen-lockfile --ignore-scripts
|
||||
pnpm build
|
||||
python3 -m build -w
|
||||
|
@ -3,9 +3,10 @@ set -e
|
||||
|
||||
cd "$(dirname ${0})"
|
||||
|
||||
# You should update the version in version.txt before running this script
|
||||
new_version="$(cat gradio/version.txt)"
|
||||
GRADIO_VERSION=$new_version
|
||||
# You should update the version in package.json before running this script
|
||||
FILE="gradio/package.json"
|
||||
new_version=$(python -c "import json; f = open('$FILE', 'r'); data = json.load(f); print(data['version']); f.close();")
|
||||
GRADIO_VERSION = $new_version
|
||||
|
||||
rm -rf gradio/templates/frontend
|
||||
rm -rf gradio/templates/cdn
|
||||
|
@ -58,7 +58,20 @@ INVALID_RUNTIME = [
|
||||
SpaceStage.PAUSED,
|
||||
]
|
||||
|
||||
__version__ = (pkgutil.get_data(__name__, "version.txt") or b"").decode("ascii").strip()
|
||||
|
||||
def get_package_version() -> str:
|
||||
try:
|
||||
package_json_data = (
|
||||
pkgutil.get_data(__name__, "package.json").decode("utf-8").strip() # type: ignore
|
||||
)
|
||||
package_data = json.loads(package_json_data)
|
||||
version = package_data.get("version", "")
|
||||
return version
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
__version__ = get_package_version()
|
||||
|
||||
|
||||
class TooManyRequestsError(Exception):
|
||||
|
@ -1 +0,0 @@
|
||||
0.5.0
|
@ -38,8 +38,8 @@ classifiers = [
|
||||
Homepage = "https://github.com/gradio-app/gradio"
|
||||
|
||||
[tool.hatch.version]
|
||||
path = "gradio_client/version.txt"
|
||||
pattern = "(?P<version>.+)"
|
||||
path = "gradio_client/package.json"
|
||||
pattern = ".*\"version\":\\s*\"(?P<version>[^\"]+)\""
|
||||
|
||||
[tool.hatch.metadata.hooks.requirements_txt]
|
||||
filename = "requirements.txt"
|
||||
|
@ -3,8 +3,9 @@ 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()
|
||||
version_file = Path(__file__).parent.parent / "gradio_client" / "package.json"
|
||||
with version_file.open() as f:
|
||||
version = json.load(f)["version"]
|
||||
|
||||
with urllib.request.urlopen("https://pypi.org/pypi/gradio_client/json") as url:
|
||||
releases = json.load(url)["releases"]
|
||||
|
@ -1,4 +1,4 @@
|
||||
import pkgutil
|
||||
import json
|
||||
|
||||
import gradio.components as components
|
||||
import gradio.inputs as inputs
|
||||
@ -103,8 +103,6 @@ from gradio.templates import (
|
||||
Webcam,
|
||||
)
|
||||
from gradio.themes import Base as Theme
|
||||
from gradio.utils import get_package_version
|
||||
|
||||
current_pkg_version = (
|
||||
(pkgutil.get_data(__name__, "version.txt") or b"").decode("ascii").strip()
|
||||
)
|
||||
__version__ = current_pkg_version
|
||||
__version__ = get_package_version()
|
||||
|
@ -16,7 +16,7 @@ import requests
|
||||
import gradio
|
||||
from gradio import wasm_utils
|
||||
from gradio.context import Context
|
||||
from gradio.utils import GRADIO_VERSION
|
||||
from gradio.utils import get_package_version
|
||||
|
||||
# For testability, we import the pyfetch function into this module scope and define a fallback coroutine object to be patched in tests.
|
||||
try:
|
||||
@ -87,10 +87,7 @@ async def _do_wasm_analytics_request(url: str, data: dict[str, Any]) -> None:
|
||||
|
||||
def version_check():
|
||||
try:
|
||||
version_data = pkgutil.get_data(__name__, "version.txt")
|
||||
if not version_data:
|
||||
raise FileNotFoundError
|
||||
current_pkg_version = version_data.decode("ascii").strip()
|
||||
current_pkg_version = get_package_version()
|
||||
latest_pkg_version = requests.get(url=PKG_VERSION_URL, timeout=3).json()[
|
||||
"version"
|
||||
]
|
||||
@ -197,7 +194,7 @@ def launched_analytics(blocks: gradio.Blocks, data: dict[str, Any]) -> None:
|
||||
str(blocks.blocks[y]) for y in x["outputs"] if y in blocks.blocks
|
||||
]
|
||||
additional_data = {
|
||||
"version": GRADIO_VERSION,
|
||||
"version": get_package_version(),
|
||||
"is_kaggle": blocks.is_kaggle,
|
||||
"is_sagemaker": blocks.is_sagemaker,
|
||||
"using_auth": blocks.auth is not None,
|
||||
|
@ -55,7 +55,6 @@ from gradio.tunneling import (
|
||||
CURRENT_TUNNELS,
|
||||
)
|
||||
from gradio.utils import (
|
||||
GRADIO_VERSION,
|
||||
TupleNoPrint,
|
||||
check_function_inputs_match,
|
||||
component_or_layout_class,
|
||||
@ -63,6 +62,7 @@ from gradio.utils import (
|
||||
delete_none,
|
||||
get_cancel_function,
|
||||
get_continuous_fn,
|
||||
get_package_version,
|
||||
)
|
||||
|
||||
try:
|
||||
@ -771,7 +771,7 @@ class Blocks(BlockContext):
|
||||
"custom_css": self.css is not None,
|
||||
"theme": self.theme.name,
|
||||
"is_custom_theme": is_custom_theme,
|
||||
"version": GRADIO_VERSION,
|
||||
"version": get_package_version(),
|
||||
}
|
||||
analytics.initiated_analytics(data)
|
||||
|
||||
|
@ -54,14 +54,19 @@ from gradio.exceptions import Error
|
||||
from gradio.oauth import attach_oauth
|
||||
from gradio.queueing import Estimation, Event
|
||||
from gradio.route_utils import Request # noqa: F401
|
||||
from gradio.utils import cancel_tasks, run_coro_in_background, set_task_name
|
||||
from gradio.utils import (
|
||||
cancel_tasks,
|
||||
get_package_version,
|
||||
run_coro_in_background,
|
||||
set_task_name,
|
||||
)
|
||||
|
||||
mimetypes.init()
|
||||
|
||||
STATIC_TEMPLATE_LIB = files("gradio").joinpath("templates").as_posix() # type: ignore
|
||||
STATIC_PATH_LIB = files("gradio").joinpath("templates", "frontend", "static").as_posix() # type: ignore
|
||||
BUILD_PATH_LIB = files("gradio").joinpath("templates", "frontend", "assets").as_posix() # type: ignore
|
||||
VERSION = files("gradio").joinpath("version.txt").read_text()
|
||||
VERSION = get_package_version()
|
||||
|
||||
|
||||
class ORJSONResponse(JSONResponse):
|
||||
|
@ -50,14 +50,23 @@ if TYPE_CHECKING: # Only import for type checking (is False at runtime).
|
||||
from gradio.routes import App
|
||||
|
||||
JSON_PATH = os.path.join(os.path.dirname(gradio.__file__), "launches.json")
|
||||
GRADIO_VERSION = (
|
||||
(pkgutil.get_data(__name__, "version.txt") or b"").decode("ascii").strip()
|
||||
)
|
||||
|
||||
P = ParamSpec("P")
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def get_package_version() -> str:
|
||||
try:
|
||||
package_json_data = (
|
||||
pkgutil.get_data(__name__, "package.json").decode("utf-8").strip() # type: ignore
|
||||
)
|
||||
package_data = json.loads(package_json_data)
|
||||
version = package_data.get("version", "")
|
||||
return version
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
def safe_get_lock() -> asyncio.Lock:
|
||||
"""Get asyncio.Lock() without fear of getting an Exception.
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
3.44.3
|
@ -9,19 +9,16 @@ import prefixer from "postcss-prefix-selector";
|
||||
import { readFileSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
|
||||
const version_path = resolve(__dirname, "../../gradio/version.txt");
|
||||
const version_path = resolve(__dirname, "../../gradio/package.json");
|
||||
const theme_token_path = resolve(__dirname, "../theme/src/tokens.css");
|
||||
const version_raw = readFileSync(version_path, { encoding: "utf-8" }).trim();
|
||||
const version_raw = JSON.parse(readFileSync(version_path, { encoding: "utf-8" })).version.trim();
|
||||
const version = version_raw.replace(/\./g, "-");
|
||||
|
||||
const client_version_path = resolve(
|
||||
__dirname,
|
||||
"../../client/python/gradio_client/version.txt"
|
||||
"../../client/python/gradio_client/package.json"
|
||||
);
|
||||
const client_version_raw = readFileSync(client_version_path, {
|
||||
encoding: "utf-8"
|
||||
}).trim();
|
||||
const client_version = client_version_raw.replace(/\./g, "-");
|
||||
const client_version_raw = JSON.parse(readFileSync(client_version_path, { encoding: "utf-8" })).version.trim();
|
||||
|
||||
import {
|
||||
inject_ejs,
|
||||
|
@ -42,8 +42,8 @@ upload_theme = "gradio.themes.upload_theme:main"
|
||||
Homepage = "https://github.com/gradio-app/gradio"
|
||||
|
||||
[tool.hatch.version]
|
||||
path = "gradio/version.txt"
|
||||
pattern = "(?P<version>.+)"
|
||||
path = "gradio/package.json"
|
||||
pattern = ".*\"version\":\\s*\"(?P<version>[^\"]+)\""
|
||||
|
||||
[tool.hatch.metadata.hooks.requirements_txt]
|
||||
filename = "requirements.txt"
|
||||
|
@ -3,9 +3,9 @@ import sys
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
root_directory = Path(__file__).parent.parent
|
||||
version = (root_directory / "gradio" / "version.txt").read_text(
|
||||
encoding='utf8').strip()
|
||||
version_file = Path(__file__).parent.parent / "gradio" / "package.json"
|
||||
with version_file.open() as f:
|
||||
version = json.load(f)["version"]
|
||||
|
||||
with urllib.request.urlopen("https://pypi.org/pypi/gradio/json") as url:
|
||||
releases = json.load(url)["releases"]
|
||||
|
@ -1,23 +1,22 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import tempfile
|
||||
import textwrap
|
||||
import requests
|
||||
|
||||
import huggingface_hub
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
VERSION_TXT = os.path.abspath(os.path.join(ROOT, "gradio", "version.txt"))
|
||||
VERSION_FILE = os.path.abspath(os.path.join(ROOT, "gradio", "package.json"))
|
||||
DIR = os.path.dirname(__file__)
|
||||
GRADIO_DEMO_DIR = os.path.abspath(os.path.join(ROOT, "demo"))
|
||||
|
||||
with open(VERSION_TXT) as f:
|
||||
gradio_version=f.read()
|
||||
gradio_version = gradio_version.strip()
|
||||
with open(VERSION_FILE) as f:
|
||||
version = json.load(f)["version"]
|
||||
|
||||
# Reasoning:
|
||||
# 1. all_demos includes all demos and is for testing PRs
|
||||
|
Loading…
x
Reference in New Issue
Block a user