Skip to content

Commit 43f174f

Browse files
committed
fix: code cleanup
1 parent 6491d81 commit 43f174f

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

src/emd/commands/bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def bootstrap(
2525
):
2626
"""
2727
Manually initialize AWS resources for model deployment.
28-
28+
2929
Note: This command is optional. Running 'emd deploy' will automatically
3030
set up infrastructure when needed.
3131
"""

src/emd/utils/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ def print_aws_config():
113113
response = sts.get_caller_identity()
114114
account_id = response["Account"]
115115
region = get_current_region()
116-
116+
117117
if region is None:
118118
console.print("[yellow]warning: Unable to determine AWS region.[/yellow]")
119119
raise typer.Exit(1)
120-
120+
121121
console.print(Panel.fit(
122122
f"[bold green]Account ID:[/bold green] {account_id}\n"
123123
f"[bold green]Region :[/bold green] {region}",
@@ -136,12 +136,12 @@ def wrapper(*args, **kwargs):
136136
error_msg = str(e)
137137
logger.error(f"AWS configuration loading failed: {error_msg}")
138138
logger.debug(traceback.format_exc())
139-
139+
140140
if kwargs.get("allow_local_deploy") or kwargs.get("only_allow_local_deploy", False):
141141
logger.warning(f"AWS configuration error: {error_msg}. Proceeding with local deployment.")
142142
kwargs['only_allow_local_deploy'] = True
143143
return fn(*args, **kwargs)
144-
144+
145145
console = Console()
146146
console.print(f"[red]❌ AWS Configuration Error: {error_msg}[/red]")
147147
raise typer.Exit(1)

src/emd/utils/smart_bootstrap.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get_deployed_infrastructure_version(region: str) -> Optional[str]:
1818
try:
1919
cfn = boto3.client('cloudformation', region_name=region)
2020
stack_info = cfn.describe_stacks(StackName=ENV_STACK_NAME)['Stacks'][0]
21-
21+
2222
# Get ArtifactVersion parameter from stack
2323
for param in stack_info.get('Parameters', []):
2424
if param['ParameterKey'] == 'ArtifactVersion':
@@ -36,20 +36,20 @@ def check_infrastructure_completeness(region: str) -> Tuple[bool, str]:
3636
try:
3737
cfn = boto3.client('cloudformation', region_name=region)
3838
s3 = boto3.client('s3', region_name=region)
39-
39+
4040
# Check CloudFormation stack
4141
try:
4242
stack_info = cfn.describe_stacks(StackName=ENV_STACK_NAME)['Stacks'][0]
4343
stack_status = stack_info['StackStatus']
44-
44+
4545
if stack_status not in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']:
4646
return False, f"CloudFormation stack status: {stack_status}"
47-
47+
4848
except cfn.exceptions.ClientError as e:
4949
if "does not exist" in str(e):
5050
return False, "CloudFormation stack does not exist"
5151
raise
52-
52+
5353
# Check S3 bucket (get bucket name from stack resources)
5454
try:
5555
from emd.sdk.bootstrap import get_bucket_name
@@ -60,9 +60,9 @@ def check_infrastructure_completeness(region: str) -> Tuple[bool, str]:
6060
s3.head_bucket(Bucket=bucket_name)
6161
except Exception as e:
6262
return False, f"S3 bucket issue: {str(e)}"
63-
63+
6464
return True, "Infrastructure is complete"
65-
65+
6666
except Exception as e:
6767
logger.debug(f"Infrastructure completeness check failed: {e}")
6868
return False, f"Infrastructure check failed: {str(e)}"
@@ -71,7 +71,7 @@ def check_infrastructure_completeness(region: str) -> Tuple[bool, str]:
7171
class SmartBootstrapManager:
7272
def __init__(self):
7373
self.console = Console()
74-
74+
7575
def check_version_compatibility(self, current_version: str, deployed_version: str, region: str) -> str:
7676
"""
7777
Check version compatibility and infrastructure completeness
@@ -82,14 +82,14 @@ def check_version_compatibility(self, current_version: str, deployed_version: st
8282
if not is_complete:
8383
logger.debug(f"Infrastructure incomplete: {status_msg}")
8484
return 'auto_bootstrap' # Infrastructure missing/incomplete, need bootstrap
85-
85+
8686
if not deployed_version:
8787
return 'auto_bootstrap' # No version info, need bootstrap
88-
88+
8989
try:
9090
current_parsed = packaging.version.parse(current_version)
9191
deployed_parsed = packaging.version.parse(deployed_version)
92-
92+
9393
if current_parsed > deployed_parsed:
9494
return 'auto_bootstrap' # Local newer, auto bootstrap
9595
elif deployed_parsed > current_parsed:
@@ -99,7 +99,7 @@ def check_version_compatibility(self, current_version: str, deployed_version: st
9999
except Exception as e:
100100
logger.debug(f"Failed to parse versions: {e}")
101101
return 'auto_bootstrap' # Default to bootstrap if parsing fails
102-
102+
103103
def show_bootstrap_notification(self, current_version: str, deployed_version: str):
104104
"""Show notification about automatic bootstrap"""
105105
self.console.print() # Empty line for spacing
@@ -108,18 +108,18 @@ def show_bootstrap_notification(self, current_version: str, deployed_version: st
108108
else:
109109
self.console.print(f"🚀 [bold green]Setting up infrastructure...[/bold green] [bold green]{current_version}[/bold green]")
110110
self.console.print() # Empty line for spacing
111-
111+
112112
def show_version_mismatch_warning(self, current_version: str, deployed_version: str):
113113
"""Show warning when cloud version is newer than local version"""
114114
self.console.print() # Empty line for spacing
115115
self.console.print(f"⚠️ [bold yellow]Version mismatch:[/bold yellow] Local [dim]{current_version}[/dim] < Cloud [bold yellow]{deployed_version}[/bold yellow]")
116116
self.console.print(f" [bold]Recommendation:[/bold] pip install --upgrade easy-model-deployer")
117117
self.console.print() # Empty line for spacing
118-
118+
119119
def is_auto_bootstrap_disabled(self) -> bool:
120120
"""Check if auto bootstrap is disabled via environment variable"""
121121
return os.getenv("EMD_DISABLE_AUTO_BOOTSTRAP", "").lower() in ["true", "1", "yes"]
122-
122+
123123
def auto_bootstrap_if_needed(self, region: str) -> bool:
124124
"""
125125
Automatically run bootstrap if needed based on comprehensive infrastructure check
@@ -129,67 +129,67 @@ def auto_bootstrap_if_needed(self, region: str) -> bool:
129129
if self.is_auto_bootstrap_disabled():
130130
logger.debug("Auto bootstrap disabled via EMD_DISABLE_AUTO_BOOTSTRAP")
131131
return False
132-
132+
133133
current_version = VERSION
134134
deployed_version = get_deployed_infrastructure_version(region)
135-
135+
136136
action = self.check_version_compatibility(current_version, deployed_version, region)
137-
137+
138138
if action == 'compatible':
139139
return False # No action needed
140-
140+
141141
elif action == 'version_mismatch_warning':
142142
# Cloud version > Local version - show warning and ask user
143143
self.show_version_mismatch_warning(current_version, deployed_version)
144-
144+
145145
if not typer.confirm("Continue deployment despite version mismatch?", default=False):
146146
self.console.print("[yellow]Deployment cancelled. Please update EMD to the latest version.[/yellow]")
147147
raise typer.Exit(0)
148-
148+
149149
return False # User chose to continue, no bootstrap
150-
150+
151151
elif action == 'auto_bootstrap':
152152
# Infrastructure missing/incomplete OR version mismatch - ask for confirmation
153153
self.show_bootstrap_notification(current_version, deployed_version)
154-
154+
155155
# Ask for user confirmation
156156
if deployed_version:
157157
# Update scenario
158158
confirm_msg = f"Update infrastructure from {deployed_version} to {current_version}?"
159159
else:
160160
# Initialize scenario
161161
confirm_msg = f"Initialize EMD infrastructure for version {current_version}?"
162-
162+
163163
if not typer.confirm(confirm_msg, default=True):
164164
self.console.print("[yellow]Bootstrap cancelled. Infrastructure will not be updated.[/yellow]")
165165
self.console.print("[red]Deployment cannot proceed without compatible infrastructure.[/red]")
166166
raise typer.Exit(1)
167-
167+
168168
# User confirmed - proceed with bootstrap
169169
try:
170170
from emd.sdk.bootstrap import create_env_stack, get_bucket_name
171-
171+
172172
bucket_name = get_bucket_name(
173173
bucket_prefix=ENV_BUCKET_NAME_PREFIX,
174174
region=region
175175
)
176-
176+
177177
create_env_stack(
178178
region=region,
179179
stack_name=ENV_STACK_NAME,
180180
bucket_name=bucket_name,
181181
force_update=True
182182
)
183-
183+
184184
self.console.print("[bold green]✅ Infrastructure setup completed successfully![/bold green]")
185185
return True
186-
186+
187187
except Exception as e:
188188
self.console.print(f"[bold red]❌ Infrastructure setup failed: {str(e)}[/bold red]")
189189
raise typer.Exit(1)
190-
190+
191191
return False
192192

193193

194194
# Global instance
195-
smart_bootstrap_manager = SmartBootstrapManager()
195+
smart_bootstrap_manager = SmartBootstrapManager()

src/emd/utils/update_notifier.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ def __init__(self):
1818
self.console = Console()
1919
self.cache_file = Path.home() / ".emd_update_cache.json"
2020
self.cache_duration = 3600 # 1 hour cache
21-
21+
2222
def is_development_mode(self) -> bool:
2323
"""Check if running in development mode"""
2424
return VERSION == "0.0.0"
25-
25+
2626
def should_check_updates(self) -> bool:
2727
"""Determine if we should check for updates"""
2828
# Skip in development mode
2929
if self.is_development_mode():
3030
return False
31-
31+
3232
# Skip if user disabled checks
3333
if os.getenv("EMD_DISABLE_UPDATE_CHECK", "").lower() in ["true", "1", "yes"]:
3434
return False
35-
35+
3636
return True
37-
37+
3838
def get_cached_version_info(self) -> Optional[Dict[str, Any]]:
3939
"""Get cached version information"""
4040
try:
@@ -46,7 +46,7 @@ def get_cached_version_info(self) -> Optional[Dict[str, Any]]:
4646
except Exception as e:
4747
logger.debug(f"Failed to read update cache: {e}")
4848
return None
49-
49+
5050
def cache_version_info(self, latest_version: str, has_update: bool):
5151
"""Cache version information"""
5252
try:
@@ -60,30 +60,30 @@ def cache_version_info(self, latest_version: str, has_update: bool):
6060
json.dump(data, f)
6161
except Exception as e:
6262
logger.debug(f"Failed to write update cache: {e}")
63-
63+
6464
def fetch_latest_version(self) -> Optional[str]:
6565
"""Fetch latest version from PyPI"""
6666
try:
6767
response = requests.get(
68-
"https://pypi.org/pypi/easy-model-deployer/json",
68+
"https://pypi.org/pypi/easy-model-deployer/json",
6969
timeout=2 # Quick timeout to avoid blocking
7070
)
7171
if response.status_code == 200:
7272
return response.json()["info"]["version"]
7373
except Exception as e:
7474
logger.debug(f"Failed to fetch latest version: {e}")
7575
return None
76-
76+
7777
def check_for_updates(self) -> Tuple[bool, Optional[str]]:
7878
"""Check if updates are available with caching"""
7979
if not self.should_check_updates():
8080
return False, None
81-
81+
8282
# Try cache first
8383
cached = self.get_cached_version_info()
8484
if cached and cached.get('current_version') == VERSION:
8585
return cached['has_update'], cached.get('latest_version')
86-
86+
8787
# Fetch from PyPI
8888
latest = self.fetch_latest_version()
8989
if latest:
@@ -93,14 +93,14 @@ def check_for_updates(self) -> Tuple[bool, Optional[str]]:
9393
return has_update, latest
9494
except Exception as e:
9595
logger.debug(f"Failed to parse versions: {e}")
96-
96+
9797
return False, None
98-
98+
9999
def show_update_notification(self):
100100
"""Display update notification if available"""
101101
try:
102102
has_update, latest_version = self.check_for_updates()
103-
103+
104104
if has_update and latest_version:
105105
# Display simple colored message
106106
self.console.print() # Empty line for spacing
@@ -113,4 +113,4 @@ def show_update_notification(self):
113113

114114

115115
# Global instance
116-
update_notifier = UpdateNotifier()
116+
update_notifier = UpdateNotifier()

0 commit comments

Comments
 (0)