| 469 | return cached_path(file_path, download_config=download_config) |
| 470 | |
| 471 | def get_module(self) -> ImportableModule: |
| 472 | revision = self.revision or os.getenv("HF_SCRIPTS_VERSION", SCRIPTS_VERSION) |
| 473 | |
| 474 | if re.match(r"\d*\.\d*\.\d*", revision): # revision is version number (three digits separated by full stops) |
| 475 | revision = "v" + revision # tagging convention on evaluate repository starts with v |
| 476 | |
| 477 | # get script and other files |
| 478 | try: |
| 479 | local_path = self.download_loading_script(revision) |
| 480 | except FileNotFoundError as err: |
| 481 | # if there is no file found with current revision tag try to load main |
| 482 | if self.revision is None and os.getenv("HF_SCRIPTS_VERSION", SCRIPTS_VERSION) != "main": |
| 483 | revision = "main" |
| 484 | local_path = self.download_loading_script(revision) |
| 485 | else: |
| 486 | raise err |
| 487 | |
| 488 | imports = get_imports(local_path) |
| 489 | local_imports = _download_additional_modules( |
| 490 | name=self.name, |
| 491 | base_path=hf_hub_url(path=self.name, name="", revision=revision), |
| 492 | imports=imports, |
| 493 | download_config=self.download_config, |
| 494 | ) |
| 495 | # copy the script and the files in an importable directory |
| 496 | dynamic_modules_path = self.dynamic_modules_path if self.dynamic_modules_path else init_dynamic_modules() |
| 497 | module_path, hash = _create_importable_file( |
| 498 | local_path=local_path, |
| 499 | local_imports=local_imports, |
| 500 | additional_files=[], |
| 501 | dynamic_modules_path=dynamic_modules_path, |
| 502 | module_namespace=self.module_type, |
| 503 | name=self.name, |
| 504 | download_mode=self.download_mode, |
| 505 | ) |
| 506 | # make the new module to be noticed by the import system |
| 507 | importlib.invalidate_caches() |
| 508 | return ImportableModule(module_path, hash) |
| 509 | |
| 510 | |
| 511 | class CachedEvaluationModuleFactory(_EvaluationModuleFactory): |