Skip to content

Commit 7783312

Browse files
committed
refactor(cli): drop PLC0415 suppression by moving import to module scope
1 parent bfdcb62 commit 7783312

1 file changed

Lines changed: 8 additions & 26 deletions

File tree

autosearch/cli/main.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from autosearch import __version__
1111
from autosearch.cli.mcp_config_writers import MCPConfigWriteError
12+
from autosearch.core import secrets_store
1213
from autosearch.core.environment_probe import probe_environment
1314
from autosearch.core.models import SearchMode
1415
from autosearch.core.scope_clarifier import ScopeClarifier
@@ -82,9 +83,7 @@ def main(
8283
# Push ~/.config/ai-secrets.env keys into process env so subcommands and
8384
# any provider/channel that does `os.getenv("FOO_API_KEY")` actually sees
8485
# what the user configured via `autosearch configure`.
85-
from autosearch.core.secrets_store import inject_into_env
86-
87-
inject_into_env()
86+
secrets_store.inject_into_env()
8887

8988
if ctx.invoked_subcommand is None and not version:
9089
raise typer.Exit(code=0)
@@ -483,8 +482,6 @@ def configure(
483482
Default flow: prompts for the value with hidden input so the secret never
484483
appears on the command line, in shell history, or in `ps`.
485484
"""
486-
import sys
487-
488485
if from_stdin:
489486
value = sys.stdin.read().rstrip("\n")
490487
elif value is None:
@@ -501,17 +498,8 @@ def configure(
501498
typer.echo("error: value must not be empty.", err=True)
502499
raise typer.Exit(code=2)
503500

504-
# Bug 3 (fix-plan): write target must follow AUTOSEARCH_SECRETS_FILE so
505-
# containers / CI / multi-user installs don't end up writing to A while
506-
# the runtime reads B.
507-
from autosearch.core.secrets_store import ( # noqa: PLC0415
508-
load_secrets,
509-
secrets_path as _secrets_path,
510-
write_secret,
511-
)
512-
513-
secrets_path = _secrets_path()
514-
existing = load_secrets(secrets_path)
501+
secrets_path = secrets_store.secrets_path()
502+
existing = secrets_store.load_secrets(secrets_path)
515503

516504
if key in existing and not replace:
517505
typer.echo(
@@ -520,7 +508,7 @@ def configure(
520508
)
521509
raise typer.Exit(code=0)
522510

523-
write_secret(key, value, path=secrets_path)
511+
secrets_store.write_secret(key, value, path=secrets_path)
524512
typer.echo(f"Written: {key} -> {secrets_path}")
525513

526514

@@ -750,18 +738,12 @@ def _write_cookie_to_secrets(
750738
the same file we just wrote. Bug 4: chmods the file 0o600 after write
751739
so cookies aren't world-readable on shared boxes.
752740
"""
753-
from autosearch.core.secrets_store import (
754-
load_secrets,
755-
secrets_path as _secrets_path,
756-
write_secret,
757-
)
758-
759-
secrets_path = _secrets_path()
760-
existing = load_secrets(secrets_path)
741+
secrets_path = secrets_store.secrets_path()
742+
existing = secrets_store.load_secrets(secrets_path)
761743
label = f"{n_cookies} cookies" if n_cookies else "cookies"
762744
existed = env_key in existing
763745

764-
write_secret(env_key, cookie_str, path=secrets_path)
746+
secrets_store.write_secret(env_key, cookie_str, path=secrets_path)
765747
if existed:
766748
typer.echo(f"Updated {env_key} ({label}) → {secrets_path}")
767749
else:

0 commit comments

Comments
 (0)