Skip to content

Commit

Permalink
Update some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amritghimire committed Oct 16, 2024
1 parent 3798325 commit 1f636cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/datachain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(
):
self.level = level

self.init()

@classmethod
def get_dir(cls, level: Optional[str]) -> str:
if level == "system":
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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]:
Expand Down
14 changes: 8 additions & 6 deletions src/datachain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 1f636cd

Please sign in to comment.