Skip to content

Commit 0ed42f3

Browse files
committed
chore(cli): remove unusued api key migration and improve config migration UX
1 parent 37291fd commit 0ed42f3

File tree

7 files changed

+49
-232
lines changed

7 files changed

+49
-232
lines changed

tests/test_cli/test_commands.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def test_tidy3d_root_command_names_are_unique():
1313
command_names = list(tidy3d_cli.commands.keys())
1414
assert len(command_names) == len(set(command_names))
1515
assert "config" in tidy3d_cli.commands
16-
assert "migrate" in tidy3d_cli.commands
16+
assert {"configure", "convert", "develop"}.issubset(set(command_names))
17+
assert "migrate" not in tidy3d_cli.commands
1718

1819

1920
def test_config_group_commands_are_namespaced():

tests/test_cli/test_migrate.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

tidy3d/config/loader.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ def resolve_config_directory() -> Path:
256256
)
257257
return _temporary_config_dir()
258258

259+
canonical_dir = canonical_config_directory()
260+
if _is_writable(canonical_dir.parent):
261+
legacy_dir = legacy_config_directory()
262+
if legacy_dir.exists():
263+
log.warning(
264+
f"Using canonical configuration directory at '{canonical_dir}'. "
265+
"Found legacy directory at '~/.tidy3d', which will be ignored. "
266+
"Remove it manually or run 'tidy3d config migrate --delete-legacy' to clean up.",
267+
log_once=True,
268+
)
269+
return canonical_dir
270+
259271
legacy_dir = legacy_config_directory()
260272
if legacy_dir.exists():
261273
log.warning(
@@ -264,10 +276,6 @@ def resolve_config_directory() -> Path:
264276
)
265277
return legacy_dir
266278

267-
canonical_dir = canonical_config_directory()
268-
if _is_writable(canonical_dir.parent):
269-
return canonical_dir
270-
271279
log.warning(f"Unable to write to '{canonical_dir}'; falling back to temporary directory.")
272280
return _temporary_config_dir()
273281

tidy3d/web/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
)
4040
from .cli import tidy3d_cli
4141
from .cli.app import configure_fn as configure
42-
from .cli.migrate import migrate
43-
44-
migrate()
4542

4643
__all__ = [
4744
"Batch",

tidy3d/web/cli/app.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from __future__ import annotations
66

7-
import json
8-
import os.path
7+
import os
8+
import shutil
99
import ssl
1010

1111
import click
@@ -17,8 +17,7 @@
1717
legacy_config_directory,
1818
migrate_legacy_config,
1919
)
20-
from tidy3d.web.cli.constants import CREDENTIAL_FILE, TIDY3D_DIR
21-
from tidy3d.web.cli.migrate import migrate as migrate_authentication
20+
from tidy3d.web.cli.constants import TIDY3D_DIR
2221
from tidy3d.web.core.constants import HEADER_APIKEY
2322
from tidy3d.web.core.environment import Env
2423

@@ -90,15 +89,6 @@ def auth(req):
9089
req.headers[HEADER_APIKEY] = apikey
9190
return req
9291

93-
if os.path.exists(CREDENTIAL_FILE):
94-
with open(CREDENTIAL_FILE, encoding="utf-8") as fp:
95-
auth_json = json.load(fp)
96-
email = auth_json["email"]
97-
password = auth_json["password"]
98-
if email and password:
99-
if migrate_authentication():
100-
return
101-
10292
if not apikey:
10393
current_apikey = get_description()
10494
message = f"Current API key: [{current_apikey}]\n" if current_apikey else ""
@@ -119,12 +109,6 @@ def auth(req):
119109
click.echo("API key is invalid.")
120110

121111

122-
@click.command(name="auth-migrate")
123-
def migrate_command():
124-
"""Click command to migrate the credential to api key."""
125-
migrate_authentication()
126-
127-
128112
@click.command()
129113
@click.argument("lsf_file")
130114
@click.argument("new_file")
@@ -158,20 +142,7 @@ def config_reset(yes: bool, preserve_profiles: bool) -> None:
158142
click.echo("Configuration reset to defaults.")
159143

160144

161-
@click.command(name="config-migrate")
162-
@click.option(
163-
"--overwrite",
164-
is_flag=True,
165-
help="Replace existing files in the destination configuration directory if they already exist.",
166-
)
167-
@click.option(
168-
"--delete-legacy",
169-
is_flag=True,
170-
help="Remove the legacy '~/.tidy3d' directory after a successful migration.",
171-
)
172-
def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
173-
"""Copy configuration files from '~/.tidy3d' to the canonical location."""
174-
145+
def _run_config_migration(overwrite: bool, delete_legacy: bool) -> None:
175146
legacy_dir = legacy_config_directory()
176147
if not legacy_dir.exists():
177148
click.echo("No legacy configuration directory found at '~/.tidy3d'; nothing to migrate.")
@@ -181,6 +152,20 @@ def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
181152
try:
182153
destination = migrate_legacy_config(overwrite=overwrite, remove_legacy=delete_legacy)
183154
except FileExistsError:
155+
if delete_legacy:
156+
try:
157+
shutil.rmtree(legacy_dir)
158+
except OSError as exc:
159+
click.echo(
160+
f"Destination '{canonical_dir}' already exists and the legacy directory "
161+
f"could not be removed. Error: {exc}"
162+
)
163+
return
164+
click.echo(
165+
f"Destination '{canonical_dir}' already exists. "
166+
"Skipped copying legacy files and removed the legacy '~/.tidy3d' directory."
167+
)
168+
return
184169
click.echo(
185170
f"Destination '{canonical_dir}' already exists. "
186171
"Use '--overwrite' to replace the existing files."
@@ -203,6 +188,23 @@ def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
203188
)
204189

205190

191+
@click.command(name="config-migrate")
192+
@click.option(
193+
"--overwrite",
194+
is_flag=True,
195+
help="Replace existing files in the destination configuration directory if they already exist.",
196+
)
197+
@click.option(
198+
"--delete-legacy",
199+
is_flag=True,
200+
help="Remove the legacy '~/.tidy3d' directory after a successful migration.",
201+
)
202+
def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
203+
"""Copy configuration files from '~/.tidy3d' to the canonical location."""
204+
205+
_run_config_migration(overwrite, delete_legacy)
206+
207+
206208
@click.group()
207209
def config_group():
208210
"""Configuration utilities."""
@@ -212,7 +214,6 @@ def config_group():
212214
config_group.add_command(config_reset, name="reset")
213215

214216
tidy3d_cli.add_command(configure)
215-
tidy3d_cli.add_command(migrate_command, name="migrate")
216217
tidy3d_cli.add_command(convert)
217218
tidy3d_cli.add_command(develop)
218219
tidy3d_cli.add_command(config_group, name="config")

tidy3d/web/cli/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88

99
TIDY3D_DIR = str(_CONFIG_ROOT)
1010
CONFIG_FILE = str(_CONFIG_ROOT / "config.toml")
11-
CREDENTIAL_FILE = str(_CONFIG_ROOT / "auth.json")

tidy3d/web/cli/migrate.py

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)