Upload hf_utils.py with huggingface_hub
Browse files- hf_utils.py +28 -0
hf_utils.py
CHANGED
|
@@ -2,6 +2,7 @@ from pathlib import Path
|
|
| 2 |
|
| 3 |
from datasets.utils.py_utils import get_imports
|
| 4 |
|
|
|
|
| 5 |
from .file_utils import get_all_files_in_dir
|
| 6 |
|
| 7 |
|
|
@@ -17,3 +18,30 @@ def get_missing_imports(file, exclude=None):
|
|
| 17 |
return [
|
| 18 |
i for i in required_modules if i not in imported_modules and i not in exclude
|
| 19 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from datasets.utils.py_utils import get_imports
|
| 4 |
|
| 5 |
+
from .deprecation_utils import compare_versions
|
| 6 |
from .file_utils import get_all_files_in_dir
|
| 7 |
|
| 8 |
|
|
|
|
| 18 |
return [
|
| 19 |
i for i in required_modules if i not in imported_modules and i not in exclude
|
| 20 |
]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class UnitxtVersionsConflictError(ValueError):
|
| 24 |
+
def __init__(self, error_in: str, hf_unitxt_version, installed_unitxt_version):
|
| 25 |
+
assert hf_unitxt_version != installed_unitxt_version
|
| 26 |
+
if compare_versions(hf_unitxt_version, installed_unitxt_version) == 1:
|
| 27 |
+
msg = f"Located installed unitxt version {installed_unitxt_version} that is older then unitxt {error_in} version {hf_unitxt_version}. Please update unitxt package or uninstall it to avoid conflicts."
|
| 28 |
+
if compare_versions(hf_unitxt_version, installed_unitxt_version) == -1:
|
| 29 |
+
msg = f"Located installed unitxt version {installed_unitxt_version} that is newer then unitxt {error_in} version {hf_unitxt_version}. Please force-reload the {error_in} or downgrade unitxt to {error_in} version or uninstall unitxt to avoid conflicts."
|
| 30 |
+
super().__init__(msg)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def get_installed_version():
|
| 34 |
+
from unitxt.settings_utils import get_constants as installed_get_constants
|
| 35 |
+
|
| 36 |
+
return installed_get_constants().version
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def verify_versions_compatibility(hf_asset_type, hf_asset_version):
|
| 40 |
+
_verify_versions(hf_asset_type, get_installed_version(), hf_asset_version)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _verify_versions(hf_asset_type, installed_version, hf_asset_version):
|
| 44 |
+
if installed_version != hf_asset_version:
|
| 45 |
+
raise UnitxtVersionsConflictError(
|
| 46 |
+
hf_asset_type, hf_asset_version, installed_version
|
| 47 |
+
)
|