44
55import os
66import ssl
7+ from typing import Optional
78
89from pydantic .v1 import BaseSettings , Field
910
@@ -21,8 +22,9 @@ def __hash__(self):
2122 website_endpoint : str
2223 s3_region : str
2324 ssl_verify : bool = Field (True , env = "TIDY3D_SSL_VERIFY" )
24- enable_caching : bool = None
25- ssl_version : ssl .TLSVersion = None
25+ enable_caching : Optional [bool ] = None
26+ ssl_version : Optional [ssl .TLSVersion ] = None
27+ env_vars : Optional [dict [str , str ]] = None
2628
2729 def active (self ) -> None :
2830 """Activate the environment instance."""
@@ -73,6 +75,17 @@ def get_real_url(self, path: str) -> str:
7375)
7476
7577
78+ nexus = EnvironmentConfig (
79+ name = "nexus" ,
80+ web_api_endpoint = "http://127.0.0.1:5000" ,
81+ ssl_verify = False ,
82+ enable_caching = False ,
83+ s3_region = "us-east-1" ,
84+ website_endpoint = "http://127.0.0.1/tidy3d" ,
85+ env_vars = {"AWS_ENDPOINT_URL_S3" : "http://127.0.0.1:9000" },
86+ )
87+
88+
7689class Environment :
7790 """Environment decorator for user interactive.
7891
@@ -88,11 +101,13 @@ class Environment:
88101 "dev" : dev ,
89102 "uat" : uat ,
90103 "prod" : prod ,
104+ "nexus" : nexus ,
91105 }
92106
93107 def __init__ (self ):
94108 log = get_logger ()
95109 """Initialize the environment."""
110+ self ._previous_env_vars = {}
96111 env_key = os .environ .get ("TIDY3D_ENV" )
97112 env_key = env_key .lower () if env_key else env_key
98113 log .info (f"env_key is { env_key } " )
@@ -107,6 +122,11 @@ def __init__(self):
107122 )
108123 self ._current = prod
109124
125+ if self ._current .env_vars :
126+ for key , value in self ._current .env_vars .items ():
127+ self ._previous_env_vars [key ] = os .environ .get (key )
128+ os .environ [key ] = value
129+
110130 @property
111131 def current (self ) -> EnvironmentConfig :
112132 """Get the current environment.
@@ -162,6 +182,17 @@ def prod(self) -> EnvironmentConfig:
162182 """
163183 return prod
164184
185+ @property
186+ def nexus (self ) -> EnvironmentConfig :
187+ """Get the nexus environment.
188+
189+ Returns
190+ -------
191+ EnvironmentConfig
192+ The config for the nexus environment.
193+ """
194+ return nexus
195+
165196 def set_current (self , config : EnvironmentConfig ) -> None :
166197 """Set the current environment.
167198
@@ -170,6 +201,19 @@ def set_current(self, config: EnvironmentConfig) -> None:
170201 config : EnvironmentConfig
171202 The environment to set to current.
172203 """
204+ for key , value in self ._previous_env_vars .items ():
205+ if value is None :
206+ if key in os .environ :
207+ del os .environ [key ]
208+ else :
209+ os .environ [key ] = value
210+ self ._previous_env_vars = {}
211+
212+ if config .env_vars :
213+ for key , value in config .env_vars .items ():
214+ self ._previous_env_vars [key ] = os .environ .get (key )
215+ os .environ [key ] = value
216+
173217 self ._current = config
174218
175219 def enable_caching (self , enable_caching : bool = True ) -> None :
0 commit comments