tinybird 0.0.1.dev161__py3-none-any.whl → 0.0.1.dev163__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.dev161'
8
- __revision__ = '29ac536'
7
+ __version__ = '0.0.1.dev163'
8
+ __revision__ = 'dff38d5'
@@ -317,7 +317,23 @@ def __unpatch_click_output():
317
317
 
318
318
 
319
319
  async def create_ctx_client(ctx: Context, config: Dict[str, Any], cloud: bool, staging: bool):
320
- commands_without_ctx_client = ["auth", "check", "local", "login", "logout", "update", "upgrade", "create", "info"]
320
+ commands_without_ctx_client = [
321
+ "auth",
322
+ "check",
323
+ "local",
324
+ "login",
325
+ "logout",
326
+ "update",
327
+ "upgrade",
328
+ "create",
329
+ "info",
330
+ "tag",
331
+ "push",
332
+ "branch",
333
+ "diff",
334
+ "fmt",
335
+ "init",
336
+ ]
321
337
  command = ctx.invoked_subcommand
322
338
  if command in commands_without_ctx_client:
323
339
  return None
@@ -36,31 +36,7 @@ async def get_tinybird_local_config(config_obj: Dict[str, Any], test: bool = Fal
36
36
  """
37
37
  path = config_obj.get("path")
38
38
  config = CLIConfig.get_project_config()
39
-
40
- try:
41
- # ruff: noqa: ASYNC210
42
- tokens = requests.get(f"{TB_LOCAL_ADDRESS}/tokens").json()
43
- except Exception:
44
- try:
45
- # Check if tinybird-local is running with docker, in case it's a config issue
46
- output = subprocess.check_output(["docker", "ps"], text=True) # noqa: ASYNC221
47
- header_row = next((line for line in output.splitlines() if "CONTAINER ID" in line), "")
48
- tb_local_row = next(
49
- (line for line in output.splitlines() if TB_CONTAINER_NAME in line),
50
- f"{TB_CONTAINER_NAME} not found in output",
51
- )
52
- add_telemetry_event(
53
- "docker_debug",
54
- data={
55
- "docker_ps_output": header_row + tb_local_row,
56
- },
57
- )
58
- except Exception:
59
- pass
60
- raise CLILocalException(
61
- FeedbackManager.error(message="Tinybird local is not running. Please run `tb local start` first.")
62
- )
63
-
39
+ tokens = get_local_tokens()
64
40
  user_token = tokens["user_token"]
65
41
  admin_token = tokens["admin_token"]
66
42
  default_token = tokens["workspace_admin_token"]
@@ -118,3 +94,29 @@ def get_build_workspace_name(path: str) -> str:
118
94
  def get_test_workspace_name(path: str) -> str:
119
95
  folder_hash = hashlib.sha256(path.encode()).hexdigest()
120
96
  return f"Tinybird_Local_Test_{folder_hash}"
97
+
98
+
99
+ def get_local_tokens() -> Dict[str, str]:
100
+ try:
101
+ # ruff: noqa: ASYNC210
102
+ return requests.get(f"{TB_LOCAL_ADDRESS}/tokens").json()
103
+ except Exception:
104
+ try:
105
+ # Check if tinybird-local is running with docker, in case it's a config issue
106
+ output = subprocess.check_output(["docker", "ps"], text=True)
107
+ header_row = next((line for line in output.splitlines() if "CONTAINER ID" in line), "")
108
+ tb_local_row = next(
109
+ (line for line in output.splitlines() if TB_CONTAINER_NAME in line),
110
+ f"{TB_CONTAINER_NAME} not found in output",
111
+ )
112
+ add_telemetry_event(
113
+ "docker_debug",
114
+ data={
115
+ "docker_ps_output": header_row + tb_local_row,
116
+ },
117
+ )
118
+ except Exception:
119
+ pass
120
+ raise CLILocalException(
121
+ FeedbackManager.error(message="Tinybird local is not running. Please run `tb local start` first.")
122
+ )
@@ -6,9 +6,10 @@
6
6
  from typing import Any, Dict, List, Optional
7
7
 
8
8
  import click
9
+ import requests
9
10
  from click import Context
10
11
 
11
- from tinybird.tb.client import TinyB
12
+ from tinybird.tb.client import AuthNoTokenException, TinyB
12
13
  from tinybird.tb.modules.cli import cli
13
14
  from tinybird.tb.modules.common import (
14
15
  _get_workspace_plan_name,
@@ -26,6 +27,10 @@ from tinybird.tb.modules.common import (
26
27
  from tinybird.tb.modules.config import CLIConfig
27
28
  from tinybird.tb.modules.exceptions import CLIWorkspaceException
28
29
  from tinybird.tb.modules.feedback_manager import FeedbackManager
30
+ from tinybird.tb.modules.local_common import (
31
+ TB_LOCAL_ADDRESS,
32
+ get_local_tokens,
33
+ )
29
34
 
30
35
 
31
36
  @cli.group()
@@ -221,3 +226,57 @@ async def delete_workspace(
221
226
  click.echo(FeedbackManager.success_workspace_deleted(workspace_name=workspace_to_delete["name"]))
222
227
  except Exception as e:
223
228
  raise CLIWorkspaceException(FeedbackManager.error_exception(error=str(e)))
229
+
230
+
231
+ @workspace.command(name="clear", short_help="Clear a workspace. Only available against Tinybird Local.")
232
+ @click.option("--yes", is_flag=True, default=False, help="Don't ask for confirmation")
233
+ @click.pass_context
234
+ @coro
235
+ async def workspace_clear(ctx: Context, yes: bool) -> None:
236
+ """Delete a workspace where you are an admin."""
237
+ is_cloud = ctx.ensure_object(dict)["env"] == "cloud"
238
+ if is_cloud:
239
+ raise CLIWorkspaceException(
240
+ FeedbackManager.error(
241
+ message="`tb workspace clear` is not available against Tinybird Cloud. Use `tb --cloud deploy` instead."
242
+ )
243
+ )
244
+ yes = yes or click.confirm(
245
+ FeedbackManager.warning(message="Are you sure you want to clear the workspace? [y/N]:"),
246
+ show_default=False,
247
+ prompt_suffix="",
248
+ )
249
+ if yes:
250
+ await clear_workspace()
251
+
252
+
253
+ async def clear_workspace() -> None:
254
+ config = CLIConfig.get_project_config()
255
+ tokens = get_local_tokens()
256
+
257
+ user_token = tokens["user_token"]
258
+ admin_token = tokens["admin_token"]
259
+ user_client = config.get_client(host=TB_LOCAL_ADDRESS, token=user_token)
260
+ ws_name = config.get("name")
261
+ if not ws_name:
262
+ raise AuthNoTokenException()
263
+
264
+ user_workspaces = requests.get( # noqa: ASYNC210
265
+ f"{TB_LOCAL_ADDRESS}/v1/user/workspaces?with_organization=true&token={admin_token}"
266
+ ).json()
267
+ user_org_id = user_workspaces.get("organization_id", {})
268
+ local_workspaces = user_workspaces.get("workspaces", [])
269
+
270
+ ws = next((ws for ws in local_workspaces if ws["name"] == ws_name), None)
271
+
272
+ if ws:
273
+ requests.delete(f"{TB_LOCAL_ADDRESS}/v1/workspaces/{ws['id']}?token={user_token}&hard_delete_confirmation=yes") # noqa: ASYNC210
274
+ ws = None
275
+
276
+ if not ws:
277
+ await user_client.create_workspace(ws_name, assign_to_organization_id=user_org_id, version="v1")
278
+ user_workspaces = requests.get(f"{TB_LOCAL_ADDRESS}/v1/user/workspaces?token={admin_token}").json() # noqa: ASYNC210
279
+ ws = next((ws for ws in user_workspaces["workspaces"] if ws["name"] == ws_name), None)
280
+
281
+ if ws:
282
+ click.echo(FeedbackManager.success(message=f"\n✓ Workspace '{ws_name}' cleared"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev161
3
+ Version: 0.0.1.dev163
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -12,14 +12,14 @@ 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=E8aXjTvNw5qa6fTVCqpIk7TJE7KKkGYHZ4NJ1NbwTmw,247
15
+ tinybird/tb/__cli__.py,sha256=PeR2Y103-abS6voCkOb0Nk66NulYrLNJHp96nj-rAhg,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
19
19
  tinybird/tb/config.py,sha256=jT9xndpeCY_g0HdB5qE2EquC0TFRRnkPnQFWZWd04jo,3998
20
20
  tinybird/tb/modules/build.py,sha256=zakH5812Lop-XHjGmDRdOPeofPtoeyb_2un_T6e50xw,19177
21
21
  tinybird/tb/modules/cicd.py,sha256=MnShTTJzKBYeajswF2jg7p7ZzupaeCgSriAN05MeEdg,7330
22
- tinybird/tb/modules/cli.py,sha256=jJ7vF05vppwqetaHiEyk_x2YFb6S53PS-PmYlNMRcTc,14274
22
+ tinybird/tb/modules/cli.py,sha256=vADGfvo8lOp9-VIYD_d3KVIlcYfQk0ciJawthn-LFaw,14449
23
23
  tinybird/tb/modules/common.py,sha256=_mNLBzC7zkveYXgJ02aMJ9L3LrxsAELx84GwEYdWNa0,82955
24
24
  tinybird/tb/modules/config.py,sha256=ziqW_t_mRVvWOd85VoB4vKyvgMkEfpXDf9H4v38p2xc,11422
25
25
  tinybird/tb/modules/connection.py,sha256=7oOR7x4PhBcm1ETFFCH2YJ_3oeGXjAbmx1cnZX9_L70,9014
@@ -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=OoBUFrMjXvQ3y8hHscpyVH9wMI7h0m79F7G6EiMSku0,4783
41
+ tinybird/tb/modules/local_common.py,sha256=LutxdEG6AR1k5PrUPsDWGVPrr3mA7AbWKhj4Hlewlic,4837
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
@@ -54,7 +54,7 @@ tinybird/tb/modules/telemetry.py,sha256=X0p5AVkM8BNsK_Rhdcg4p2eIf6OHimHO_VLldBqH
54
54
  tinybird/tb/modules/test.py,sha256=Yopg89cRwOQpgRzsb9nvu2Z-UR2as2vBjVa5PF3uiK0,13420
55
55
  tinybird/tb/modules/token.py,sha256=2fmKwu10_M0pqs6YmJVeILR9ZQB0ejRAET86agASbKM,13488
56
56
  tinybird/tb/modules/watch.py,sha256=H1FieLTVGRqmZ0hR0vELbQJ9l0CThrFCgGCta-MPuAY,8883
57
- tinybird/tb/modules/workspace.py,sha256=h4Re1_2DahZ9C-yF7vgquMrYiG7Gj62jNfbzkEJR2BY,8066
57
+ tinybird/tb/modules/workspace.py,sha256=v9o4ImrEOxLhCYhVGtJ-slek8DGOW0cJGn7F91DMmj4,10390
58
58
  tinybird/tb/modules/workspace_members.py,sha256=RYLpyPM1ECCasHRg3uvpckzXplX0_KgNFsSPZn_i6qk,8744
59
59
  tinybird/tb/modules/datafile/build.py,sha256=d_h3pRFDPFrDKGhpFx2iejY25GuB2k8yfNouj6s8caw,50973
60
60
  tinybird/tb/modules/datafile/build_common.py,sha256=LU24kAQmxDJIyoIapDaYG-SU3P4FrMG9UBf8m9PgVSI,4565
@@ -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.dev161.dist-info/METADATA,sha256=zcXNbkwS4Ut4VaoEViYVtbi9qS0bQ82ra-c_nzjJ2pA,1607
84
- tinybird-0.0.1.dev161.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
85
- tinybird-0.0.1.dev161.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
86
- tinybird-0.0.1.dev161.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
87
- tinybird-0.0.1.dev161.dist-info/RECORD,,
83
+ tinybird-0.0.1.dev163.dist-info/METADATA,sha256=2RhhimAjREyciOOUnO8pJ2Yw-HxEsDfGOZlYfgtIYNM,1607
84
+ tinybird-0.0.1.dev163.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
85
+ tinybird-0.0.1.dev163.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
86
+ tinybird-0.0.1.dev163.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
87
+ tinybird-0.0.1.dev163.dist-info/RECORD,,