diff --git a/src/datachain/config.py b/src/datachain/config.py index 68b3e7a8..f5a73905 100644 --- a/src/datachain/config.py +++ b/src/datachain/config.py @@ -22,6 +22,8 @@ def __init__( ): self.level = level + self.init() + @classmethod def get_dir(cls, level: Optional[str]) -> str: if level == "system": @@ -31,13 +33,12 @@ def get_dir(cls, level: Optional[str]) -> str: return DataChainDir.find().root - @staticmethod - def init(datachain_dir: Optional[str] = None): - d = DataChainDir(datachain_dir) + def init(self): + d = DataChainDir(self.get_dir(self.level)) d.init() with open(d.config, "w"): - return Config(d.root) + return self def load_one(self, level: Optional[str] = None) -> TOMLDocument: config_path = DataChainDir(self.get_dir(level)).config @@ -60,7 +61,7 @@ def load_config_to_level(self) -> TOMLDocument: return merged_conf - def read(self) -> Optional[TOMLDocument]: + def read(self) -> TOMLDocument: if self.level is None: return self.load_config_to_level() return self.load_one(self.level) @@ -72,10 +73,11 @@ def edit(self): self.write(config) - def write(self, config: TOMLDocument): - config_file = DataChainDir(self.get_dir(self.level)).config + def config_file(self): + return DataChainDir(self.get_dir(self.level)).config - with open(config_file, "w") as f: + def write(self, config: TOMLDocument): + with open(self.config_file(), "w") as f: dump(config, f) def get_remote_config(self, remote: str = "") -> Mapping[str, str]: diff --git a/src/datachain/utils.py b/src/datachain/utils.py index dcb61527..712f5084 100644 --- a/src/datachain/utils.py +++ b/src/datachain/utils.py @@ -30,6 +30,8 @@ APPAUTHOR = "iterative" ENV_DATACHAIN_SYSTEM_CONFIG_DIR = "DATACHAIN_SYSTEM_CONFIG_DIR" ENV_DATACHAIN_GLOBAL_CONFIG_DIR = "DATACHAIN_GLOBAL_CONFIG_DIR" +STUDIO_URL = "https://studio.dvc.ai" + T = TypeVar("T", bound="DataChainDir") @@ -97,15 +99,15 @@ def find(cls: type[T], create: bool = True) -> T: def system_config_dir(): - return os.getenv( - DataChainDir.ENV_DATACHAIN_SYSTEM_CONFIG_DIR - ) or platformdirs.site_config_dir(APPNAME, APPAUTHOR) + return os.getenv(ENV_DATACHAIN_SYSTEM_CONFIG_DIR) or platformdirs.site_config_dir( + APPNAME, APPAUTHOR + ) def global_config_dir(): - return os.getenv( - DataChainDir.ENV_DATACHAIN_GLOBAL_CONFIG_DIR - ) or platformdirs.user_config_dir(APPNAME, APPAUTHOR) + return os.getenv(ENV_DATACHAIN_GLOBAL_CONFIG_DIR) or platformdirs.user_config_dir( + APPNAME, APPAUTHOR + ) def human_time_to_int(time: str) -> Optional[int]: