replacing distutils.StrictVersion dependency for Python 3.12 (#6938)

* replacing distutils.StrictVersion dependency with packaging.version.Version after distutils deprecation (in 3.10) and removal in Python 3.12 (see https://docs.python.org/3.10/whatsnew/3.10.html#distutils-deprecated)

* add changeset

* remove distutils

* add changeset

---------

Co-authored-by: daniel <daniel@tfc.ai>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
D 2024-01-04 00:05:40 +08:00 committed by GitHub
parent 02c2442217
commit 459c5dc989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/wasm": patch
"gradio": patch
---
fix:replacing distutils.StrictVersion dependency for Python 3.12

View File

@ -7,7 +7,7 @@ import os
import threading
import urllib.parse
import warnings
from distutils.version import StrictVersion
from packaging.version import Version
from typing import Any
import httpx
@ -88,7 +88,7 @@ def version_check():
try:
current_pkg_version = get_package_version()
latest_pkg_version = httpx.get(url=PKG_VERSION_URL, timeout=3).json()["version"]
if StrictVersion(latest_pkg_version) > StrictVersion(current_pkg_version):
if Version(latest_pkg_version) > Version(current_pkg_version):
print(
f"IMPORTANT: You are using gradio version {current_pkg_version}, "
f"however version {latest_pkg_version} is available, please upgrade."

View File

@ -75,7 +75,7 @@ async function initializeEnvironment(
updateProgress("Loading Gradio wheels");
await micropip.add_mock_package("ffmpy", "0.3.0");
await micropip.add_mock_package("aiohttp", "3.8.4");
await pyodide.loadPackage(["ssl", "distutils", "setuptools"]);
await pyodide.loadPackage(["ssl", "setuptools"]);
await micropip.install(["typing-extensions>=4.8.0"]); // Typing extensions needs to be installed first otherwise the versions from the pyodide lockfile is used which is incompatible with the latest fastapi.
await micropip.install(["markdown-it-py[linkify]~=2.2.0"]); // On 3rd June 2023, markdown-it-py 3.0.0 has been released. The `gradio` package depends on its `>=2.0.0` version so its 3.x will be resolved. However, it conflicts with `mdit-py-plugins`'s dependency `markdown-it-py >=1.0.0,<3.0.0` and micropip currently can't resolve it. So we explicitly install the compatible version of the library here.
await micropip.install(["anyio==3.*"]); // `fastapi` depends on `anyio>=3.4.0,<5` so its 4.* can be installed, but it conflicts with the anyio version `httpx` depends on, `==3.*`. Seems like micropip can't resolve it for now, so we explicitly install the compatible version of the library here.