Skip to content

Commit b92986e

Browse files
bmehta001Copilot
andcommitted
Address Copilot PR review feedback
- JS: Make progressCallback required (not optional) in downloadAndRegisterEpsWithProgress - C#: Guard null/empty result.Data in DiscoverEpsImpl before deserializing - Python: Use Callable[[str, float], None] instead of built-in callable - Rust README: Fix closure to use move + Arc<Mutex> for Send + 'static Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 449bed0 commit b92986e

4 files changed

Lines changed: 26 additions & 18 deletions

File tree

sdk/cs/src/FoundryLocalManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,13 @@ private EpInfo[] DiscoverEpsImpl()
234234
throw new FoundryLocalException($"Error discovering execution providers: {result.Error}", _logger);
235235
}
236236

237-
return JsonSerializer.Deserialize(result.Data!, JsonSerializationContext.Default.EpInfoArray)
237+
var data = result.Data;
238+
if (string.IsNullOrWhiteSpace(data))
239+
{
240+
return Array.Empty<EpInfo>();
241+
}
242+
243+
return JsonSerializer.Deserialize(data, JsonSerializationContext.Default.EpInfoArray)
238244
?? Array.Empty<EpInfo>();
239245
}
240246

sdk/js/src/foundryLocalManager.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ export class FoundryLocalManager {
182182
* @returns A promise that resolves when all downloads complete.
183183
*/
184184
public async downloadAndRegisterEpsWithProgress(
185-
names?: string[],
186-
progressCallback?: (epName: string, percent: number) => void
185+
names: string[] | undefined,
186+
progressCallback: (epName: string, percent: number) => void
187187
): Promise<void> {
188188
const params: { Params?: { Names: string } } = {};
189189
if (names && names.length > 0) {
@@ -194,14 +194,12 @@ export class FoundryLocalManager {
194194
"download_and_register_eps",
195195
Object.keys(params).length > 0 ? params : undefined,
196196
(chunk: string) => {
197-
if (progressCallback) {
198-
const sepIndex = chunk.indexOf('|');
199-
if (sepIndex >= 0) {
200-
const epName = chunk.substring(0, sepIndex);
201-
const percent = parseFloat(chunk.substring(sepIndex + 1));
202-
if (!isNaN(percent)) {
203-
progressCallback(epName || '', percent);
204-
}
197+
const sepIndex = chunk.indexOf('|');
198+
if (sepIndex >= 0) {
199+
const epName = chunk.substring(0, sepIndex);
200+
const percent = parseFloat(chunk.substring(sepIndex + 1));
201+
if (!isNaN(percent)) {
202+
progressCallback(epName || '', percent);
205203
}
206204
}
207205
}

sdk/python/src/foundry_local_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import logging
1010
import threading
1111

12-
from typing import Optional
12+
from typing import Callable, Optional
1313

1414
from .catalog import Catalog
1515
from .configuration import Configuration
@@ -98,7 +98,7 @@ def discover_eps(self) -> list[EpInfo]:
9898
def download_and_register_eps(
9999
self,
100100
names: Optional[list[str]] = None,
101-
progress_callback: Optional[callable] = None,
101+
progress_callback: Optional[Callable[[str, float], None]] = None,
102102
) -> Optional[EpDownloadResult]:
103103
"""Download and register execution providers (blocking).
104104

sdk/rust/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,15 @@ Use `download_and_register_eps_with_progress` to receive typed `(ep_name, percen
8989
as each EP downloads (`percent` is 0.0–100.0):
9090

9191
```rust
92-
let mut current_ep = String::new();
93-
manager.download_and_register_eps_with_progress(None, |ep_name, percent| {
94-
if ep_name != current_ep {
95-
if !current_ep.is_empty() { println!(); }
96-
current_ep = ep_name.to_string();
92+
use std::sync::{Arc, Mutex};
93+
94+
let current_ep = Arc::new(Mutex::new(String::new()));
95+
let ep = Arc::clone(&current_ep);
96+
manager.download_and_register_eps_with_progress(None, move |ep_name, percent| {
97+
let mut current = ep.lock().unwrap();
98+
if ep_name != current.as_str() {
99+
if !current.is_empty() { println!(); }
100+
*current = ep_name.to_string();
97101
}
98102
print!("\r {} {:5.1}%", ep_name, percent);
99103
if percent >= 100.0 { println!(); }

0 commit comments

Comments
 (0)