Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions qnexus/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import warnings
from functools import wraps
from pathlib import Path
from typing import Any, Callable, Literal, ParamSpec, TypeVar

from httpx import Response
Expand Down Expand Up @@ -45,7 +44,7 @@ def remove_token(token_type: TokenTypes) -> None:
# Don't try to delete refresh token in Jupyterhub
if is_jupyterhub_environment() and token_type == "refresh_token":
return
token_file_path = Path.home() / CONFIG.token_path / token_file_from_type[token_type]
token_file_path = CONFIG.resolved_token_path / token_file_from_type[token_type]
if token_file_path.exists():
token_file_path.unlink()

Expand Down Expand Up @@ -77,7 +76,7 @@ class AccessToken(BaseModel):

def read_token(token_type: TokenTypes) -> str:
"""Read a token from a file."""
token_file_path = Path.home() / CONFIG.token_path
token_file_path = CONFIG.resolved_token_path
with (token_file_path / token_file_from_type[token_type]).open(
encoding="UTF-8"
) as file:
Expand All @@ -94,7 +93,7 @@ def write_token(token_type: TokenTypes, token: str) -> None:
if is_jupyterhub_environment() and token_type == "refresh_token":
return

token_file_path = Path.home() / CONFIG.token_path
token_file_path = CONFIG.resolved_token_path
token_file_path.mkdir(parents=True, exist_ok=True)
with (token_file_path / token_file_from_type[token_type]).open(
encoding="UTF-8", mode="w"
Expand Down
9 changes: 9 additions & 0 deletions qnexus/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Quantinuum Nexus API client configuration via pydantic-settings."""

from pathlib import Path
from pydantic import AliasChoices, Field
from pydantic_settings import BaseSettings, SettingsConfigDict

Expand All @@ -24,6 +25,14 @@ class Config(BaseSettings):
# auth
store_tokens: bool = True # Not implemented
token_path: str = ".qnx/auth"
absolute_token_path: str | None = None

@property
def resolved_token_path(self) -> Path:
"""Resolve token path from token_path and absolute_token_path."""
if self.absolute_token_path is not None:
return Path(self.absolute_token_path)
return Path(Path.home(), self.token_path)

# testing
qa_user_email: str = ""
Expand Down