Skip to content
Merged
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
3 changes: 2 additions & 1 deletion tests/test_cli/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def test_tidy3d_root_command_names_are_unique():
command_names = list(tidy3d_cli.commands.keys())
assert len(command_names) == len(set(command_names))
assert "config" in tidy3d_cli.commands
assert "migrate" in tidy3d_cli.commands
assert {"configure", "convert", "develop"}.issubset(set(command_names))
assert "migrate" not in tidy3d_cli.commands


def test_config_group_commands_are_namespaced():
Expand Down
87 changes: 0 additions & 87 deletions tests/test_cli/test_migrate.py

This file was deleted.

16 changes: 12 additions & 4 deletions tidy3d/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,18 @@ def resolve_config_directory() -> Path:
)
return _temporary_config_dir()

canonical_dir = canonical_config_directory()
if _is_writable(canonical_dir.parent):
legacy_dir = legacy_config_directory()
if legacy_dir.exists():
log.warning(
f"Using canonical configuration directory at '{canonical_dir}'. "
"Found legacy directory at '~/.tidy3d', which will be ignored. "
"Remove it manually or run 'tidy3d config migrate --delete-legacy' to clean up.",
log_once=True,
)
return canonical_dir

legacy_dir = legacy_config_directory()
if legacy_dir.exists():
log.warning(
Expand All @@ -264,10 +276,6 @@ def resolve_config_directory() -> Path:
)
return legacy_dir

canonical_dir = canonical_config_directory()
if _is_writable(canonical_dir.parent):
return canonical_dir

log.warning(f"Unable to write to '{canonical_dir}'; falling back to temporary directory.")
return _temporary_config_dir()

Expand Down
3 changes: 0 additions & 3 deletions tidy3d/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
)
from .cli import tidy3d_cli
from .cli.app import configure_fn as configure
from .cli.migrate import migrate

migrate()

__all__ = [
"Batch",
Expand Down
69 changes: 35 additions & 34 deletions tidy3d/web/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from __future__ import annotations

import json
import os.path
import os
import shutil
import ssl

import click
Expand All @@ -17,8 +17,7 @@
legacy_config_directory,
migrate_legacy_config,
)
from tidy3d.web.cli.constants import CREDENTIAL_FILE, TIDY3D_DIR
from tidy3d.web.cli.migrate import migrate as migrate_authentication
from tidy3d.web.cli.constants import TIDY3D_DIR
from tidy3d.web.core.constants import HEADER_APIKEY
from tidy3d.web.core.environment import Env

Expand Down Expand Up @@ -90,15 +89,6 @@ def auth(req):
req.headers[HEADER_APIKEY] = apikey
return req

if os.path.exists(CREDENTIAL_FILE):
with open(CREDENTIAL_FILE, encoding="utf-8") as fp:
auth_json = json.load(fp)
email = auth_json["email"]
password = auth_json["password"]
if email and password:
if migrate_authentication():
return

if not apikey:
current_apikey = get_description()
message = f"Current API key: [{current_apikey}]\n" if current_apikey else ""
Expand All @@ -119,12 +109,6 @@ def auth(req):
click.echo("API key is invalid.")


@click.command(name="auth-migrate")
def migrate_command():
"""Click command to migrate the credential to api key."""
migrate_authentication()


@click.command()
@click.argument("lsf_file")
@click.argument("new_file")
Expand Down Expand Up @@ -158,20 +142,7 @@ def config_reset(yes: bool, preserve_profiles: bool) -> None:
click.echo("Configuration reset to defaults.")


@click.command(name="config-migrate")
@click.option(
"--overwrite",
is_flag=True,
help="Replace existing files in the destination configuration directory if they already exist.",
)
@click.option(
"--delete-legacy",
is_flag=True,
help="Remove the legacy '~/.tidy3d' directory after a successful migration.",
)
def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
"""Copy configuration files from '~/.tidy3d' to the canonical location."""

def _run_config_migration(overwrite: bool, delete_legacy: bool) -> None:
legacy_dir = legacy_config_directory()
if not legacy_dir.exists():
click.echo("No legacy configuration directory found at '~/.tidy3d'; nothing to migrate.")
Expand All @@ -181,6 +152,20 @@ def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
try:
destination = migrate_legacy_config(overwrite=overwrite, remove_legacy=delete_legacy)
except FileExistsError:
if delete_legacy:
try:
shutil.rmtree(legacy_dir)
except OSError as exc:
click.echo(
f"Destination '{canonical_dir}' already exists and the legacy directory "
f"could not be removed. Error: {exc}"
)
return
click.echo(
f"Destination '{canonical_dir}' already exists. "
"Skipped copying legacy files and removed the legacy '~/.tidy3d' directory."
)
return
click.echo(
f"Destination '{canonical_dir}' already exists. "
"Use '--overwrite' to replace the existing files."
Expand All @@ -203,6 +188,23 @@ def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
)


@click.command(name="config-migrate")
@click.option(
"--overwrite",
is_flag=True,
help="Replace existing files in the destination configuration directory if they already exist.",
)
@click.option(
"--delete-legacy",
is_flag=True,
help="Remove the legacy '~/.tidy3d' directory after a successful migration.",
)
def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
"""Copy configuration files from '~/.tidy3d' to the canonical location."""

_run_config_migration(overwrite, delete_legacy)


@click.group()
def config_group():
"""Configuration utilities."""
Expand All @@ -212,7 +214,6 @@ def config_group():
config_group.add_command(config_reset, name="reset")

tidy3d_cli.add_command(configure)
tidy3d_cli.add_command(migrate_command, name="migrate")
tidy3d_cli.add_command(convert)
tidy3d_cli.add_command(develop)
tidy3d_cli.add_command(config_group, name="config")
1 change: 0 additions & 1 deletion tidy3d/web/cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@

TIDY3D_DIR = str(_CONFIG_ROOT)
CONFIG_FILE = str(_CONFIG_ROOT / "config.toml")
CREDENTIAL_FILE = str(_CONFIG_ROOT / "auth.json")
102 changes: 0 additions & 102 deletions tidy3d/web/cli/migrate.py

This file was deleted.

Loading