Skip to content

Commit

Permalink
fix(pkg_resources): use importlib in favor of pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jayceslesar committed Jul 31, 2023
1 parent 5244c58 commit 352497e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-rooms-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:fix(pkg_resources): use `importlib.resources`
20 changes: 9 additions & 11 deletions gradio/cli_env_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
"""
import platform

import pkg_resources

from importlib.metadata import version, distribution, PackageNotFoundError

def print_environment_info():
print("Gradio Environment Information:")

print("Operating System: ", platform.system())
print("\n")

for package_name in ["gradio", "gradio_client"]:
try:
package_dist = pkg_resources.get_distribution(package_name)
package_version = package_dist.version
package_version = version(package_name)
print(f"{package_name} version: ", package_version)

print(f"\n{package_name} Dependencies:")
for req in package_dist.requires():
print(
f" {req.project_name}: {pkg_resources.get_distribution(req.project_name).version}"
)

dist = distribution(package_name)
for req in dist.requires:
try:
print(f" {req}: {version(req)}")
except PackageNotFoundError:
print(f"{req} is not installed.")
print("\n")
except pkg_resources.DistributionNotFound:
except PackageNotFoundError:
print(f"{package_name} package is not installed.")
5 changes: 3 additions & 2 deletions gradio/flagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import filelock
import huggingface_hub
import pkg_resources
import importlib.resources as pkg_resources
from importlib.metadata import version
from gradio_client import utils as client_utils
from gradio_client.documentation import document, set_documentation_group

Expand Down Expand Up @@ -242,7 +243,7 @@ def setup(self, components: list[IOComponent], flagging_dir: str):
flagging_dir (str): local directory where the dataset is cloned,
updated, and pushed from.
"""
hh_version = pkg_resources.get_distribution("huggingface_hub").version
hh_version = version("huggingface_hub")
try:
if StrictVersion(hh_version) < StrictVersion("0.12.0"):
raise ImportError(
Expand Down
10 changes: 5 additions & 5 deletions gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import httpx
import markupsafe
import orjson
import pkg_resources
import importlib.resources as pkg_resources
from fastapi import Depends, FastAPI, File, HTTPException, UploadFile, WebSocket, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import (
Expand Down Expand Up @@ -52,10 +52,10 @@

mimetypes.init()

STATIC_TEMPLATE_LIB = pkg_resources.resource_filename("gradio", "templates/")
STATIC_PATH_LIB = pkg_resources.resource_filename("gradio", "templates/frontend/static")
BUILD_PATH_LIB = pkg_resources.resource_filename("gradio", "templates/frontend/assets")
VERSION_FILE = pkg_resources.resource_filename("gradio", "version.txt")
STATIC_TEMPLATE_LIB = pkg_resources.path("gradio", "templates")
STATIC_PATH_LIB = pkg_resources.path("gradio", "templates.frontend.static")
BUILD_PATH_LIB = pkg_resources.path("gradio", "templates.frontend.assets")
VERSION_FILE = pkg_resources.path("gradio", "version.txt")
with open(VERSION_FILE) as version_file:
VERSION = version_file.read()

Expand Down

0 comments on commit 352497e

Please sign in to comment.