recce-cloud-nightly 1.26.0.20251124.post1__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.
recce_cloud/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.26.0.20251124-post1
@@ -0,0 +1,24 @@
1
+ """Recce Cloud - Lightweight CLI for Recce Cloud operations."""
2
+
3
+ import os
4
+
5
+
6
+ def get_version():
7
+ """Get version from VERSION file."""
8
+ # Try recce_cloud/VERSION first (for standalone package)
9
+ version_file = os.path.join(os.path.dirname(__file__), "VERSION")
10
+ if os.path.exists(version_file):
11
+ with open(version_file) as fh:
12
+ return fh.read().strip()
13
+
14
+ # Fallback to ../recce/VERSION (for development)
15
+ version_file = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "recce", "VERSION"))
16
+ if os.path.exists(version_file):
17
+ with open(version_file) as fh:
18
+ return fh.read().strip()
19
+
20
+ # Last resort
21
+ return "unknown"
22
+
23
+
24
+ __version__ = get_version()
@@ -0,0 +1,17 @@
1
+ """Recce Cloud API client module."""
2
+
3
+ from recce_cloud.api.base import BaseRecceCloudClient
4
+ from recce_cloud.api.client import RecceCloudClient
5
+ from recce_cloud.api.exceptions import RecceCloudException
6
+ from recce_cloud.api.factory import create_platform_client
7
+ from recce_cloud.api.github import GitHubRecceCloudClient
8
+ from recce_cloud.api.gitlab import GitLabRecceCloudClient
9
+
10
+ __all__ = [
11
+ "BaseRecceCloudClient",
12
+ "RecceCloudClient",
13
+ "RecceCloudException",
14
+ "create_platform_client",
15
+ "GitHubRecceCloudClient",
16
+ "GitLabRecceCloudClient",
17
+ ]
@@ -0,0 +1,111 @@
1
+ """
2
+ Base API client for Recce Cloud.
3
+ """
4
+
5
+ import os
6
+ from abc import ABC, abstractmethod
7
+ from typing import Dict, Optional
8
+
9
+ import requests
10
+
11
+ from recce_cloud.api.exceptions import RecceCloudException
12
+
13
+
14
+ class BaseRecceCloudClient(ABC):
15
+ """Abstract base class for platform-specific Recce Cloud API clients."""
16
+
17
+ def __init__(self, token: str, api_host: Optional[str] = None):
18
+ """
19
+ Initialize the API client.
20
+
21
+ Args:
22
+ token: Authentication token (GITHUB_TOKEN, CI_JOB_TOKEN, or RECCE_API_TOKEN)
23
+ api_host: Recce Cloud API host (defaults to RECCE_CLOUD_API_HOST or https://cloud.datarecce.io)
24
+ """
25
+ self.token = token
26
+ self.api_host = api_host or os.getenv("RECCE_CLOUD_API_HOST", "https://cloud.datarecce.io")
27
+
28
+ def _make_request(self, method: str, url: str, **kwargs) -> Dict:
29
+ """
30
+ Make an HTTP request to Recce Cloud API.
31
+
32
+ Args:
33
+ method: HTTP method (GET, POST, PUT, etc.)
34
+ url: Full URL for the request
35
+ **kwargs: Additional arguments passed to requests
36
+
37
+ Returns:
38
+ Response JSON as dictionary
39
+
40
+ Raises:
41
+ RecceCloudException: If the request fails
42
+ """
43
+ headers = kwargs.pop("headers", {})
44
+ headers.update(
45
+ {
46
+ "Authorization": f"Bearer {self.token}",
47
+ "Content-Type": "application/json",
48
+ }
49
+ )
50
+
51
+ try:
52
+ response = requests.request(method, url, headers=headers, **kwargs)
53
+ response.raise_for_status()
54
+
55
+ # Handle empty responses (e.g., 204 No Content)
56
+ if response.status_code == 204 or not response.content:
57
+ return {}
58
+
59
+ return response.json()
60
+ except requests.exceptions.HTTPError as e:
61
+ reason = str(e)
62
+ if e.response is not None:
63
+ try:
64
+ error_detail = e.response.json()
65
+ reason = error_detail.get("message", str(e))
66
+ except Exception:
67
+ reason = e.response.text or str(e)
68
+ raise RecceCloudException(reason=reason, status_code=e.response.status_code if e.response else None)
69
+ except requests.exceptions.RequestException as e:
70
+ raise RecceCloudException(reason=str(e))
71
+
72
+ @abstractmethod
73
+ def touch_recce_session(
74
+ self,
75
+ branch: str,
76
+ adapter_type: str,
77
+ cr_number: Optional[int] = None,
78
+ commit_sha: Optional[str] = None,
79
+ session_type: Optional[str] = None,
80
+ ) -> Dict:
81
+ """
82
+ Create or touch a Recce session.
83
+
84
+ Args:
85
+ branch: Branch name
86
+ adapter_type: DBT adapter type (e.g., 'postgres', 'snowflake', 'bigquery')
87
+ cr_number: Change request number (PR/MR number) for CR sessions
88
+ commit_sha: Commit SHA (GitLab requires this)
89
+ session_type: Session type ("cr", "prod", "dev") - determines if cr_number is used
90
+
91
+ Returns:
92
+ Dictionary containing:
93
+ - session_id: Session ID
94
+ - manifest_upload_url: Presigned URL for manifest.json upload
95
+ - catalog_upload_url: Presigned URL for catalog.json upload
96
+ """
97
+ pass
98
+
99
+ @abstractmethod
100
+ def upload_completed(self, session_id: str, commit_sha: Optional[str] = None) -> Dict:
101
+ """
102
+ Notify Recce Cloud that upload is complete.
103
+
104
+ Args:
105
+ session_id: Session ID from touch_recce_session
106
+ commit_sha: Commit SHA (GitLab requires this)
107
+
108
+ Returns:
109
+ Empty dictionary or acknowledgement
110
+ """
111
+ pass
@@ -0,0 +1,150 @@
1
+ """
2
+ Recce Cloud API client for lightweight operations.
3
+
4
+ Simplified version of recce.util.recce_cloud.RecceCloud with only
5
+ the methods needed for upload-session functionality.
6
+ """
7
+
8
+ import os
9
+
10
+ import requests
11
+
12
+ from recce_cloud.api.exceptions import RecceCloudException
13
+
14
+ RECCE_CLOUD_API_HOST = os.environ.get("RECCE_CLOUD_API_HOST", "https://cloud.datarecce.io")
15
+
16
+ DOCKER_INTERNAL_URL_PREFIX = "http://host.docker.internal"
17
+ LOCALHOST_URL_PREFIX = "http://localhost"
18
+
19
+
20
+ class RecceCloudClient:
21
+ """
22
+ Lightweight Recce Cloud API client.
23
+
24
+ Supports authentication with Recce Cloud API token (starts with "rct-").
25
+ """
26
+
27
+ def __init__(self, token: str):
28
+ if token is None:
29
+ raise ValueError("Token cannot be None.")
30
+ self.token = token
31
+ self.base_url_v2 = f"{RECCE_CLOUD_API_HOST}/api/v2"
32
+
33
+ def _request(self, method: str, url: str, headers: dict = None, **kwargs):
34
+ """Make authenticated HTTP request to Recce Cloud API."""
35
+ headers = {
36
+ **(headers or {}),
37
+ "Authorization": f"Bearer {self.token}",
38
+ }
39
+ return requests.request(method, url, headers=headers, **kwargs)
40
+
41
+ def _replace_localhost_with_docker_internal(self, url: str) -> str:
42
+ """Convert localhost URLs to docker internal URLs if running in Docker."""
43
+ if url is None:
44
+ return None
45
+ if (
46
+ os.environ.get("RECCE_SHARE_INSTANCE_ENV") == "docker"
47
+ or os.environ.get("RECCE_TASK_INSTANCE_ENV") == "docker"
48
+ or os.environ.get("RECCE_INSTANCE_ENV") == "docker"
49
+ ):
50
+ # For local development, convert the presigned URL from localhost to host.docker.internal
51
+ if url.startswith(LOCALHOST_URL_PREFIX):
52
+ return url.replace(LOCALHOST_URL_PREFIX, DOCKER_INTERNAL_URL_PREFIX)
53
+ return url
54
+
55
+ def get_session(self, session_id: str) -> dict:
56
+ """
57
+ Get session information from Recce Cloud.
58
+
59
+ Args:
60
+ session_id: The session ID to retrieve
61
+
62
+ Returns:
63
+ dict containing session information with keys:
64
+ - org_id: Organization ID
65
+ - project_id: Project ID
66
+ - ... other session fields
67
+
68
+ Raises:
69
+ RecceCloudException: If the request fails
70
+ """
71
+ api_url = f"{self.base_url_v2}/sessions/{session_id}"
72
+ response = self._request("GET", api_url)
73
+ if response.status_code == 403:
74
+ return {"status": "error", "message": response.json().get("detail")}
75
+ if response.status_code != 200:
76
+ raise RecceCloudException(
77
+ reason=response.text,
78
+ status_code=response.status_code,
79
+ )
80
+ data = response.json()
81
+ if data["success"] is not True:
82
+ raise RecceCloudException(
83
+ reason=data.get("message", "Unknown error"),
84
+ status_code=response.status_code,
85
+ )
86
+ return data["session"]
87
+
88
+ def get_upload_urls_by_session_id(self, org_id: str, project_id: str, session_id: str) -> dict:
89
+ """
90
+ Get presigned S3 upload URLs for a session.
91
+
92
+ Args:
93
+ org_id: Organization ID
94
+ project_id: Project ID
95
+ session_id: Session ID
96
+
97
+ Returns:
98
+ dict with keys:
99
+ - manifest_url: Presigned URL for uploading manifest.json
100
+ - catalog_url: Presigned URL for uploading catalog.json
101
+
102
+ Raises:
103
+ RecceCloudException: If the request fails
104
+ """
105
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/upload-url"
106
+ response = self._request("GET", api_url)
107
+ if response.status_code != 200:
108
+ raise RecceCloudException(
109
+ reason=response.text,
110
+ status_code=response.status_code,
111
+ )
112
+ data = response.json()
113
+ if data["presigned_urls"] is None:
114
+ raise RecceCloudException(
115
+ reason="No presigned URLs returned from the server.",
116
+ status_code=404,
117
+ )
118
+
119
+ presigned_urls = data["presigned_urls"]
120
+ for key, url in presigned_urls.items():
121
+ presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
122
+ return presigned_urls
123
+
124
+ def update_session(self, org_id: str, project_id: str, session_id: str, adapter_type: str) -> dict:
125
+ """
126
+ Update session metadata with adapter type.
127
+
128
+ Args:
129
+ org_id: Organization ID
130
+ project_id: Project ID
131
+ session_id: Session ID
132
+ adapter_type: dbt adapter type (e.g., "postgres", "snowflake", "bigquery")
133
+
134
+ Returns:
135
+ dict containing updated session information
136
+
137
+ Raises:
138
+ RecceCloudException: If the request fails
139
+ """
140
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}"
141
+ data = {"adapter_type": adapter_type}
142
+ response = self._request("PATCH", api_url, json=data)
143
+ if response.status_code == 403:
144
+ return {"status": "error", "message": response.json().get("detail")}
145
+ if response.status_code != 200:
146
+ raise RecceCloudException(
147
+ reason=response.text,
148
+ status_code=response.status_code,
149
+ )
150
+ return response.json()
@@ -0,0 +1,26 @@
1
+ """
2
+ Exceptions for Recce Cloud API.
3
+ """
4
+
5
+ import json
6
+
7
+
8
+ class RecceCloudException(Exception):
9
+ """Exception raised when Recce Cloud API returns an error."""
10
+
11
+ def __init__(self, reason: str, status_code: int = None):
12
+ """
13
+ Initialize exception.
14
+
15
+ Args:
16
+ reason: Error reason/message
17
+ status_code: HTTP status code (optional)
18
+ """
19
+ try:
20
+ reason = json.loads(reason).get("detail", reason)
21
+ except (json.JSONDecodeError, AttributeError):
22
+ pass
23
+
24
+ super().__init__(reason)
25
+ self.reason = reason
26
+ self.status_code = status_code
@@ -0,0 +1,63 @@
1
+ """
2
+ Factory for creating platform-specific API clients.
3
+ """
4
+
5
+ import os
6
+ from typing import Optional
7
+
8
+ from recce_cloud.api.github import GitHubRecceCloudClient
9
+ from recce_cloud.api.gitlab import GitLabRecceCloudClient
10
+ from recce_cloud.ci_providers import CIDetector
11
+ from recce_cloud.ci_providers.base import CIInfo
12
+
13
+
14
+ def create_platform_client(
15
+ token: str,
16
+ ci_info: Optional[CIInfo] = None,
17
+ api_host: Optional[str] = None,
18
+ ):
19
+ """
20
+ Create a platform-specific Recce Cloud API client based on CI environment.
21
+
22
+ Args:
23
+ token: Authentication token (GITHUB_TOKEN, CI_JOB_TOKEN, or RECCE_API_TOKEN)
24
+ ci_info: CI information (auto-detected if not provided)
25
+ api_host: Recce Cloud API host (optional)
26
+
27
+ Returns:
28
+ GitHubRecceCloudClient or GitLabRecceCloudClient
29
+
30
+ Raises:
31
+ ValueError: If platform is not supported or required information is missing
32
+ """
33
+ # Auto-detect CI info if not provided
34
+ if ci_info is None:
35
+ ci_info = CIDetector.detect()
36
+
37
+ if ci_info.platform == "github-actions":
38
+ repository = ci_info.repository or os.getenv("GITHUB_REPOSITORY")
39
+ if not repository:
40
+ raise ValueError("GitHub repository information is required but not detected")
41
+
42
+ return GitHubRecceCloudClient(token=token, repository=repository, api_host=api_host)
43
+
44
+ elif ci_info.platform == "gitlab-ci":
45
+ project_path = ci_info.repository or os.getenv("CI_PROJECT_PATH")
46
+ repository_url = os.getenv("CI_PROJECT_URL")
47
+
48
+ if not project_path:
49
+ raise ValueError("GitLab project path is required but not detected")
50
+ if not repository_url:
51
+ raise ValueError("GitLab project URL is required but not detected")
52
+
53
+ return GitLabRecceCloudClient(
54
+ token=token,
55
+ project_path=project_path,
56
+ repository_url=repository_url,
57
+ api_host=api_host,
58
+ )
59
+
60
+ else:
61
+ raise ValueError(
62
+ f"Unsupported platform: {ci_info.platform}. " "Only GitHub Actions and GitLab CI are supported."
63
+ )
@@ -0,0 +1,76 @@
1
+ """
2
+ GitHub-specific API client for Recce Cloud.
3
+ """
4
+
5
+ from typing import Dict, Optional
6
+
7
+ from recce_cloud.api.base import BaseRecceCloudClient
8
+
9
+
10
+ class GitHubRecceCloudClient(BaseRecceCloudClient):
11
+ """GitHub Actions-specific implementation of Recce Cloud API client."""
12
+
13
+ def __init__(self, token: str, repository: str, api_host: Optional[str] = None):
14
+ """
15
+ Initialize GitHub API client.
16
+
17
+ Args:
18
+ token: GitHub token (GITHUB_TOKEN or RECCE_API_TOKEN)
19
+ repository: Repository in format "owner/repo"
20
+ api_host: Recce Cloud API host
21
+ """
22
+ super().__init__(token, api_host)
23
+ self.repository = repository
24
+
25
+ def touch_recce_session(
26
+ self,
27
+ branch: str,
28
+ adapter_type: str,
29
+ cr_number: Optional[int] = None,
30
+ session_type: Optional[str] = None,
31
+ ) -> Dict:
32
+ """
33
+ Create or touch a Recce session for GitHub Actions.
34
+
35
+ Args:
36
+ branch: Branch name
37
+ adapter_type: DBT adapter type
38
+ cr_number: PR number for pull request sessions (None for prod sessions)
39
+ commit_sha: Not used for GitHub (optional for compatibility)
40
+ session_type: Session type ("cr", "prod", "dev") - determines if pr_number is passed
41
+
42
+ Returns:
43
+ Dictionary containing session_id, manifest_upload_url, catalog_upload_url
44
+ """
45
+ url = f"{self.api_host}/api/v2/github/{self.repository}/touch-recce-session"
46
+
47
+ payload = {
48
+ "branch": branch,
49
+ "adapter_type": adapter_type,
50
+ }
51
+
52
+ # Only include pr_number for "cr" type sessions
53
+ # For "prod" type, omit pr_number even if cr_number is detected
54
+ if session_type == "cr" and cr_number is not None:
55
+ payload["pr_number"] = cr_number
56
+
57
+ return self._make_request("POST", url, json=payload)
58
+
59
+ def upload_completed(self, session_id: str, commit_sha: Optional[str] = None) -> Dict:
60
+ """
61
+ Notify Recce Cloud that upload is complete for GitHub.
62
+
63
+ Args:
64
+ session_id: Session ID from touch_recce_session
65
+ commit_sha: Not used for GitHub (optional for compatibility)
66
+
67
+ Returns:
68
+ Empty dictionary or acknowledgement
69
+ """
70
+ url = f"{self.api_host}/api/v2/github/{self.repository}/upload-completed"
71
+
72
+ payload = {
73
+ "session_id": session_id,
74
+ }
75
+
76
+ return self._make_request("POST", url, json=payload)
@@ -0,0 +1,82 @@
1
+ """
2
+ GitLab-specific API client for Recce Cloud.
3
+ """
4
+
5
+ from typing import Dict, Optional
6
+
7
+ from recce_cloud.api.base import BaseRecceCloudClient
8
+
9
+
10
+ class GitLabRecceCloudClient(BaseRecceCloudClient):
11
+ """GitLab CI-specific implementation of Recce Cloud API client."""
12
+
13
+ def __init__(self, token: str, project_path: str, repository_url: str, api_host: Optional[str] = None):
14
+ """
15
+ Initialize GitLab API client.
16
+
17
+ Args:
18
+ token: GitLab token (CI_JOB_TOKEN or RECCE_API_TOKEN)
19
+ project_path: Project path in format "group/project"
20
+ repository_url: Full repository URL (e.g., https://gitlab.com/group/project)
21
+ api_host: Recce Cloud API host
22
+ """
23
+ super().__init__(token, api_host)
24
+ self.project_path = project_path
25
+ self.repository_url = repository_url
26
+
27
+ def touch_recce_session(
28
+ self,
29
+ branch: str,
30
+ adapter_type: str,
31
+ cr_number: Optional[int] = None,
32
+ commit_sha: Optional[str] = None,
33
+ session_type: Optional[str] = None,
34
+ ) -> Dict:
35
+ """
36
+ Create or touch a Recce session for GitLab CI.
37
+
38
+ Args:
39
+ branch: Branch name
40
+ adapter_type: DBT adapter type
41
+ cr_number: MR IID for merge request sessions (None for prod sessions)
42
+ commit_sha: Commit SHA (required for GitLab)
43
+ session_type: Session type ("cr", "prod", "dev") - determines if mr_iid is passed
44
+
45
+ Returns:
46
+ Dictionary containing session_id, manifest_upload_url, catalog_upload_url
47
+ """
48
+ url = f"{self.api_host}/api/v2/gitlab/{self.project_path}/touch-recce-session"
49
+
50
+ payload = {
51
+ "branch": branch,
52
+ "adapter_type": adapter_type,
53
+ "commit_sha": commit_sha,
54
+ "repository_url": self.repository_url,
55
+ }
56
+
57
+ # Only include mr_iid for "cr" type sessions
58
+ # For "prod" type, omit mr_iid even if cr_number is detected
59
+ if session_type == "cr" and cr_number is not None:
60
+ payload["mr_iid"] = cr_number
61
+
62
+ return self._make_request("POST", url, json=payload)
63
+
64
+ def upload_completed(self, session_id: str, commit_sha: Optional[str] = None) -> Dict:
65
+ """
66
+ Notify Recce Cloud that upload is complete for GitLab.
67
+
68
+ Args:
69
+ session_id: Session ID from touch_recce_session
70
+ commit_sha: Commit SHA (required for GitLab)
71
+
72
+ Returns:
73
+ Empty dictionary or acknowledgement
74
+ """
75
+ url = f"{self.api_host}/api/v2/gitlab/{self.project_path}/upload-completed"
76
+
77
+ payload = {
78
+ "session_id": session_id,
79
+ "commit_sha": commit_sha,
80
+ }
81
+
82
+ return self._make_request("POST", url, json=payload)
@@ -0,0 +1,57 @@
1
+ """
2
+ Artifact utilities for recce-cloud.
3
+
4
+ Simplified version of recce.artifact with only the functions needed
5
+ for upload-session functionality.
6
+ """
7
+
8
+ import json
9
+ import os
10
+
11
+
12
+ def verify_artifacts_path(target_path: str) -> bool:
13
+ """
14
+ Verify if the target path contains valid dbt artifacts.
15
+
16
+ Args:
17
+ target_path: Path to the directory containing artifacts
18
+
19
+ Returns:
20
+ True if the target path contains manifest.json and catalog.json
21
+ """
22
+ if not target_path:
23
+ return False
24
+
25
+ if not os.path.exists(target_path):
26
+ return False
27
+
28
+ if not os.path.isdir(target_path):
29
+ return False
30
+
31
+ required_artifacts_files = ["manifest.json", "catalog.json"]
32
+
33
+ if all(f in os.listdir(target_path) for f in required_artifacts_files):
34
+ return True
35
+
36
+ return False
37
+
38
+
39
+ def get_adapter_type(manifest_path: str) -> str:
40
+ """
41
+ Extract adapter type from manifest.json.
42
+
43
+ Args:
44
+ manifest_path: Path to manifest.json file
45
+
46
+ Returns:
47
+ Adapter type string (e.g., "postgres", "snowflake", "bigquery")
48
+
49
+ Raises:
50
+ Exception: If adapter type cannot be found in manifest
51
+ """
52
+ with open(manifest_path, "r", encoding="utf-8") as f:
53
+ manifest_data = json.load(f)
54
+ adapter_type = manifest_data.get("metadata", {}).get("adapter_type")
55
+ if adapter_type is None:
56
+ raise Exception("Failed to parse adapter type from manifest.json")
57
+ return adapter_type
@@ -0,0 +1,9 @@
1
+ """
2
+ CI/CD Provider detection and information extraction.
3
+ """
4
+
5
+ from recce_cloud.ci_providers.detector import CIDetector
6
+ from recce_cloud.ci_providers.github_actions import GitHubActionsProvider
7
+ from recce_cloud.ci_providers.gitlab_ci import GitLabCIProvider
8
+
9
+ __all__ = ["CIDetector", "GitHubActionsProvider", "GitLabCIProvider"]