Skip to content

Commit cca8809

Browse files
yeldarbyclaude
andcommitted
fix(cli): extend suppress_sdk_output scope for image upload and version download
Wrap all SDK calls (including single_upload, upload_dataset, versions, download) inside suppress_sdk_output context to prevent "loading..." noise from corrupting --json output. Also consolidate try/except to catch errors from SDK operations, not just initialization. 256 tests pass, all linting clean. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a8203a1 commit cca8809

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

roboflow/cli/handlers/image.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,23 @@ def _handle_upload_directory(args: argparse.Namespace, api_key: str, path: str)
102102
import roboflow
103103
from roboflow.cli._output import suppress_sdk_output
104104

105+
retries = getattr(args, "retries", None) or getattr(args, "num_retries", 0) or 0
106+
105107
with suppress_sdk_output(args):
106108
try:
107109
rf = roboflow.Roboflow(api_key)
108110
workspace = rf.workspace(args.workspace)
111+
workspace.upload_dataset(
112+
dataset_path=path,
113+
project_name=args.project,
114+
num_workers=args.concurrency,
115+
batch_name=getattr(args, "batch", None),
116+
num_retries=retries,
117+
)
109118
except Exception as exc:
110119
output_error(args, str(exc), exit_code=3)
111120
return
112121

113-
retries = getattr(args, "retries", None) or getattr(args, "num_retries", 0) or 0
114-
115-
try:
116-
workspace.upload_dataset(
117-
dataset_path=path,
118-
project_name=args.project,
119-
num_workers=args.concurrency,
120-
batch_name=getattr(args, "batch", None),
121-
num_retries=retries,
122-
)
123-
except Exception as exc:
124-
output_error(args, str(exc))
125-
return
126-
127122
# Count files uploaded (approximate via image extensions)
128123
count = 0
129124
image_exts = {".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff", ".webp"}

roboflow/cli/handlers/version.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,27 @@ def _download(args: argparse.Namespace) -> None:
172172
try:
173173
rf = roboflow.Roboflow()
174174
project = rf.workspace(w).project(p)
175+
176+
if not v:
177+
versions = project.versions()
178+
if not versions:
179+
output_error(args, f"Project {p} does not have any versions.")
180+
return
181+
version_obj = versions[-1]
182+
else:
183+
version_obj = project.version(int(v))
184+
185+
version_obj.download(args.format, location=args.location, overwrite=True)
186+
except SystemExit:
187+
raise
175188
except Exception as exc:
176189
output_error(args, str(exc), exit_code=3)
177190
return
178191

179-
if not v:
180-
versions = project.versions()
181-
if not versions:
182-
output_error(args, f"Project {p} does not have any versions.")
183-
return
184-
version = versions[-1]
185-
else:
186-
version = project.version(int(v))
187-
188-
version.download(args.format, location=args.location, overwrite=True)
189-
190192
data = {
191193
"workspace": w,
192194
"project": p,
193-
"version": int(v) if v else version.version,
195+
"version": int(v) if v else version_obj.version,
194196
"format": args.format,
195197
"location": args.location or "",
196198
}

0 commit comments

Comments
 (0)