tinybird 0.0.1.dev165__py3-none-any.whl → 0.0.1.dev166__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 tinybird might be problematic. Click here for more details.

tinybird/tb/__cli__.py CHANGED
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
4
4
  __url__ = 'https://www.tinybird.co/docs/forward/commands'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '0.0.1.dev165'
8
- __revision__ = '154a5d7'
7
+ __version__ = '0.0.1.dev166'
8
+ __revision__ = 'dfe3726'
@@ -576,7 +576,10 @@ def create_deployment(
576
576
  sys.exit(0)
577
577
  elif status == "failed":
578
578
  click.echo(FeedbackManager.error(message="Deployment failed"))
579
- sys_exit("deployment_error", "Deployment failed" + str(deployment.get("errors")))
579
+ sys_exit(
580
+ "deployment_error",
581
+ f"Deployment failed. Errors: {str(deployment.get('errors') + deployment.get('feedback'))}",
582
+ )
580
583
  else:
581
584
  click.echo(FeedbackManager.error(message=f"Unknown deployment result {status}"))
582
585
  except Exception as e:
@@ -606,7 +609,10 @@ def create_deployment(
606
609
  if auto:
607
610
  click.echo(FeedbackManager.error(message="Rolling back deployment"))
608
611
  discard_deployment(client.host, HEADERS, wait=wait)
609
- sys_exit("deployment_error", "Deployment failed: " + str(deployment.get("errors")))
612
+ sys_exit(
613
+ "deployment_error",
614
+ f"Deployment failed. Errors: {str(deployment.get('errors') + deployment.get('feedback'))}",
615
+ )
610
616
 
611
617
  if deployment.get("status") == "data_ready":
612
618
  break
@@ -1,12 +1,19 @@
1
1
  import hashlib
2
+ import json
2
3
  import logging
3
4
  import os
4
5
  import re
5
6
  import subprocess
6
- from typing import Any, Dict
7
+ import time
8
+ from typing import Any, Dict, Optional
7
9
 
10
+ import boto3
11
+ import click
8
12
  import requests
9
13
 
14
+ import docker
15
+ from docker.client import DockerClient
16
+ from docker.models.containers import Container
10
17
  from tinybird.tb.client import AuthNoTokenException, TinyB
11
18
  from tinybird.tb.modules.config import CLIConfig
12
19
  from tinybird.tb.modules.exceptions import CLILocalException
@@ -118,6 +125,249 @@ def get_local_tokens() -> Dict[str, str]:
118
125
  )
119
126
  except Exception:
120
127
  pass
128
+ is_ci = (
129
+ os.getenv("GITHUB_ACTIONS")
130
+ or os.getenv("TRAVIS")
131
+ or os.getenv("CIRCLECI")
132
+ or os.getenv("GITLAB_CI")
133
+ or os.getenv("CI")
134
+ or os.getenv("TB_CI")
135
+ )
136
+ if not is_ci:
137
+ yes = click.confirm(
138
+ FeedbackManager.warning(message="Tinybird local is not running. Do you want to start it? [Y/n]"),
139
+ prompt_suffix="",
140
+ show_default=False,
141
+ default=True,
142
+ )
143
+ if yes:
144
+ click.echo(FeedbackManager.highlight(message="» Starting Tinybird Local..."))
145
+ docker_client = get_docker_client()
146
+ start_tinybird_local(docker_client, False)
147
+ click.echo(FeedbackManager.success(message="✓ Tinybird Local is ready!"))
148
+ return get_local_tokens()
121
149
  raise CLILocalException(
122
150
  FeedbackManager.error(message="Tinybird local is not running. Please run `tb local start` first.")
123
151
  )
152
+
153
+
154
+ def start_tinybird_local(
155
+ docker_client: DockerClient,
156
+ use_aws_creds: bool,
157
+ ) -> None:
158
+ """Start the Tinybird container."""
159
+ pull_show_prompt = False
160
+ pull_required = False
161
+ try:
162
+ local_image = docker_client.images.get(TB_IMAGE_NAME)
163
+ local_image_id = local_image.attrs["RepoDigests"][0].split("@")[1]
164
+ remote_image = docker_client.images.get_registry_data(TB_IMAGE_NAME)
165
+ pull_show_prompt = local_image_id != remote_image.id
166
+ except Exception:
167
+ pull_show_prompt = False
168
+ pull_required = True
169
+
170
+ if pull_show_prompt and click.confirm(
171
+ FeedbackManager.warning(message="△ New version detected, download? [y/N]:"),
172
+ show_default=False,
173
+ prompt_suffix="",
174
+ ):
175
+ click.echo(FeedbackManager.info(message="* Downloading latest version of Tinybird Local..."))
176
+ pull_required = True
177
+
178
+ if pull_required:
179
+ docker_client.images.pull(TB_IMAGE_NAME, platform="linux/amd64")
180
+
181
+ environment = get_use_aws_creds() if use_aws_creds else {}
182
+
183
+ container = get_existing_container_with_matching_env(docker_client, TB_CONTAINER_NAME, environment)
184
+
185
+ if container and not pull_required:
186
+ # Container `start` is idempotent. It's safe to call it even if the container is already running.
187
+ container.start()
188
+ else:
189
+ if container:
190
+ container.remove(force=True)
191
+
192
+ container = docker_client.containers.run(
193
+ TB_IMAGE_NAME,
194
+ name=TB_CONTAINER_NAME,
195
+ detach=True,
196
+ ports={"7181/tcp": TB_LOCAL_PORT},
197
+ remove=False,
198
+ platform="linux/amd64",
199
+ environment=environment,
200
+ )
201
+
202
+ click.echo(FeedbackManager.info(message="* Waiting for Tinybird Local to be ready..."))
203
+ while True:
204
+ container.reload() # Refresh container attributes
205
+ health = container.attrs.get("State", {}).get("Health", {}).get("Status")
206
+ if health == "healthy":
207
+ break
208
+ if health == "unhealthy":
209
+ raise CLILocalException(
210
+ FeedbackManager.error(
211
+ message="Tinybird Local is unhealthy. Try running `tb local restart` in a few seconds."
212
+ )
213
+ )
214
+
215
+ time.sleep(5)
216
+
217
+ # Remove tinybird-local dangling images to avoid running out of disk space
218
+ images = docker_client.images.list(name=re.sub(r":.*$", "", TB_IMAGE_NAME), all=True, filters={"dangling": True})
219
+ for image in images:
220
+ image.remove(force=True)
221
+
222
+
223
+ def get_existing_container_with_matching_env(
224
+ docker_client: DockerClient, container_name: str, required_env: dict[str, str]
225
+ ) -> Optional[Container]:
226
+ """
227
+ Checks if a container with the given name exists and has matching environment variables.
228
+ If it exists but environment doesn't match, it returns None.
229
+
230
+ Args:
231
+ docker_client: The Docker client instance
232
+ container_name: The name of the container to check
233
+ required_env: Dictionary of environment variables that must be present
234
+
235
+ Returns:
236
+ The container if it exists with matching environment, None otherwise
237
+ """
238
+ container = None
239
+ containers = docker_client.containers.list(all=True, filters={"name": container_name})
240
+ if containers:
241
+ container = containers[0]
242
+
243
+ if container and required_env:
244
+ container_info = container.attrs
245
+ container_env = container_info.get("Config", {}).get("Env", [])
246
+ env_missing = False
247
+ for key, value in required_env.items():
248
+ env_var = f"{key}={value}"
249
+ if env_var not in container_env:
250
+ env_missing = True
251
+ break
252
+
253
+ if env_missing:
254
+ container.remove(force=True)
255
+ container = None
256
+
257
+ return container
258
+
259
+
260
+ def get_docker_client() -> DockerClient:
261
+ """Check if Docker is installed and running."""
262
+ try:
263
+ docker_host = os.getenv("DOCKER_HOST")
264
+ if not docker_host:
265
+ # Try to get docker host from docker context
266
+ try:
267
+ try:
268
+ output = subprocess.check_output(["docker", "context", "inspect"], text=True)
269
+ except Exception as e:
270
+ add_telemetry_event(
271
+ "docker_error",
272
+ error=f"docker_context_inspect_error: {str(e)}",
273
+ )
274
+ raise e
275
+ try:
276
+ context = json.loads(output)
277
+ except Exception as e:
278
+ add_telemetry_event(
279
+ "docker_error",
280
+ error=f"docker_context_inspect_parse_output_error: {str(e)}",
281
+ data={
282
+ "docker_context_inspect_output": output,
283
+ },
284
+ )
285
+ raise e
286
+ if context and len(context) > 0:
287
+ try:
288
+ docker_host = context[0].get("Endpoints", {}).get("docker", {}).get("Host")
289
+ if docker_host:
290
+ os.environ["DOCKER_HOST"] = docker_host
291
+ except Exception as e:
292
+ add_telemetry_event(
293
+ "docker_error",
294
+ error=f"docker_context_parse_host_error: {str(e)}",
295
+ data={
296
+ "context": json.dumps(context),
297
+ },
298
+ )
299
+ raise e
300
+ except Exception:
301
+ pass
302
+ try:
303
+ client = docker.from_env() # type: ignore
304
+ except Exception as e:
305
+ add_telemetry_event(
306
+ "docker_error",
307
+ error=f"docker_get_client_from_env_error: {str(e)}",
308
+ )
309
+ raise e
310
+ try:
311
+ client.ping()
312
+ except Exception as e:
313
+ client_dict_non_sensitive = {k: v for k, v in client.api.__dict__.items() if "auth" not in k}
314
+ add_telemetry_event(
315
+ "docker_error",
316
+ error=f"docker_ping_error: {str(e)}",
317
+ data={
318
+ "client": repr(client_dict_non_sensitive),
319
+ },
320
+ )
321
+ raise e
322
+ return client
323
+ except Exception:
324
+ raise CLILocalException(
325
+ FeedbackManager.error(
326
+ message=(
327
+ f"No container runtime is running. Make sure a Docker-compatible runtime is installed and running. "
328
+ f"Trying to connect to Docker-compatible runtime at {docker_host}\n\n"
329
+ "If you're using a custom location, please provide it using the DOCKER_HOST environment variable."
330
+ )
331
+ )
332
+ )
333
+
334
+
335
+ def get_use_aws_creds() -> dict[str, str]:
336
+ credentials: dict[str, str] = {}
337
+ try:
338
+ # Get the boto3 session and credentials
339
+ session = boto3.Session()
340
+ creds = session.get_credentials()
341
+
342
+ if creds:
343
+ # Create environment variables for the container based on boto credentials
344
+ credentials["AWS_ACCESS_KEY_ID"] = creds.access_key
345
+ credentials["AWS_SECRET_ACCESS_KEY"] = creds.secret_key
346
+
347
+ # Add session token if it exists (for temporary credentials)
348
+ if creds.token:
349
+ credentials["AWS_SESSION_TOKEN"] = creds.token
350
+
351
+ # Add region if available
352
+ if session.region_name:
353
+ credentials["AWS_DEFAULT_REGION"] = session.region_name
354
+
355
+ click.echo(
356
+ FeedbackManager.success(
357
+ message=f"✓ AWS credentials found and will be passed to Tinybird Local (region: {session.region_name or 'not set'})"
358
+ )
359
+ )
360
+ else:
361
+ click.echo(
362
+ FeedbackManager.warning(
363
+ message="△ No AWS credentials found. S3 operations will not work in Tinybird Local."
364
+ )
365
+ )
366
+ except Exception as e:
367
+ click.echo(
368
+ FeedbackManager.warning(
369
+ message=f"△ Error retrieving AWS credentials: {str(e)}. S3 operations will not work in Tinybird Local."
370
+ )
371
+ )
372
+
373
+ return credentials
@@ -13,7 +13,6 @@ from pathlib import Path
13
13
  from typing import Any, Dict, List, Optional, Tuple
14
14
 
15
15
  import click
16
- import requests
17
16
  import yaml
18
17
  from requests import Response
19
18
 
@@ -22,11 +21,11 @@ from tinybird.tb.client import TinyB
22
21
  from tinybird.tb.modules.build import process as build_project
23
22
  from tinybird.tb.modules.cli import cli
24
23
  from tinybird.tb.modules.config import CLIConfig
25
- from tinybird.tb.modules.exceptions import CLILocalException, CLITestException
24
+ from tinybird.tb.modules.exceptions import CLITestException
26
25
  from tinybird.tb.modules.feedback_manager import FeedbackManager
27
26
  from tinybird.tb.modules.llm import LLM
28
27
  from tinybird.tb.modules.llm_utils import extract_xml, parse_xml
29
- from tinybird.tb.modules.local_common import TB_LOCAL_ADDRESS, get_test_workspace_name
28
+ from tinybird.tb.modules.local_common import get_local_tokens, get_test_workspace_name
30
29
  from tinybird.tb.modules.project import Project
31
30
 
32
31
  yaml.SafeDumper.org_represent_str = yaml.SafeDumper.represent_str # type: ignore[attr-defined]
@@ -314,13 +313,7 @@ def get_pipe_path(name_or_filename: str, folder: str) -> Path:
314
313
 
315
314
  def cleanup_test_workspace(client: TinyB, path: str) -> None:
316
315
  user_client = deepcopy(client)
317
- try:
318
- # ruff: noqa: ASYNC210
319
- tokens = requests.get(f"{TB_LOCAL_ADDRESS}/tokens").json()
320
- except Exception:
321
- raise CLILocalException(
322
- FeedbackManager.error(message="Tinybird local is not running. Please run `tb local start` first.")
323
- )
316
+ tokens = get_local_tokens()
324
317
  try:
325
318
  user_token = tokens["user_token"]
326
319
  user_client.token = user_token
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev165
3
+ Version: 0.0.1.dev166
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -12,7 +12,7 @@ tinybird/syncasync.py,sha256=IPnOx6lMbf9SNddN1eBtssg8vCLHMt76SuZ6YNYm-Yk,27761
12
12
  tinybird/tornado_template.py,sha256=jjNVDMnkYFWXflmT8KU_Ssbo5vR8KQq3EJMk5vYgXRw,41959
13
13
  tinybird/ch_utils/constants.py,sha256=aYvg2C_WxYWsnqPdZB1ZFoIr8ZY-XjUXYyHKE9Ansj0,3890
14
14
  tinybird/ch_utils/engine.py,sha256=BZuPM7MFS7vaEKK5tOMR2bwSAgJudPrJt27uVEwZmTY,40512
15
- tinybird/tb/__cli__.py,sha256=PJGHMfcwNnFGvrhAnlIKfCt69U-C76TSHew8JjOVy-c,247
15
+ tinybird/tb/__cli__.py,sha256=Bncibdl66_JHCDwjy6-b6gYfCvP97569anD3Ydq_nmo,247
16
16
  tinybird/tb/check_pypi.py,sha256=rW4QmDRbtgKdUUwJCnBkVjmTjZSZGN-XgZhx7vMkC0w,1009
17
17
  tinybird/tb/cli.py,sha256=u3eGOhX0MHkuT6tiwaZ0_3twqLmqKXDAOxF7yV_Nn9Q,1075
18
18
  tinybird/tb/client.py,sha256=CSBl_JRuioPyY0H8Ac96dJ9wQXDXfrvK2lwqlOxKGoY,55715
@@ -26,7 +26,7 @@ tinybird/tb/modules/connection.py,sha256=7oOR7x4PhBcm1ETFFCH2YJ_3oeGXjAbmx1cnZX9
26
26
  tinybird/tb/modules/copy.py,sha256=2Mm4FWKehOG7CoOhiF1m9UZJgJn0W1_cMolqju8ONYg,5805
27
27
  tinybird/tb/modules/create.py,sha256=OHUvuHuvP0iecPPGI4eVOHOgR20qy7a_Sw7sbJKuG8g,17411
28
28
  tinybird/tb/modules/datasource.py,sha256=V314rkpdVxVMjsp5qcSCTqDlmp4Vu--qM07BoWh-aqs,17783
29
- tinybird/tb/modules/deployment.py,sha256=pnW2DAVTZYHEOJDbBH6uv0_Y7UV_6adq6q_r5w8miXI,26073
29
+ tinybird/tb/modules/deployment.py,sha256=BAvZy8ghdIwK_eH8J6eJ0W69U2TPtvRmtIThYc2cvOQ,26255
30
30
  tinybird/tb/modules/deprecations.py,sha256=rrszC1f_JJeJ8mUxGoCxckQTJFBCR8wREf4XXXN-PRc,4507
31
31
  tinybird/tb/modules/dev_server.py,sha256=57FCKuWpErwYUYgHspYDkLWEm9F4pbvVOtMrFXX1fVU,10129
32
32
  tinybird/tb/modules/endpoint.py,sha256=XySDt3pk66vxOZ0egUfz4bY8bEk3BjOXkv-L0OIJ3sc,12083
@@ -38,7 +38,7 @@ tinybird/tb/modules/job.py,sha256=n4dSSBgnA8NqD7srGahf2xRj6wxkmX9Vl0J-QJ_a2w0,29
38
38
  tinybird/tb/modules/llm.py,sha256=KfsCYmKeW1VQz0iDZhGKCRkQv_Y3kTHh6JuxvofOguE,1076
39
39
  tinybird/tb/modules/llm_utils.py,sha256=nS9r4FAElJw8yXtmdYrx-rtI2zXR8qXfi1QqUDCfxvg,3469
40
40
  tinybird/tb/modules/local.py,sha256=SUaGWH9TLDFFF9uCw4y7UW4NsKgnXG8uxTcxz1dbkCM,14230
41
- tinybird/tb/modules/local_common.py,sha256=9KP8ZrDhFHxTgXoqTnF348D0uof9JugjC-RIN2d9Mh8,4896
41
+ tinybird/tb/modules/local_common.py,sha256=4GHb7h26iTT02vF_eExsLQM26BGgHF_qTpmDKmxK6nY,14216
42
42
  tinybird/tb/modules/login.py,sha256=fmXPSdvJnKPv03chptGuu3_Fm6LhP6kUsUKhrmT8rJc,8269
43
43
  tinybird/tb/modules/logout.py,sha256=ULooy1cDBD02-r7voZmhV7udA0ML5tVuflJyShrh56Y,1022
44
44
  tinybird/tb/modules/materialization.py,sha256=QJX5kCPhhm6IXBO1JsalVfbQdypCe_eOUDZ_WHJZWS8,5478
@@ -51,7 +51,7 @@ tinybird/tb/modules/secret.py,sha256=WsqzxxLh9W_jkuHL2JofMXdIJy0lT5WEI-7bQSIDgAc
51
51
  tinybird/tb/modules/shell.py,sha256=Zd_4Ak_5tKVX-cw6B4ag36xZeEGHeh-jZpAsIXkoMoE,14116
52
52
  tinybird/tb/modules/table.py,sha256=4XrtjM-N0zfNtxVkbvLDQQazno1EPXnxTyo7llivfXk,11035
53
53
  tinybird/tb/modules/telemetry.py,sha256=X0p5AVkM8BNsK_Rhdcg4p2eIf6OHimHO_VLldBqHQ8o,11386
54
- tinybird/tb/modules/test.py,sha256=Yopg89cRwOQpgRzsb9nvu2Z-UR2as2vBjVa5PF3uiK0,13420
54
+ tinybird/tb/modules/test.py,sha256=891Br7sgRk88Zqqj4UQHWbdIK7aI7QY2wpAaBscPxRw,13134
55
55
  tinybird/tb/modules/token.py,sha256=2fmKwu10_M0pqs6YmJVeILR9ZQB0ejRAET86agASbKM,13488
56
56
  tinybird/tb/modules/watch.py,sha256=H1FieLTVGRqmZ0hR0vELbQJ9l0CThrFCgGCta-MPuAY,8883
57
57
  tinybird/tb/modules/workspace.py,sha256=-XUvL2PB5GcviJ8m30h-ZDc5kwJcm1wy1dreYa2l4Ck,10658
@@ -80,8 +80,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
80
80
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
81
81
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
82
82
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
83
- tinybird-0.0.1.dev165.dist-info/METADATA,sha256=WfcrvDPMsy_ogA0thcGWuXqgd7DIe3zU0eA-2v6XR3E,1607
84
- tinybird-0.0.1.dev165.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
85
- tinybird-0.0.1.dev165.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
86
- tinybird-0.0.1.dev165.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
87
- tinybird-0.0.1.dev165.dist-info/RECORD,,
83
+ tinybird-0.0.1.dev166.dist-info/METADATA,sha256=BAITivfECM2Is3v12uYS8vUupGPgcXdLunIaqiQ3WEQ,1607
84
+ tinybird-0.0.1.dev166.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
85
+ tinybird-0.0.1.dev166.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
86
+ tinybird-0.0.1.dev166.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
87
+ tinybird-0.0.1.dev166.dist-info/RECORD,,