Skip to content

Commit

Permalink
fix(pkg_resources): replace with importlib functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jayceslesar committed Jul 31, 2023
1 parent 68e6c98 commit b0f98fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
20 changes: 9 additions & 11 deletions gradio/cli_env_info.py
Expand Up @@ -3,27 +3,25 @@
"""
import platform

import importlib.resources as 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.")
3 changes: 2 additions & 1 deletion gradio/flagging.py
Expand Up @@ -15,6 +15,7 @@
import filelock
import huggingface_hub
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
6 changes: 3 additions & 3 deletions gradio/routes.py
Expand Up @@ -52,9 +52,9 @@

mimetypes.init()

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")
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 b0f98fa

Please sign in to comment.