Elron commited on
Commit
1849dad
1 Parent(s): 4c76401

Upload register.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. register.py +37 -19
register.py CHANGED
@@ -1,43 +1,61 @@
1
- import inspect
2
- import os
3
  import importlib
4
  import inspect
 
5
 
6
- from .artifact import Artifact
 
7
  from .utils import Singleton
 
 
 
 
8
  # Usage
9
- non_registered_files = ['__init__.py', 'artifact.py', 'utils.py', 'register.py', 'metric.py', 'dataset.py', 'blocks.py']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def _register_all_artifacts():
12
-
13
  dir = os.path.dirname(__file__)
14
  file_name = os.path.basename(__file__)
15
-
16
  for file in os.listdir(dir):
17
- if file.endswith('.py') and file not in non_registered_files and file != file_name:
18
- module_name = file.replace('.py', '')
19
-
20
- module = importlib.import_module('.' + module_name, __package__)
21
-
22
  for name, obj in inspect.getmembers(module):
23
  # Make sure the object is a class
24
  if inspect.isclass(obj):
25
  # Make sure the class is a subclass of Artifact (but not Artifact itself)
26
  if issubclass(obj, Artifact) and obj is not Artifact:
27
  Artifact.register_class(obj)
28
-
29
 
30
- class ProjectArtifactRegisterer(Singleton):
31
-
32
  def __init__(self):
33
-
34
- if not hasattr(self, '_registered'):
35
  self._registered = False
36
-
37
  if not self._registered:
 
38
  _register_all_artifacts()
39
  self._registered = True
40
-
41
 
42
  def register_all_artifacts():
43
- 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()