Skip to content

Commit ba352a5

Browse files
committed
fix(web): restore legacy environment exports
1 parent 5ecb369 commit ba352a5

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

tests/config/test_legacy_env.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import ssl
5+
import warnings
56

67
from tidy3d.config import Env, get_manager, reload_config
78
from tidy3d.config import config as config_wrapper
@@ -69,3 +70,25 @@ def test_env_vars_follow_profile_switch(mock_config_dir, monkeypatch, config_man
6970
assert os.environ["TIDY3D_TEST_VAR"] == "applied"
7071
finally:
7172
reload_config(profile="default")
73+
74+
75+
def test_web_core_environment_reexports():
76+
"""Legacy `tidy3d.web.core.environment` exports remain available via config shim."""
77+
78+
import tidy3d.web as web
79+
from tidy3d.config import Env as ConfigEnv
80+
81+
environment = web.core.environment
82+
assert environment.Env is ConfigEnv
83+
84+
with warnings.catch_warnings(record=True) as caught:
85+
warnings.simplefilter("always", DeprecationWarning)
86+
dev = environment.dev
87+
uat = environment.uat
88+
89+
assert dev is ConfigEnv.dev
90+
assert uat is ConfigEnv.uat
91+
assert len(caught) == 2
92+
assert "tidy3d.web.core.environment.dev" in str(caught[0].message)
93+
assert "tidy3d.web.core.environment.uat" in str(caught[1].message)
94+
assert "2.12" in str(caught[0].message)

tidy3d/config/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def _create_manager() -> ConfigManager:
3434

3535

3636
_base_manager = _create_manager()
37+
# TODO(FXC-3827): Drop LegacyConfigWrapper once legacy accessors are removed in Tidy3D 2.12.
3738
_config_wrapper = LegacyConfigWrapper(_base_manager)
3839
config = _config_wrapper
3940

41+
# TODO(FXC-3827): Remove legacy Env exports after deprecation window (planned 2.12).
4042
Environment = LegacyEnvironment
4143
EnvironmentConfig = LegacyEnvironmentConfig
4244
Env = LegacyEnvironment(_base_manager)

tidy3d/config/legacy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from tidy3d.log import log
1818

19+
# TODO(FXC-3827): Remove LegacyConfigWrapper/Environment shims and related helpers in Tidy3D 2.12.
1920
from .manager import ConfigManager, normalize_profile_name
2021
from .profiles import BUILTIN_PROFILES
2122

@@ -26,6 +27,7 @@ def _warn_env_deprecated() -> None:
2627
log.warning(message, log_once=True)
2728

2829

30+
# TODO(FXC-3827): Delete LegacyConfigWrapper once legacy attribute access is dropped.
2931
class LegacyConfigWrapper:
3032
"""Provide attribute-level compatibility with the legacy config module."""
3133

@@ -144,6 +146,7 @@ def __str__(self) -> str:
144146
return self._manager.format()
145147

146148

149+
# TODO(FXC-3827): Delete LegacyEnvironmentConfig once profile-based Env shim is removed.
147150
class LegacyEnvironmentConfig:
148151
"""Backward compatible environment config wrapper that proxies ConfigManager."""
149152

@@ -318,6 +321,7 @@ def _value(self, key: str) -> Any:
318321
return self._web_section().get(key)
319322

320323

324+
# TODO(FXC-3827): Delete LegacyEnvironment after deprecating `tidy3d.config.Env`.
321325
class LegacyEnvironment:
322326
"""Legacy Env wrapper that maps to profiles."""
323327

tidy3d/web/core/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
"""Tidy3d core package imports"""
2+
3+
from __future__ import annotations
4+
5+
# TODO(FXC-3827): Drop this import once the legacy shim is removed in Tidy3D 2.12.
6+
from . import environment
7+
8+
__all__ = ["environment"]

tidy3d/web/core/environment.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22

33
from __future__ import annotations
44

5+
# TODO(FXC-3827): Remove this module-level legacy shim in Tidy3D 2.12.
6+
import warnings
7+
from typing import Any
8+
59
from tidy3d.config import Env, Environment, EnvironmentConfig
610

7-
__all__ = ["Env", "Environment", "EnvironmentConfig"]
11+
__all__ = [ # noqa: F822
12+
"Env",
13+
"Environment",
14+
"EnvironmentConfig",
15+
"dev",
16+
"nexus",
17+
"pre",
18+
"prod",
19+
"uat",
20+
]
21+
22+
_LEGACY_ENV_NAMES = {"dev", "uat", "pre", "prod", "nexus"}
23+
_DEPRECATION_MESSAGE = (
24+
"'tidy3d.web.core.environment.{name}' is deprecated and will be removed in "
25+
"Tidy3D 2.12. Transition to 'tidy3d.config.Env.{name}' or "
26+
"'tidy3d.config.config.switch_profile(...)'."
27+
)
28+
29+
30+
def _get_legacy_env(name: str) -> Any:
31+
warnings.warn(_DEPRECATION_MESSAGE.format(name=name), DeprecationWarning, stacklevel=2)
32+
return getattr(Env, name)
33+
34+
35+
def __getattr__(name: str) -> Any:
36+
if name in _LEGACY_ENV_NAMES:
37+
return _get_legacy_env(name)
38+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
39+
40+
41+
def __dir__() -> list[str]:
42+
return sorted(set(__all__))

tidy3d/web/environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
# TODO(FXC-3827): Remove this re-export once `tidy3d.web.environment` shim is retired in 2.12.
56
from .core.environment import Env
67

78
__all__ = ["Env"]

0 commit comments

Comments
 (0)