Elron commited on
Commit
1e56308
1 Parent(s): 47b886a

Upload settings_utils.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. settings_utils.py +84 -10
settings_utils.py CHANGED
@@ -1,16 +1,21 @@
1
  import os
2
 
3
- from .logging_utils import get_logger
4
 
5
- logger = get_logger()
6
 
7
 
8
  class Settings:
9
  _instance = None
10
  _settings = {}
 
 
 
 
 
11
 
12
  def __new__(cls):
13
- if cls._instance is None:
14
  cls._instance = super().__new__(cls)
15
  return cls._instance
16
 
@@ -18,9 +23,10 @@ class Settings:
18
  if key.endswith("_key") or key in {"_instance", "_settings"}:
19
  raise AttributeError(f"Modifying '{key}' is not allowed.")
20
  if key in self._settings:
21
- logger.info(
22
- f"unitxt.settings.{key} changed: {self._settings[key]} -> {value}"
23
- )
 
24
  self._settings[key] = value
25
 
26
  def __getattr__(self, key):
@@ -47,11 +53,79 @@ class Settings:
47
  ]
48
 
49
 
50
- settings = Settings()
51
- settings.allow_unverified_code = False
52
- settings.use_only_local_catalogs = False
53
- settings.global_loader_limit = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
 
56
  def get_settings():
57
  return Settings()
 
 
 
 
 
1
  import os
2
 
3
+ import pkg_resources
4
 
5
+ from .version import version
6
 
7
 
8
  class Settings:
9
  _instance = None
10
  _settings = {}
11
+ _logger = None
12
+
13
+ @classmethod
14
+ def is_uninitilized(cls):
15
+ return cls._instance is None
16
 
17
  def __new__(cls):
18
+ if cls.is_uninitilized():
19
  cls._instance = super().__new__(cls)
20
  return cls._instance
21
 
 
23
  if key.endswith("_key") or key in {"_instance", "_settings"}:
24
  raise AttributeError(f"Modifying '{key}' is not allowed.")
25
  if key in self._settings:
26
+ if self._logger is not None:
27
+ self._logger.info(
28
+ f"unitxt.settings.{key} changed: {self._settings[key]} -> {value}"
29
+ )
30
  self._settings[key] = value
31
 
32
  def __getattr__(self, key):
 
53
  ]
54
 
55
 
56
+ class Constants:
57
+ _instance = None
58
+ _constants = {}
59
+
60
+ @classmethod
61
+ def is_uninitilized(cls):
62
+ return cls._instance is None
63
+
64
+ def __new__(cls):
65
+ if cls.is_uninitilized():
66
+ cls._instance = super().__new__(cls)
67
+ return cls._instance
68
+
69
+ def __setattr__(self, key, value):
70
+ if key.endswith("_key") or key in {"_instance", "_constants"}:
71
+ raise AttributeError(f"Modifying '{key}' is not allowed.")
72
+ if key in self._constants:
73
+ raise ValueError("Cannot override constants.")
74
+ self._constants[key] = value
75
+
76
+ def __getattr__(self, key):
77
+ if key in self._constants:
78
+ return self._constants[key]
79
+
80
+ raise AttributeError(f"'{key}' not found")
81
+
82
+
83
+ if Settings.is_uninitilized():
84
+ settings = Settings()
85
+ settings.allow_unverified_code = False
86
+ settings.use_only_local_catalogs = False
87
+ settings.global_loader_limit = None
88
+ settings.num_resamples_for_instance_metrics = 1000
89
+ settings.num_resamples_for_global_metrics = 100
90
+ settings.max_log_message_size = 100000
91
+ settings.artifactories = None
92
+ settings.default_recipe = "standard_recipe"
93
+ settings.default_verbosity = "debug"
94
+ settings.remote_metrics = []
95
+
96
+ if Constants.is_uninitilized():
97
+ constants = Constants()
98
+ constants.dataset_file = os.path.join(os.path.dirname(__file__), "dataset.py")
99
+ constants.metric_file = os.path.join(os.path.dirname(__file__), "metric.py")
100
+ constants.local_catalog_path = os.path.join(os.path.dirname(__file__), "catalog")
101
+ try:
102
+ constants.default_catalog_path = pkg_resources.resource_filename(
103
+ "unitxt", "catalog"
104
+ )
105
+ except ModuleNotFoundError:
106
+ constants.default_catalog_path = constants.local_catalog_path
107
+ constants.catalog_dir = constants.local_catalog_path
108
+ constants.dataset_url = "unitxt/data"
109
+ constants.metric_url = "unitxt/metric"
110
+ constants.version = version
111
+ constants.catalog_hirarchy_sep = "."
112
+ constants.env_local_catalogs_paths_sep = ":"
113
+ constants.non_registered_files = [
114
+ "__init__.py",
115
+ "artifact.py",
116
+ "utils.py",
117
+ "register.py",
118
+ "metric.py",
119
+ "dataset.py",
120
+ "blocks.py",
121
+ ]
122
+ constants.codebase_url = "https://github.com/IBM/unitxt"
123
+ constants.website_url = "https://www.unitxt.org"
124
 
125
 
126
  def get_settings():
127
  return Settings()
128
+
129
+
130
+ def get_constants():
131
+ return Constants()