recce-cloud-nightly 1.27.0.20251130__py3-none-any.whl → 1.31.0.20260101__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of recce-cloud-nightly might be problematic. Click here for more details.
- recce_cloud/.gitignore +22 -0
- recce_cloud/PKG-INFO +801 -0
- recce_cloud/README.md +780 -0
- recce_cloud/VERSION +1 -1
- recce_cloud/api/base.py +21 -0
- recce_cloud/api/client.py +36 -0
- recce_cloud/api/github.py +30 -0
- recce_cloud/api/gitlab.py +29 -0
- recce_cloud/cli.py +189 -0
- recce_cloud/download.py +230 -0
- recce_cloud/hatch_build.py +20 -0
- recce_cloud/pyproject.toml +49 -0
- recce_cloud/pyproject.toml.bak +49 -0
- recce_cloud_nightly-1.31.0.20260101.dist-info/METADATA +801 -0
- recce_cloud_nightly-1.31.0.20260101.dist-info/RECORD +28 -0
- {recce_cloud_nightly-1.27.0.20251130.dist-info → recce_cloud_nightly-1.31.0.20260101.dist-info}/WHEEL +1 -2
- recce_cloud_nightly-1.27.0.20251130.dist-info/METADATA +0 -163
- recce_cloud_nightly-1.27.0.20251130.dist-info/RECORD +0 -23
- recce_cloud_nightly-1.27.0.20251130.dist-info/licenses/LICENSE +0 -201
- recce_cloud_nightly-1.27.0.20251130.dist-info/top_level.txt +0 -1
- {recce_cloud_nightly-1.27.0.20251130.dist-info → recce_cloud_nightly-1.31.0.20260101.dist-info}/entry_points.txt +0 -0
recce_cloud/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.31.0.20260101
|
recce_cloud/api/base.py
CHANGED
|
@@ -109,3 +109,24 @@ class BaseRecceCloudClient(ABC):
|
|
|
109
109
|
Empty dictionary or acknowledgement
|
|
110
110
|
"""
|
|
111
111
|
pass
|
|
112
|
+
|
|
113
|
+
@abstractmethod
|
|
114
|
+
def get_session_download_urls(
|
|
115
|
+
self,
|
|
116
|
+
cr_number: Optional[int] = None,
|
|
117
|
+
session_type: Optional[str] = None,
|
|
118
|
+
) -> Dict:
|
|
119
|
+
"""
|
|
120
|
+
Get download URLs for artifacts from a session.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
cr_number: Change request number (PR/MR number) for CR sessions
|
|
124
|
+
session_type: Session type ("cr", "prod", "dev")
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
Dictionary containing:
|
|
128
|
+
- session_id: Session ID
|
|
129
|
+
- manifest_url: Presigned URL for manifest.json download
|
|
130
|
+
- catalog_url: Presigned URL for catalog.json download
|
|
131
|
+
"""
|
|
132
|
+
pass
|
recce_cloud/api/client.py
CHANGED
|
@@ -121,6 +121,42 @@ class RecceCloudClient:
|
|
|
121
121
|
presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
|
|
122
122
|
return presigned_urls
|
|
123
123
|
|
|
124
|
+
def get_download_urls_by_session_id(self, org_id: str, project_id: str, session_id: str) -> dict:
|
|
125
|
+
"""
|
|
126
|
+
Get presigned S3 download URLs for a session.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
org_id: Organization ID
|
|
130
|
+
project_id: Project ID
|
|
131
|
+
session_id: Session ID
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
dict with keys:
|
|
135
|
+
- manifest_url: Presigned URL for downloading manifest.json
|
|
136
|
+
- catalog_url: Presigned URL for downloading catalog.json
|
|
137
|
+
|
|
138
|
+
Raises:
|
|
139
|
+
RecceCloudException: If the request fails
|
|
140
|
+
"""
|
|
141
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/download-url"
|
|
142
|
+
response = self._request("GET", api_url)
|
|
143
|
+
if response.status_code != 200:
|
|
144
|
+
raise RecceCloudException(
|
|
145
|
+
reason=response.text,
|
|
146
|
+
status_code=response.status_code,
|
|
147
|
+
)
|
|
148
|
+
data = response.json()
|
|
149
|
+
if data["presigned_urls"] is None:
|
|
150
|
+
raise RecceCloudException(
|
|
151
|
+
reason="No presigned URLs returned from the server.",
|
|
152
|
+
status_code=404,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
presigned_urls = data["presigned_urls"]
|
|
156
|
+
for key, url in presigned_urls.items():
|
|
157
|
+
presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
|
|
158
|
+
return presigned_urls
|
|
159
|
+
|
|
124
160
|
def update_session(self, org_id: str, project_id: str, session_id: str, adapter_type: str) -> dict:
|
|
125
161
|
"""
|
|
126
162
|
Update session metadata with adapter type.
|
recce_cloud/api/github.py
CHANGED
|
@@ -27,6 +27,7 @@ class GitHubRecceCloudClient(BaseRecceCloudClient):
|
|
|
27
27
|
branch: str,
|
|
28
28
|
adapter_type: str,
|
|
29
29
|
cr_number: Optional[int] = None,
|
|
30
|
+
commit_sha: Optional[str] = None,
|
|
30
31
|
session_type: Optional[str] = None,
|
|
31
32
|
) -> Dict:
|
|
32
33
|
"""
|
|
@@ -74,3 +75,32 @@ class GitHubRecceCloudClient(BaseRecceCloudClient):
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
return self._make_request("POST", url, json=payload)
|
|
78
|
+
|
|
79
|
+
def get_session_download_urls(
|
|
80
|
+
self,
|
|
81
|
+
cr_number: Optional[int] = None,
|
|
82
|
+
session_type: Optional[str] = None,
|
|
83
|
+
) -> Dict:
|
|
84
|
+
"""
|
|
85
|
+
Get download URLs for artifacts from a GitHub session.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
cr_number: PR number for pull request sessions
|
|
89
|
+
session_type: Session type ("cr", "prod", "dev")
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
Dictionary containing session_id, manifest_url, catalog_url
|
|
93
|
+
"""
|
|
94
|
+
url = f"{self.api_host}/api/v2/github/{self.repository}/session-download-url"
|
|
95
|
+
|
|
96
|
+
# Build query parameters
|
|
97
|
+
params = {}
|
|
98
|
+
|
|
99
|
+
# For prod session, set base=true
|
|
100
|
+
if session_type == "prod":
|
|
101
|
+
params["base"] = "true"
|
|
102
|
+
# For CR session, include pr_number
|
|
103
|
+
elif session_type == "cr" and cr_number is not None:
|
|
104
|
+
params["pr_number"] = cr_number
|
|
105
|
+
|
|
106
|
+
return self._make_request("GET", url, params=params)
|
recce_cloud/api/gitlab.py
CHANGED
|
@@ -80,3 +80,32 @@ class GitLabRecceCloudClient(BaseRecceCloudClient):
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
return self._make_request("POST", url, json=payload)
|
|
83
|
+
|
|
84
|
+
def get_session_download_urls(
|
|
85
|
+
self,
|
|
86
|
+
cr_number: Optional[int] = None,
|
|
87
|
+
session_type: Optional[str] = None,
|
|
88
|
+
) -> Dict:
|
|
89
|
+
"""
|
|
90
|
+
Get download URLs for artifacts from a GitLab session.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
cr_number: MR IID for merge request sessions
|
|
94
|
+
session_type: Session type ("cr", "prod", "dev")
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
Dictionary containing session_id, manifest_url, catalog_url
|
|
98
|
+
"""
|
|
99
|
+
url = f"{self.api_host}/api/v2/gitlab/{self.project_path}/session-download-url"
|
|
100
|
+
|
|
101
|
+
# Build query parameters
|
|
102
|
+
params = {}
|
|
103
|
+
|
|
104
|
+
# For prod session, set base=true
|
|
105
|
+
if session_type == "prod":
|
|
106
|
+
params["base"] = "true"
|
|
107
|
+
# For CR session, include mr_iid
|
|
108
|
+
elif session_type == "cr" and cr_number is not None:
|
|
109
|
+
params["mr_iid"] = cr_number
|
|
110
|
+
|
|
111
|
+
return self._make_request("GET", url, params=params)
|
recce_cloud/cli.py
CHANGED
|
@@ -14,6 +14,10 @@ from rich.logging import RichHandler
|
|
|
14
14
|
from recce_cloud import __version__
|
|
15
15
|
from recce_cloud.artifact import get_adapter_type, verify_artifacts_path
|
|
16
16
|
from recce_cloud.ci_providers import CIDetector
|
|
17
|
+
from recce_cloud.download import (
|
|
18
|
+
download_from_existing_session,
|
|
19
|
+
download_with_platform_apis,
|
|
20
|
+
)
|
|
17
21
|
from recce_cloud.upload import upload_to_existing_session, upload_with_platform_apis
|
|
18
22
|
|
|
19
23
|
# Configure logging
|
|
@@ -241,5 +245,190 @@ def upload(target_path, session_id, cr, session_type, dry_run):
|
|
|
241
245
|
upload_with_platform_apis(console, token, ci_info, manifest_path, catalog_path, adapter_type, target_path)
|
|
242
246
|
|
|
243
247
|
|
|
248
|
+
@cloud_cli.command()
|
|
249
|
+
@click.option(
|
|
250
|
+
"--target-path",
|
|
251
|
+
type=click.Path(),
|
|
252
|
+
default="target",
|
|
253
|
+
help="Path to directory where artifacts will be downloaded (default: 'target')",
|
|
254
|
+
)
|
|
255
|
+
@click.option(
|
|
256
|
+
"--session-id",
|
|
257
|
+
envvar="RECCE_SESSION_ID",
|
|
258
|
+
help="Recce Cloud session ID to download artifacts from (or use RECCE_SESSION_ID env var). "
|
|
259
|
+
"If not provided, session will be found automatically using platform-specific APIs (GitHub/GitLab).",
|
|
260
|
+
)
|
|
261
|
+
@click.option(
|
|
262
|
+
"--prod",
|
|
263
|
+
is_flag=True,
|
|
264
|
+
help="Download production/base session instead of PR/MR session",
|
|
265
|
+
)
|
|
266
|
+
@click.option(
|
|
267
|
+
"--dry-run",
|
|
268
|
+
is_flag=True,
|
|
269
|
+
help="Show what would be downloaded without actually downloading",
|
|
270
|
+
)
|
|
271
|
+
@click.option(
|
|
272
|
+
"--force",
|
|
273
|
+
"-f",
|
|
274
|
+
is_flag=True,
|
|
275
|
+
help="Overwrite existing files without prompting",
|
|
276
|
+
)
|
|
277
|
+
def download(target_path, session_id, prod, dry_run, force):
|
|
278
|
+
"""
|
|
279
|
+
Download dbt artifacts (manifest.json, catalog.json) from Recce Cloud.
|
|
280
|
+
|
|
281
|
+
\b
|
|
282
|
+
Authentication (auto-detected):
|
|
283
|
+
- RECCE_API_TOKEN (for --session-id workflow)
|
|
284
|
+
- GITHUB_TOKEN (GitHub Actions)
|
|
285
|
+
- CI_JOB_TOKEN (GitLab CI)
|
|
286
|
+
|
|
287
|
+
\b
|
|
288
|
+
Common Examples:
|
|
289
|
+
# Auto-find and download current PR/MR session
|
|
290
|
+
recce-cloud download
|
|
291
|
+
|
|
292
|
+
# Download project's production/base session
|
|
293
|
+
recce-cloud download --prod
|
|
294
|
+
|
|
295
|
+
# Download from specific session ID
|
|
296
|
+
recce-cloud download --session-id abc123
|
|
297
|
+
|
|
298
|
+
# Download prod session to target-base
|
|
299
|
+
recce-cloud download --prod --target-path target-base
|
|
300
|
+
|
|
301
|
+
# Force overwrite existing files
|
|
302
|
+
recce-cloud download --force
|
|
303
|
+
"""
|
|
304
|
+
console = Console()
|
|
305
|
+
|
|
306
|
+
# Validate flag combinations
|
|
307
|
+
if session_id and prod:
|
|
308
|
+
console.print("[yellow]Warning:[/yellow] --prod is ignored when --session-id is provided")
|
|
309
|
+
|
|
310
|
+
# Determine session type from --prod flag
|
|
311
|
+
session_type = "prod" if prod else None
|
|
312
|
+
|
|
313
|
+
# 1. Auto-detect CI environment information
|
|
314
|
+
console.rule("CI Environment Detection", style="blue")
|
|
315
|
+
try:
|
|
316
|
+
ci_info = CIDetector.detect()
|
|
317
|
+
ci_info = CIDetector.apply_overrides(ci_info, session_type=session_type)
|
|
318
|
+
|
|
319
|
+
# Display detected CI information immediately
|
|
320
|
+
if ci_info:
|
|
321
|
+
info_table = []
|
|
322
|
+
if ci_info.platform:
|
|
323
|
+
info_table.append(f"[cyan]Platform:[/cyan] {ci_info.platform}")
|
|
324
|
+
|
|
325
|
+
if ci_info.repository:
|
|
326
|
+
info_table.append(f"[cyan]Repository:[/cyan] {ci_info.repository}")
|
|
327
|
+
|
|
328
|
+
if ci_info.session_type:
|
|
329
|
+
info_table.append(f"[cyan]Session Type:[/cyan] {ci_info.session_type}")
|
|
330
|
+
|
|
331
|
+
# Only show CR number and URL for CR sessions (not for prod)
|
|
332
|
+
if ci_info.session_type == "cr" and ci_info.cr_number is not None:
|
|
333
|
+
if ci_info.platform == "github-actions":
|
|
334
|
+
info_table.append(f"[cyan]PR Number:[/cyan] {ci_info.cr_number}")
|
|
335
|
+
elif ci_info.platform == "gitlab-ci":
|
|
336
|
+
info_table.append(f"[cyan]MR Number:[/cyan] {ci_info.cr_number}")
|
|
337
|
+
else:
|
|
338
|
+
info_table.append(f"[cyan]CR Number:[/cyan] {ci_info.cr_number}")
|
|
339
|
+
|
|
340
|
+
# Only show CR URL for CR sessions
|
|
341
|
+
if ci_info.session_type == "cr" and ci_info.cr_url:
|
|
342
|
+
if ci_info.platform == "github-actions":
|
|
343
|
+
info_table.append(f"[cyan]PR URL:[/cyan] {ci_info.cr_url}")
|
|
344
|
+
elif ci_info.platform == "gitlab-ci":
|
|
345
|
+
info_table.append(f"[cyan]MR URL:[/cyan] {ci_info.cr_url}")
|
|
346
|
+
else:
|
|
347
|
+
info_table.append(f"[cyan]CR URL:[/cyan] {ci_info.cr_url}")
|
|
348
|
+
|
|
349
|
+
for line in info_table:
|
|
350
|
+
console.print(line)
|
|
351
|
+
else:
|
|
352
|
+
console.print("[yellow]No CI environment detected[/yellow]")
|
|
353
|
+
except Exception as e:
|
|
354
|
+
console.print(f"[yellow]Warning:[/yellow] Failed to detect CI environment: {e}")
|
|
355
|
+
console.print("Continuing without CI metadata...")
|
|
356
|
+
ci_info = None
|
|
357
|
+
|
|
358
|
+
# 2. Handle dry-run mode (before authentication or API calls)
|
|
359
|
+
if dry_run:
|
|
360
|
+
console.rule("Dry Run Summary", style="yellow")
|
|
361
|
+
console.print("[yellow]Dry run mode enabled - no actual download will be performed[/yellow]")
|
|
362
|
+
console.print()
|
|
363
|
+
|
|
364
|
+
# Display platform information if detected
|
|
365
|
+
if ci_info and ci_info.platform:
|
|
366
|
+
console.print("[cyan]Platform Information:[/cyan]")
|
|
367
|
+
console.print(f" • Platform: {ci_info.platform}")
|
|
368
|
+
if ci_info.repository:
|
|
369
|
+
console.print(f" • Repository: {ci_info.repository}")
|
|
370
|
+
if ci_info.session_type:
|
|
371
|
+
console.print(f" • Session Type: {ci_info.session_type}")
|
|
372
|
+
if ci_info.session_type == "cr" and ci_info.cr_number is not None:
|
|
373
|
+
console.print(f" • CR Number: {ci_info.cr_number}")
|
|
374
|
+
console.print()
|
|
375
|
+
|
|
376
|
+
# Display download summary
|
|
377
|
+
console.print("[cyan]Download Workflow:[/cyan]")
|
|
378
|
+
if session_id:
|
|
379
|
+
console.print(" • Download from specific session ID")
|
|
380
|
+
console.print(f" • Session ID: {session_id}")
|
|
381
|
+
else:
|
|
382
|
+
if prod:
|
|
383
|
+
console.print(" • Download project's production/base session")
|
|
384
|
+
else:
|
|
385
|
+
console.print(" • Auto-detect and download PR/MR session")
|
|
386
|
+
|
|
387
|
+
if ci_info and ci_info.platform in ["github-actions", "gitlab-ci"]:
|
|
388
|
+
console.print(" • Platform-specific APIs will be used")
|
|
389
|
+
else:
|
|
390
|
+
console.print(" • [yellow]Warning: Platform not supported for auto-session discovery[/yellow]")
|
|
391
|
+
|
|
392
|
+
console.print()
|
|
393
|
+
console.print("[cyan]Download destination:[/cyan]")
|
|
394
|
+
console.print(f" • Target path: {os.path.abspath(target_path)}")
|
|
395
|
+
console.print(" • Files: manifest.json, catalog.json")
|
|
396
|
+
if force:
|
|
397
|
+
console.print(" • Will overwrite existing files")
|
|
398
|
+
elif os.path.exists(target_path):
|
|
399
|
+
console.print(" • [yellow]Warning: Target path exists (use --force to overwrite)[/yellow]")
|
|
400
|
+
|
|
401
|
+
console.print()
|
|
402
|
+
console.print("[green]✓[/green] Dry run completed successfully")
|
|
403
|
+
sys.exit(0)
|
|
404
|
+
|
|
405
|
+
# 3. Choose download workflow based on whether session_id is provided
|
|
406
|
+
if session_id:
|
|
407
|
+
# Generic workflow: Download from existing session using session ID
|
|
408
|
+
# This workflow requires RECCE_API_TOKEN
|
|
409
|
+
token = os.getenv("RECCE_API_TOKEN")
|
|
410
|
+
if not token:
|
|
411
|
+
console.print("[red]Error:[/red] No RECCE_API_TOKEN provided")
|
|
412
|
+
console.print("Set RECCE_API_TOKEN environment variable for session-based download")
|
|
413
|
+
sys.exit(2)
|
|
414
|
+
|
|
415
|
+
download_from_existing_session(console, token, session_id, target_path, force)
|
|
416
|
+
else:
|
|
417
|
+
# Platform-specific workflow: Use platform APIs to find session and download
|
|
418
|
+
# This workflow MUST use CI job tokens (CI_JOB_TOKEN or GITHUB_TOKEN)
|
|
419
|
+
if not ci_info or not ci_info.access_token:
|
|
420
|
+
console.print("[red]Error:[/red] Platform-specific download requires CI environment")
|
|
421
|
+
console.print("Either run in GitHub Actions/GitLab CI or provide --session-id for generic download")
|
|
422
|
+
sys.exit(2)
|
|
423
|
+
|
|
424
|
+
token = ci_info.access_token
|
|
425
|
+
if ci_info.platform == "github-actions":
|
|
426
|
+
console.print("[cyan]Info:[/cyan] Using GITHUB_TOKEN for platform-specific authentication")
|
|
427
|
+
elif ci_info.platform == "gitlab-ci":
|
|
428
|
+
console.print("[cyan]Info:[/cyan] Using CI_JOB_TOKEN for platform-specific authentication")
|
|
429
|
+
|
|
430
|
+
download_with_platform_apis(console, token, ci_info, target_path, force)
|
|
431
|
+
|
|
432
|
+
|
|
244
433
|
if __name__ == "__main__":
|
|
245
434
|
cloud_cli()
|
recce_cloud/download.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Download helper functions for recce-cloud CLI.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
|
|
10
|
+
from recce_cloud.api.client import RecceCloudClient
|
|
11
|
+
from recce_cloud.api.exceptions import RecceCloudException
|
|
12
|
+
from recce_cloud.api.factory import create_platform_client
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _ensure_target_directory(console, target_path: str, force: bool = False):
|
|
16
|
+
"""
|
|
17
|
+
Ensure target directory exists or can be created.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
console: Rich console for output
|
|
21
|
+
target_path: Path to target directory
|
|
22
|
+
force: Whether to overwrite existing directory
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
SystemExit: If directory exists without force flag or cannot be created
|
|
26
|
+
"""
|
|
27
|
+
if os.path.exists(target_path):
|
|
28
|
+
if not force:
|
|
29
|
+
console.print(f"[red]Error:[/red] Target path already exists: {target_path}")
|
|
30
|
+
console.print("Use --force to overwrite existing directory")
|
|
31
|
+
sys.exit(3)
|
|
32
|
+
console.print(f"[yellow]Warning:[/yellow] Overwriting existing path: {target_path}")
|
|
33
|
+
else:
|
|
34
|
+
# Create target directory
|
|
35
|
+
try:
|
|
36
|
+
os.makedirs(target_path, exist_ok=True)
|
|
37
|
+
except Exception as e:
|
|
38
|
+
console.print(f"[red]Error:[/red] Failed to create target path: {target_path}")
|
|
39
|
+
console.print(f"Reason: {e}")
|
|
40
|
+
sys.exit(3)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _download_artifact(console, url: str, target_path: str, artifact_name: str):
|
|
44
|
+
"""
|
|
45
|
+
Download a single artifact file from URL.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
console: Rich console for output
|
|
49
|
+
url: Download URL
|
|
50
|
+
target_path: Path where file should be saved
|
|
51
|
+
artifact_name: Human-readable name for error messages (e.g., "manifest.json")
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
SystemExit: If download fails
|
|
55
|
+
"""
|
|
56
|
+
console.print(f'Downloading {artifact_name} to "{target_path}"')
|
|
57
|
+
try:
|
|
58
|
+
response = requests.get(url)
|
|
59
|
+
if response.status_code != 200:
|
|
60
|
+
raise Exception(f"Download failed with status {response.status_code}: {response.text}")
|
|
61
|
+
with open(target_path, "wb") as f:
|
|
62
|
+
f.write(response.content)
|
|
63
|
+
except Exception as e:
|
|
64
|
+
console.print(f"[red]Error:[/red] Failed to download {artifact_name}")
|
|
65
|
+
console.print(f"Reason: {e}")
|
|
66
|
+
sys.exit(4)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _download_artifacts(console, manifest_url: str, catalog_url: str, target_path: str):
|
|
70
|
+
"""
|
|
71
|
+
Download manifest.json and catalog.json to target directory.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
console: Rich console for output
|
|
75
|
+
manifest_url: URL for manifest.json
|
|
76
|
+
catalog_url: URL for catalog.json
|
|
77
|
+
target_path: Target directory path
|
|
78
|
+
|
|
79
|
+
Raises:
|
|
80
|
+
SystemExit: If any download fails
|
|
81
|
+
"""
|
|
82
|
+
manifest_path = os.path.join(target_path, "manifest.json")
|
|
83
|
+
catalog_path = os.path.join(target_path, "catalog.json")
|
|
84
|
+
|
|
85
|
+
_download_artifact(console, manifest_url, manifest_path, "manifest.json")
|
|
86
|
+
_download_artifact(console, catalog_url, catalog_path, "catalog.json")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def download_from_existing_session(console, token: str, session_id: str, target_path: str, force: bool = False):
|
|
90
|
+
"""
|
|
91
|
+
Download artifacts from an existing Recce Cloud session using session ID.
|
|
92
|
+
|
|
93
|
+
This is the generic workflow that requires a pre-existing session ID.
|
|
94
|
+
"""
|
|
95
|
+
try:
|
|
96
|
+
client = RecceCloudClient(token)
|
|
97
|
+
except Exception as e:
|
|
98
|
+
console.print("[red]Error:[/red] Failed to initialize API client")
|
|
99
|
+
console.print(f"Reason: {e}")
|
|
100
|
+
sys.exit(2)
|
|
101
|
+
|
|
102
|
+
# Get session info (org_id, project_id)
|
|
103
|
+
console.print(f'Downloading artifacts for session ID "{session_id}"')
|
|
104
|
+
try:
|
|
105
|
+
session = client.get_session(session_id)
|
|
106
|
+
if session.get("status") == "error":
|
|
107
|
+
console.print(f"[red]Error:[/red] {session.get('message')}")
|
|
108
|
+
sys.exit(2)
|
|
109
|
+
|
|
110
|
+
org_id = session.get("org_id")
|
|
111
|
+
if org_id is None:
|
|
112
|
+
console.print(f"[red]Error:[/red] Session ID {session_id} does not belong to any organization.")
|
|
113
|
+
sys.exit(2)
|
|
114
|
+
|
|
115
|
+
project_id = session.get("project_id")
|
|
116
|
+
if project_id is None:
|
|
117
|
+
console.print(f"[red]Error:[/red] Session ID {session_id} does not belong to any project.")
|
|
118
|
+
sys.exit(2)
|
|
119
|
+
|
|
120
|
+
except RecceCloudException as e:
|
|
121
|
+
console.print("[red]Error:[/red] Failed to get session info")
|
|
122
|
+
console.print(f"Reason: {e.reason}")
|
|
123
|
+
sys.exit(2)
|
|
124
|
+
except Exception as e:
|
|
125
|
+
console.print("[red]Error:[/red] Failed to get session info")
|
|
126
|
+
console.print(f"Reason: {e}")
|
|
127
|
+
sys.exit(2)
|
|
128
|
+
|
|
129
|
+
# Get presigned URLs
|
|
130
|
+
try:
|
|
131
|
+
presigned_urls = client.get_download_urls_by_session_id(org_id, project_id, session_id)
|
|
132
|
+
except RecceCloudException as e:
|
|
133
|
+
console.print("[red]Error:[/red] Failed to get download URLs")
|
|
134
|
+
console.print(f"Reason: {e.reason}")
|
|
135
|
+
sys.exit(4)
|
|
136
|
+
except Exception as e:
|
|
137
|
+
console.print("[red]Error:[/red] Failed to get download URLs")
|
|
138
|
+
console.print(f"Reason: {e}")
|
|
139
|
+
sys.exit(4)
|
|
140
|
+
|
|
141
|
+
# Ensure target directory exists
|
|
142
|
+
_ensure_target_directory(console, target_path, force)
|
|
143
|
+
|
|
144
|
+
# Download artifacts
|
|
145
|
+
_download_artifacts(console, presigned_urls["manifest_url"], presigned_urls["catalog_url"], target_path)
|
|
146
|
+
|
|
147
|
+
# Success!
|
|
148
|
+
console.rule("Downloaded Successfully", style="green")
|
|
149
|
+
console.print(
|
|
150
|
+
f'Downloaded dbt artifacts from Recce Cloud for session ID "{session_id}" to "{os.path.abspath(target_path)}"'
|
|
151
|
+
)
|
|
152
|
+
sys.exit(0)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def download_with_platform_apis(console, token: str, ci_info, target_path: str, force: bool = False):
|
|
156
|
+
"""
|
|
157
|
+
Download artifacts using platform-specific APIs (GitHub Actions or GitLab CI).
|
|
158
|
+
|
|
159
|
+
This workflow uses session-download-url to find and download artifacts.
|
|
160
|
+
"""
|
|
161
|
+
# Validate platform support
|
|
162
|
+
if ci_info.platform not in ["github-actions", "gitlab-ci"]:
|
|
163
|
+
console.print("[red]Error:[/red] Platform-specific download requires GitHub Actions or GitLab CI environment")
|
|
164
|
+
console.print(f"Detected platform: {ci_info.platform or 'unknown'}")
|
|
165
|
+
console.print(
|
|
166
|
+
"Either run this command in a supported CI environment or provide --session-id for generic download"
|
|
167
|
+
)
|
|
168
|
+
sys.exit(1)
|
|
169
|
+
|
|
170
|
+
# Create platform-specific client
|
|
171
|
+
try:
|
|
172
|
+
client = create_platform_client(token, ci_info)
|
|
173
|
+
except ValueError as e:
|
|
174
|
+
console.print("[red]Error:[/red] Failed to create platform client")
|
|
175
|
+
console.print(f"Reason: {e}")
|
|
176
|
+
sys.exit(2)
|
|
177
|
+
|
|
178
|
+
# Get session download URLs
|
|
179
|
+
console.rule("Finding session and getting download URLs", style="blue")
|
|
180
|
+
|
|
181
|
+
# Determine what to display based on session type
|
|
182
|
+
if ci_info.session_type == "prod":
|
|
183
|
+
console.print("Looking for production/base session...")
|
|
184
|
+
elif ci_info.session_type == "cr":
|
|
185
|
+
console.print(f"Looking for PR/MR session (CR #{ci_info.cr_number})...")
|
|
186
|
+
else:
|
|
187
|
+
console.print("Looking for session...")
|
|
188
|
+
|
|
189
|
+
try:
|
|
190
|
+
download_response = client.get_session_download_urls(
|
|
191
|
+
cr_number=ci_info.cr_number,
|
|
192
|
+
session_type=ci_info.session_type,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
session_id = download_response.get("session_id")
|
|
196
|
+
presigned_urls = download_response.get("presigned_urls", {})
|
|
197
|
+
manifest_download_url = presigned_urls.get("manifest_url")
|
|
198
|
+
catalog_download_url = presigned_urls.get("catalog_url")
|
|
199
|
+
|
|
200
|
+
if not session_id or not manifest_download_url or not catalog_download_url:
|
|
201
|
+
console.print("[red]Error:[/red] Incomplete response from session-download-url API")
|
|
202
|
+
console.print(f"Response: {download_response}")
|
|
203
|
+
sys.exit(4)
|
|
204
|
+
|
|
205
|
+
console.print(f"[green]Session ID:[/green] {session_id}")
|
|
206
|
+
|
|
207
|
+
except RecceCloudException as e:
|
|
208
|
+
console.print("[red]Error:[/red] Failed to get session download URLs")
|
|
209
|
+
console.print(f"Reason: {e.reason}")
|
|
210
|
+
sys.exit(4)
|
|
211
|
+
except Exception as e:
|
|
212
|
+
console.print("[red]Error:[/red] Failed to get session download URLs")
|
|
213
|
+
console.print(f"Reason: {e}")
|
|
214
|
+
sys.exit(4)
|
|
215
|
+
|
|
216
|
+
# Ensure target directory exists
|
|
217
|
+
_ensure_target_directory(console, target_path, force)
|
|
218
|
+
|
|
219
|
+
# Download artifacts
|
|
220
|
+
_download_artifacts(console, manifest_download_url, catalog_download_url, target_path)
|
|
221
|
+
|
|
222
|
+
# Success!
|
|
223
|
+
console.rule("Downloaded Successfully", style="green")
|
|
224
|
+
console.print(f'Downloaded dbt artifacts from Recce Cloud for session ID "{session_id}"')
|
|
225
|
+
console.print(f'Artifacts saved to: "{os.path.abspath(target_path)}"')
|
|
226
|
+
|
|
227
|
+
if ci_info.cr_url:
|
|
228
|
+
console.print(f"Change request: {ci_info.cr_url}")
|
|
229
|
+
|
|
230
|
+
sys.exit(0)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Custom hatch build hook to read README from package root directory."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from hatchling.metadata.plugin.interface import MetadataHookInterface
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CustomMetadataHook(MetadataHookInterface):
|
|
9
|
+
"""Read README from package root directory for recce-cloud package."""
|
|
10
|
+
|
|
11
|
+
PLUGIN_NAME = "custom"
|
|
12
|
+
|
|
13
|
+
def update(self, metadata: dict) -> None:
|
|
14
|
+
"""Update metadata with README content from parent directory."""
|
|
15
|
+
readme_path = Path(self.root) / "README.md"
|
|
16
|
+
if readme_path.exists():
|
|
17
|
+
metadata["readme"] = {
|
|
18
|
+
"content-type": "text/markdown",
|
|
19
|
+
"text": readme_path.read_text(encoding="utf-8"),
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "recce-cloud-nightly"
|
|
3
|
+
dynamic = ["version", "readme"]
|
|
4
|
+
description = "Lightweight CLI for Recce Cloud operations"
|
|
5
|
+
authors = [{name = "InfuseAI Dev Team", email = "dev@infuseai.io"}]
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
license = {text = "Apache-2.0"}
|
|
8
|
+
|
|
9
|
+
dependencies = [
|
|
10
|
+
"click>=7.1",
|
|
11
|
+
"requests>=2.28.1",
|
|
12
|
+
"rich>=12.0.0",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3.9",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"License :: OSI Approved :: Apache Software License",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Development Status :: 4 - Beta",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
recce-cloud = "recce_cloud.cli:cloud_cli"
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
"Bug Tracker" = "https://github.com/InfuseAI/recce/issues"
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["hatchling"]
|
|
34
|
+
build-backend = "hatchling.build"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.version]
|
|
37
|
+
path = "VERSION"
|
|
38
|
+
pattern = "(?P<version>.+)"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.metadata]
|
|
41
|
+
allow-direct-references = true
|
|
42
|
+
|
|
43
|
+
[tool.hatch.metadata.hooks.custom]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["."]
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.wheel.sources]
|
|
49
|
+
"." = "recce_cloud"
|