From e5693f4006e966782679264cad5240588fbb8969 Mon Sep 17 00:00:00 2001 From: Jamie Date: Mon, 3 Jun 2024 15:38:03 +0100 Subject: [PATCH 1/3] import packaging to be compatible with setuptools==70.0.0 --- clip/clip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clip/clip.py b/clip/clip.py index f7a5da5e6..58afd838f 100644 --- a/clip/clip.py +++ b/clip/clip.py @@ -3,7 +3,7 @@ import urllib import warnings from typing import Any, Union, List -from pkg_resources import packaging +import packaging import torch from PIL import Image From 374b2a3a80c9f552cdff876bd29260744c6cf3c3 Mon Sep 17 00:00:00 2001 From: Jamie Date: Mon, 3 Jun 2024 15:51:44 +0100 Subject: [PATCH 2/3] import packaging to be compatible with setuptools==70.0.0, while also supporting prior setuptools versions --- clip/clip.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/clip/clip.py b/clip/clip.py index 58afd838f..9c037a7b2 100644 --- a/clip/clip.py +++ b/clip/clip.py @@ -3,7 +3,7 @@ import urllib import warnings from typing import Any, Union, List -import packaging +import pkg_resources import torch from PIL import Image @@ -20,6 +20,30 @@ BICUBIC = Image.BICUBIC +import pkg_resources + +# Solves import issue with changes in setuptools 70.0.0 (https://setuptools.pypa.io/en/stable/history.html#v70-0-0) +def import_packaging(): + try: + # Get the version of setuptools + setuptools_version = pkg_resources.get_distribution("setuptools").version + # Print setuptools version for debugging + print(f"setuptools version: {setuptools_version}") + + # Parse the version string to compare versions + from packaging import version + if version.parse(setuptools_version) >= version.parse("70.0.0"): + # For setuptools version 70.0.0 and above + import packaging + else: + # For setuptools versions below 70.0.0 + from pkg_resources import packaging + return packaging + except Exception as e: + raise ImportError(f"Failed to import 'packaging' module: {e}") + +packaging = import_packaging() + if packaging.version.parse(torch.__version__) < packaging.version.parse("1.7.1"): warnings.warn("PyTorch version 1.7.1 or higher is recommended") @@ -39,6 +63,27 @@ "ViT-L/14@336px": "https://openaipublic.azureedge.net/clip/models/3035c92b350959924f9f00213499208652fc7ea050643e8b385c2dac08641f02/ViT-L-14-336px.pt", } +def import_packaging(): + try: + # Get the version of setuptools + setuptools_version = pkg_resources.get_distribution("setuptools").version + # Print setuptools version for debugging + print(f"setuptools version: {setuptools_version}") + + # Parse the version string to compare versions + from packaging import version + if version.parse(setuptools_version) >= version.parse("70.0.0"): + # For setuptools version 70.0.0 and above + import packaging + else: + # For setuptools versions below 70.0.0 + from pkg_resources import packaging + return packaging + except Exception as e: + raise ImportError(f"Failed to import 'packaging' module: {e}") + +packaging = import_packaging() + def _download(url: str, root: str): os.makedirs(root, exist_ok=True) From a780b46cae2b748bdb9be60ecba35c0bb4b0baa5 Mon Sep 17 00:00:00 2001 From: Jamie Date: Mon, 3 Jun 2024 16:08:48 +0100 Subject: [PATCH 3/3] removing duplicate --- clip/clip.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/clip/clip.py b/clip/clip.py index 9c037a7b2..070f7da55 100644 --- a/clip/clip.py +++ b/clip/clip.py @@ -63,28 +63,6 @@ def import_packaging(): "ViT-L/14@336px": "https://openaipublic.azureedge.net/clip/models/3035c92b350959924f9f00213499208652fc7ea050643e8b385c2dac08641f02/ViT-L-14-336px.pt", } -def import_packaging(): - try: - # Get the version of setuptools - setuptools_version = pkg_resources.get_distribution("setuptools").version - # Print setuptools version for debugging - print(f"setuptools version: {setuptools_version}") - - # Parse the version string to compare versions - from packaging import version - if version.parse(setuptools_version) >= version.parse("70.0.0"): - # For setuptools version 70.0.0 and above - import packaging - else: - # For setuptools versions below 70.0.0 - from pkg_resources import packaging - return packaging - except Exception as e: - raise ImportError(f"Failed to import 'packaging' module: {e}") - -packaging = import_packaging() - - def _download(url: str, root: str): os.makedirs(root, exist_ok=True) filename = os.path.basename(url)