Skip to content

Commit 78c253e

Browse files
Fix Python client not respecting CORTEX_CLI_CONFIG_DIR environment variable for client-id.txt (#1953)
1 parent b3e2fc8 commit 78c253e

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

pkg/cortex/client/cortex/client.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
from cortex import util
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-
4336
class Client:
4437
@sentry_wrapper
4538
def __init__(self, env: dict):
@@ -129,7 +122,7 @@ def create_api(
129122
if api_spec.get("name") is None:
130123
raise ValueError("`api_spec` must have the `name` key set")
131124

132-
project_dir = cli_config_dir() / "deployments" / api_spec["name"]
125+
project_dir = util.cli_config_dir() / "deployments" / api_spec["name"]
133126

134127
if project_dir.exists():
135128
shutil.rmtree(str(project_dir))
@@ -367,7 +360,9 @@ def patch(self, api_spec: dict, force: bool = False) -> dict:
367360
force: Override an already in-progress API update.
368361
"""
369362

370-
cortex_yaml_file = cli_config_dir() / "deployments" / f"cortex-{str(uuid.uuid4())}.yaml"
363+
cortex_yaml_file = (
364+
util.cli_config_dir() / "deployments" / f"cortex-{str(uuid.uuid4())}.yaml"
365+
)
371366
with util.open_temporarily(cortex_yaml_file, "w") as f:
372367
yaml.dump([api_spec], f)
373368
args = ["patch", cortex_yaml_file, "--env", self.env_name, "-o", "json"]

pkg/cortex/client/cortex/telemetry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
CORTEX_TELEMETRY_SENTRY_DSN,
2929
CORTEX_TELEMETRY_SENTRY_ENVIRONMENT,
3030
)
31+
from cortex import util
3132

3233

3334
def _sentry_client(
@@ -81,7 +82,7 @@ def _create_default_scope(optional_tags: dict = {}) -> sentry_sdk.Scope:
8182
scope = sentry_sdk.Scope()
8283

8384
user_id = None
84-
client_id_file_path = pathlib.Path.home() / ".cortex" / "client-id.txt"
85+
client_id_file_path = util.cli_config_dir() / "client-id.txt"
8586
if not client_id_file_path.is_file():
8687
client_id_file_path.parent.mkdir(parents=True, exist_ok=True)
8788
client_id_file_path.write_text(str(uuid4()))

pkg/cortex/client/cortex/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
import shutil
1919

2020

21+
def cli_config_dir() -> Path:
22+
cli_config_dir = os.environ.get("CORTEX_CLI_CONFIG_DIR", "")
23+
if cli_config_dir == "":
24+
return Path.home() / ".cortex"
25+
return Path(cli_config_dir).expanduser().resolve()
26+
27+
2128
@contextmanager
2229
def open_temporarily(path, mode):
2330
Path(path).parent.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)