Skip to content

Commit 8c003b4

Browse files
authored
Use CORTEX_CLI_CONFIG_DIR in python client when making temporary files (#1798)
1 parent 43dbfc8 commit 8c003b4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/cortex/client/cortex/client.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
EXPECTED_PYTHON_VERSION = "3.6.9"
3434

3535

36+
def cli_config_dir() -> Path:
37+
cli_config_dir = os.environ.get("CORTEX_CLI_CONFIG_DIR", "")
38+
if cli_config_dir == "":
39+
return Path.home() / ".cortex"
40+
return Path(cli_config_dir).expanduser().resolve()
41+
42+
3643
class Client:
3744
def __init__(self, env: dict):
3845
"""
@@ -91,7 +98,7 @@ def create_api(
9198
if api_spec.get("name") is None:
9299
raise ValueError("`api_spec` must have the `name` key set")
93100

94-
project_dir = Path.home() / ".cortex" / "deployments" / api_spec["name"]
101+
project_dir = cli_config_dir() / "deployments" / api_spec["name"]
95102

96103
if project_dir.exists():
97104
shutil.rmtree(str(project_dir))
@@ -296,9 +303,7 @@ def patch(self, api_spec: dict, force: bool = False) -> dict:
296303
force: Override an already in-progress API update.
297304
"""
298305

299-
cortex_yaml_file = (
300-
Path.home() / ".cortex" / "deployments" / f"cortex-{str(uuid.uuid4())}.yaml"
301-
)
306+
cortex_yaml_file = cli_config_dir() / "deployments" / f"cortex-{str(uuid.uuid4())}.yaml"
302307
with util.open_temporarily(cortex_yaml_file, "w") as f:
303308
yaml.dump([api_spec], f)
304309
args = ["patch", cortex_yaml_file, "--env", self.env_name, "-o", "json"]

0 commit comments

Comments
 (0)