18 from pathlib
import Path
25 from .user
import UserConfiguration
26 from .node
import NodeConfiguration
27 from .base
import CONFIG_DIR, DEFAULT_VENV_PATH, InvalidConfiguration, ConfigurationNotFound
28 from ..utils
import isCliRuntime
31 def configMigration(configPath: Path) ->
None:
32 with configPath.open(
"r")
as file:
33 oldConfig = json.load(file)
36 "username": oldConfig.get(
"username"),
37 "password": oldConfig.get(
"password"),
38 "token": oldConfig.get(
"token"),
39 "refreshToken": oldConfig.get(
"refreshToken"),
40 "tokenExpirationDate": oldConfig.get(
"tokenExpirationDate"),
41 "refreshTokenExpirationDate": oldConfig.get(
"refreshTokenExpirationDate"),
42 "serverUrl": oldConfig.get(
"serverUrl"),
43 "projectId": oldConfig.get(
"projectId"),
47 "name": oldConfig.get(
"nodeName"),
48 "accessToken": oldConfig.get(
"nodeAccessToken"),
49 "storagePath": oldConfig.get(
"storagePath"),
50 "image": oldConfig.get(
"image"),
51 "allowGpu": oldConfig.get(
"allowGpu"),
52 "ram": oldConfig.get(
"nodeRam"),
53 "sharedMemory": oldConfig.get(
"nodeSharedMemory"),
54 "swap": oldConfig.get(
"nodeSwap"),
55 "cpuCount": oldConfig.get(
"cpuCount"),
56 "mode": oldConfig.get(
"nodeMode"),
57 "allowDocker": oldConfig.get(
"allowDocker"),
58 "secret": oldConfig.get(
"nodeSecret"),
59 "initScript": oldConfig.get(
"initScript"),
60 "modelId": oldConfig.get(
"modelId"),
61 "id": oldConfig.get(
"nodeId")
65 if DEFAULT_VENV_PATH.exists():
66 shutil.rmtree(DEFAULT_VENV_PATH)
69 def _syncConfigWithEnv() -> None:
76 oldConfigPath = CONFIG_DIR /
"config.json"
77 if oldConfigPath.exists():
79 f
">> [Coretex] Old configuration found at path: {oldConfigPath}. Migrating to new configuration."
81 configMigration(oldConfigPath)
84 userConfig = UserConfiguration.load()
85 if not "CTX_API_URL" in os.environ:
86 os.environ[
"CTX_API_URL"] = userConfig.serverUrl
87 except (ConfigurationNotFound, InvalidConfiguration):
88 if not "CTX_API_URL" in os.environ:
89 os.environ[
"CTX_API_URL"] =
"https://api.coretex.ai/"
91 if not "CTX_STORAGE_PATH" in os.environ
or isCliRuntime():
92 os.environ[
"CTX_STORAGE_PATH"] = f
"{CONFIG_DIR}/data"