Elron commited on
Commit
d9933d4
1 Parent(s): 523aeee

Upload register.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. register.py +34 -28
register.py CHANGED
@@ -1,55 +1,61 @@
1
- import inspect
2
- import os
3
  import importlib
4
  import inspect
 
5
 
6
- from . import blocks
7
- from .artifact import Artifact
8
  from .utils import Singleton
9
 
10
- def register_blocks():
11
- # Iterate over every object in the blocks module
12
- for name, obj in inspect.getmembers(blocks):
13
- # Make sure the object is a class
14
- if inspect.isclass(obj):
15
- # Make sure the class is a subclass of Artifact (but not Artifact itself)
16
- if issubclass(obj, Artifact) and obj is not Artifact:
17
- Artifact.register_class(obj)
18
 
19
  # Usage
20
- non_registered_files = ['__init__.py', 'artifact.py', 'utils.py', 'register.py', 'metric.py', 'dataset.py', 'blocks.py']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def _register_all_artifacts():
23
-
24
  dir = os.path.dirname(__file__)
25
  file_name = os.path.basename(__file__)
26
-
27
  for file in os.listdir(dir):
28
- if file.endswith('.py') and file not in non_registered_files and file != file_name:
29
- module_name = file.replace('.py', '')
30
-
31
- module = importlib.import_module('.' + module_name, __package__)
32
-
33
  for name, obj in inspect.getmembers(module):
34
  # Make sure the object is a class
35
  if inspect.isclass(obj):
36
  # Make sure the class is a subclass of Artifact (but not Artifact itself)
37
  if issubclass(obj, Artifact) and obj is not Artifact:
38
  Artifact.register_class(obj)
39
-
40
 
41
 
42
- class ProjectArtifactRegisterer():
43
-
44
  def __init__(self):
45
-
46
- if not hasattr(self, '_registered'):
47
  self._registered = False
48
-
49
  if not self._registered:
 
50
  _register_all_artifacts()
51
  self._registered = True
52
-
53
 
54
  def register_all_artifacts():
55
- ProjectArtifactRegisterer()
 
 
 
1
  import importlib
2
  import inspect
3
+ import os
4
 
5
+ from .artifact import Artifact, Artifactories
6
+ from .catalog import LocalCatalog, GithubCatalog, PATHS_SEP
7
  from .utils import Singleton
8
 
9
+
10
+ UNITXT_ARTIFACTORIES_ENV_VAR = 'UNITXT_ARTIFACTORIES'
 
 
 
 
 
 
11
 
12
  # Usage
13
+ non_registered_files = [
14
+ "__init__.py",
15
+ "artifact.py",
16
+ "utils.py",
17
+ "register.py",
18
+ "metric.py",
19
+ "dataset.py",
20
+ "blocks.py",
21
+ ]
22
+
23
+
24
+ def _register_all_catalogs():
25
+ Artifactories().register_atrifactory(LocalCatalog())
26
+ if UNITXT_ARTIFACTORIES_ENV_VAR in os.environ:
27
+ for path in os.environ[UNITXT_ARTIFACTORIES_ENV_VAR].split(PATHS_SEP):
28
+ Artifactories().register_atrifactory(LocalCatalog(location=path))
29
+ Artifactories().register_atrifactory(GithubCatalog())
30
 
31
  def _register_all_artifacts():
 
32
  dir = os.path.dirname(__file__)
33
  file_name = os.path.basename(__file__)
34
+
35
  for file in os.listdir(dir):
36
+ if file.endswith(".py") and file not in non_registered_files and file != file_name:
37
+ module_name = file.replace(".py", "")
38
+
39
+ module = importlib.import_module("." + module_name, __package__)
40
+
41
  for name, obj in inspect.getmembers(module):
42
  # Make sure the object is a class
43
  if inspect.isclass(obj):
44
  # Make sure the class is a subclass of Artifact (but not Artifact itself)
45
  if issubclass(obj, Artifact) and obj is not Artifact:
46
  Artifact.register_class(obj)
 
47
 
48
 
49
+ class ProjectArtifactRegisterer(metaclass=Singleton):
 
50
  def __init__(self):
51
+ if not hasattr(self, "_registered"):
 
52
  self._registered = False
53
+
54
  if not self._registered:
55
+ _register_all_catalogs()
56
  _register_all_artifacts()
57
  self._registered = True
58
+
59
 
60
  def register_all_artifacts():
61
+ ProjectArtifactRegisterer()