Download settings_utils.py from unitxt/data: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/unitxt/data/resolve/ccce770f3c9d7e5f2b14abf5154955e8752c449d/settings_utils.py
- Command line
-
hf download hf://datasets/unitxt/data@ccce770f3c9d7e5f2b14abf5154955e8752c449d/settings_utils.py
-
curl -L -o settings_utils.py https://huggingface.co/datasets/unitxt/data/resolve/ccce770f3c9d7e5f2b14abf5154955e8752c449d/settings_utils.py
1.23 kB
| import os | |
| class Settings: | |
| _instance = None | |
| _settings = {} | |
| def __new__(cls): | |
| if cls._instance is None: | |
| cls._instance = super().__new__(cls) | |
| return cls._instance | |
| def __setattr__(self, key, value): | |
| if key.endswith("_key") or key in {"_instance", "_settings"}: | |
| raise AttributeError(f"Modifying '{key}' is not allowed.") | |
| self._settings[key] = value | |
| def __getattr__(self, key): | |
| if key.endswith("_key"): | |
| actual_key = key[:-4] # Remove the "_key" suffix | |
| return self.environment_variable_key_name(actual_key) | |
| env_value = os.getenv(self.environment_variable_key_name(key)) | |
| if env_value is not None: | |
| return env_value | |
| if key in self._settings: | |
| return self._settings[key] | |
| raise AttributeError(f"'{key}' not found") | |
| def environment_variable_key_name(self, key): | |
| return "UNITXT_" + key.upper() | |
| def get_all_environment_variables(self): | |
| return [ | |
| self.environment_variable_key_name(key) for key in self._settings.keys() | |
| ] | |
| settings = Settings() | |
| settings.allow_unverified_code = False | |
| def get_settings(): | |
| return Settings() | |