tinybird 0.0.1.dev73__py3-none-any.whl → 0.0.1.dev75__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/cli/introduction.html'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '0.0.1.dev73'
8
- __revision__ = 'a843588'
7
+ __version__ = '0.0.1.dev75'
8
+ __revision__ = '0985575'
@@ -7,6 +7,7 @@ import time
7
7
  from functools import partial
8
8
  from pathlib import Path
9
9
  from typing import Callable, Optional
10
+ from urllib.parse import urlencode
10
11
 
11
12
  import click
12
13
  import requests
@@ -191,6 +192,7 @@ def show_data(tb_client: TinyB, filename: str, diff: Optional[str] = None):
191
192
  table_name = diff
192
193
  resource_path = Path(filename)
193
194
  resource_name = resource_path.stem
195
+ resource_content = resource_path.read_text()
194
196
 
195
197
  pipeline = resource_name if filename.endswith(".pipe") else None
196
198
 
@@ -201,6 +203,17 @@ def show_data(tb_client: TinyB, filename: str, diff: Optional[str] = None):
201
203
 
202
204
  res = asyncio.run(tb_client.query(sql, pipeline=pipeline))
203
205
  print_table_formatted(res, table_name)
206
+ if Project.is_endpoint(resource_content):
207
+ example_params = {
208
+ "format": "json",
209
+ "pipe": resource_name,
210
+ "q": "",
211
+ "token": tb_client.token,
212
+ }
213
+ endpoint_url = asyncio.run(tb_client._req(f"/examples/query.http?{urlencode(example_params)}"))
214
+ if endpoint_url:
215
+ endpoint_url = endpoint_url.replace("http://localhost:8001", tb_client.host)
216
+ click.echo(FeedbackManager.gray(message="\nTest endpoint at ") + FeedbackManager.info(message=endpoint_url))
204
217
 
205
218
 
206
219
  def process(
@@ -1,5 +1,4 @@
1
1
  import json
2
- import logging
3
2
  from copy import deepcopy
4
3
  from typing import Any, Dict, List, Optional, Set
5
4
  from urllib.parse import urlencode
@@ -9,7 +8,7 @@ import requests
9
8
  from croniter import croniter
10
9
 
11
10
  from tinybird.client import DoesNotExistException, TinyB
12
- from tinybird.tb.modules.common import requests_delete, requests_get, wait_job
11
+ from tinybird.tb.modules.common import requests_delete, requests_get
13
12
  from tinybird.tb.modules.config import CLIConfig
14
13
  from tinybird.tb.modules.datafile.common import ON_DEMAND, CopyModes, CopyParameters, PipeNodeTypes, PipeTypes
15
14
  from tinybird.tb.modules.exceptions import CLIPipeException
@@ -66,50 +65,10 @@ async def new_pipe(
66
65
  current_pipe = next((play for play in playgrounds if play["name"] == p["name"] + "__tb__playground"), None)
67
66
  pipe_exists = current_pipe is not None
68
67
 
69
- is_materialized = any([node.get("params", {}).get("type", None) == "materialized" for node in p["nodes"]])
70
- copy_node = next((node for node in p["nodes"] if node.get("params", {}).get("type", None) == "copy"), None)
71
- sink_node = next((node for node in p["nodes"] if node.get("params", {}).get("type", None) == "sink"), None)
72
- stream_node = next((node for node in p["nodes"] if node.get("params", {}).get("type", None) == "stream"), None)
73
-
74
68
  for node in p["nodes"]:
75
69
  if node["params"]["name"] == p["name"]:
76
70
  raise click.ClickException(FeedbackManager.error_pipe_node_same_name(name=p["name"]))
77
71
 
78
- if pipe_exists:
79
- if force or run_tests:
80
- # TODO: this should create a different node and rename it to the final one on success
81
- if check and not populate:
82
- if not is_materialized and not copy_node and not sink_node and not stream_node:
83
- pass
84
- else:
85
- if is_materialized:
86
- await check_materialized(
87
- p,
88
- host,
89
- token,
90
- tb_client,
91
- override_datasource=override_datasource,
92
- current_pipe=current_pipe,
93
- )
94
- if copy_node:
95
- await check_copy_pipe(pipe=current_pipe, copy_node=copy_node, tb_client=tb_client)
96
- if sink_node:
97
- await check_sink_pipe(pipe=current_pipe, sink_node=sink_node, tb_client=tb_client)
98
- if stream_node:
99
- await check_stream_pipe(pipe=current_pipe, stream_node=stream_node, tb_client=tb_client)
100
- if run_tests:
101
- logging.info(f"skipping force override of {p['name']}")
102
- return
103
- else:
104
- raise click.ClickException(FeedbackManager.error_pipe_already_exists(pipe=p["name"]))
105
- elif not pipe_exists and check:
106
- if is_materialized:
107
- await check_materialized(
108
- p, host, token, tb_client, override_datasource=override_datasource, current_pipe=current_pipe
109
- )
110
- if copy_node:
111
- await check_copy_pipe(pipe=current_pipe, copy_node=copy_node, tb_client=tb_client)
112
-
113
72
  params = {}
114
73
  params.update(cli_params)
115
74
  if force:
@@ -136,17 +95,6 @@ async def new_pipe(
136
95
  if p["nodes"]:
137
96
  body["nodes"] = [parse_node(n) for n in p["nodes"]]
138
97
 
139
- if copy_node:
140
- body["target_datasource"] = copy_node.get("target_datasource", None)
141
- # We will update the schedule cron later
142
- body["schedule_cron"] = None
143
-
144
- if sink_node:
145
- body.update(sink_node.get("export_params", {}))
146
-
147
- if stream_node:
148
- body.update(stream_node.get("export_params", {}))
149
-
150
98
  post_headers = {"Content-Type": "application/json"}
151
99
 
152
100
  post_headers.update(headers)
@@ -176,71 +124,6 @@ async def new_pipe(
176
124
  except Exception as e:
177
125
  raise click.ClickException(FeedbackManager.error_pushing_pipe(pipe=p["name"], error=str(e)))
178
126
 
179
- datasource = data.get("datasource", None)
180
-
181
- if datasource and populate and not copy_node:
182
- job_url = data.get("job", {}).get("job_url", None)
183
- job_id = data.get("job", {}).get("job_id", None)
184
- if populate_subset:
185
- click.echo(FeedbackManager.info_populate_subset_job_url(url=job_url, subset=populate_subset))
186
- elif populate_condition:
187
- click.echo(
188
- FeedbackManager.info_populate_condition_job_url(url=job_url, populate_condition=populate_condition)
189
- )
190
- else:
191
- click.echo(FeedbackManager.info_populate_job_url(url=job_url))
192
-
193
- if wait_populate:
194
- result = await wait_job(tb_client, job_id, job_url, "Populating")
195
- click.echo(FeedbackManager.info_populate_job_result(result=result))
196
- else:
197
- if data.get("type") == "default" and not skip_tokens and not as_standard and not copy_node and not sink_node:
198
- # FIXME: set option to add last node as endpoint in the API
199
- endpoint_node = next(
200
- (node for node in data.get("nodes", []) if node.get("type") == "endpoint"), data.get("nodes", [])[-1]
201
- )
202
- try:
203
- data = await tb_client._req(
204
- f"/v0/pipes/{p['name']}/nodes/{endpoint_node.get('id')}/endpoint?{urlencode(cli_params)}",
205
- method="POST",
206
- headers=headers,
207
- )
208
- except Exception as e:
209
- raise Exception(
210
- FeedbackManager.error_creating_endpoint(
211
- node=endpoint_node.get("name"), pipe=p["name"], error=str(e)
212
- )
213
- )
214
-
215
- if copy_node:
216
- pipe_id = data["id"]
217
- node = next((node for node in data["nodes"] if node["node_type"] == "copy"), None)
218
- if node:
219
- copy_params = {"pipe_name_or_id": pipe_id, "node_id": node["id"]}
220
- try:
221
- target_datasource = copy_node.get(CopyParameters.TARGET_DATASOURCE, None)
222
- schedule_cron = copy_node.get(CopyParameters.COPY_SCHEDULE, None)
223
- mode = copy_node.get("mode", CopyModes.APPEND)
224
- schedule_cron = None if schedule_cron == ON_DEMAND else schedule_cron
225
- current_target_datasource_id = data["copy_target_datasource"]
226
- target_datasource_response = await tb_client.get_datasource(target_datasource)
227
- target_datasource_to_send = (
228
- target_datasource
229
- if target_datasource_response.get("id", target_datasource) != current_target_datasource_id
230
- else None
231
- )
232
- copy_params[CopyParameters.TARGET_DATASOURCE] = target_datasource_to_send
233
- current_schedule = data.get("schedule", {})
234
- current_schedule_cron = current_schedule.get("cron", None) if current_schedule else None
235
- schedule_cron_should_be_removed = current_schedule_cron and not schedule_cron
236
- copy_params["schedule_cron"] = "None" if schedule_cron_should_be_removed else schedule_cron
237
- copy_params["mode"] = mode
238
- await tb_client.pipe_update_copy(**copy_params)
239
- except Exception as e:
240
- raise Exception(
241
- FeedbackManager.error_setting_copy_node(node=copy_node.get("name"), pipe=p["name"], error=str(e))
242
- )
243
-
244
127
  if p["tokens"] and not skip_tokens and not as_standard and data.get("type") in ["endpoint", "copy"]:
245
128
  # search for token with specified name and adds it if not found or adds permissions to it
246
129
  t = None
@@ -339,36 +339,34 @@ def create_deployment(
339
339
  result = r.json()
340
340
  logging.debug(json.dumps(result, indent=2))
341
341
 
342
- if check:
343
- print_changes(result, project)
344
- feedback = result.get("deployment", {}).get("feedback", [])
345
- for f in feedback:
342
+ print_changes(result, project)
343
+
344
+ feedback = result.get("deployment", {}).get("feedback", [])
345
+ for f in feedback:
346
+ click.echo(FeedbackManager.warning(message=f"△ {f.get('level')}: {f.get('resource')}: {f.get('message')}"))
347
+
348
+ deploy_errors = result.get("deployment", {}).get("errors")
349
+ for deploy_error in deploy_errors:
350
+ if deploy_error.get("filename", None):
346
351
  click.echo(
347
- FeedbackManager.warning(message=f"{f.get('level')}: {f.get('resource')}: {f.get('message')}")
352
+ FeedbackManager.error(message=f"{deploy_error.get('filename')}\n\n{deploy_error.get('error')}")
348
353
  )
354
+ else:
355
+ click.echo(FeedbackManager.error(message=f"{deploy_error.get('error')}"))
349
356
 
350
- status = result.get("result")
357
+ status = result.get("result")
358
+ if check:
351
359
  if status == "success":
352
360
  click.echo(FeedbackManager.success(message="\n✓ Deployment is valid"))
353
- else:
354
- click.echo(FeedbackManager.error(message="\n✗ Deployment is not valid"))
355
- deploy_errors = result.get("errors")
356
- for deploy_error in deploy_errors:
357
- if deploy_error.get("filename", None):
358
- click.echo(
359
- FeedbackManager.error(
360
- message=f"{deploy_error.get('filename')}\n\n{deploy_error.get('error')}"
361
- )
362
- )
363
- else:
364
- click.echo(FeedbackManager.error(message=f"{deploy_error.get('error')}"))
365
- return
366
-
367
- deploy_result = result.get("result")
368
- if deploy_result == "success":
369
- print_changes(result, project)
361
+ sys.exit(0)
362
+
363
+ click.echo(FeedbackManager.error(message="\n✗ Deployment is not valid"))
364
+ sys.exit(1)
365
+
366
+ status = result.get("result")
367
+ if status == "success":
370
368
  deployment = result.get("deployment", {})
371
- # We show the url in the case of region is public
369
+ # TODO: This is a hack to show the url in the case of region is public. The URL should be returned by the API
372
370
  if client.host == "https://api.europe-west2.gcp.tinybird.co":
373
371
  click.echo(
374
372
  FeedbackManager.gray(message="Deployment URL: ")
@@ -381,25 +379,10 @@ def create_deployment(
381
379
  click.echo(FeedbackManager.info(message="\n✓ Deployment submitted successfully"))
382
380
  else:
383
381
  click.echo(FeedbackManager.success(message="\n✓ Deployment submitted successfully"))
384
-
385
- feedback = deployment.get("feedback", [])
386
- for f in feedback:
387
- click.echo(
388
- FeedbackManager.warning(message=f"△ {f.get('level')}: {f.get('resource')}: {f.get('message')}")
389
- )
390
-
391
- elif deploy_result == "failed":
382
+ elif status == "failed":
392
383
  click.echo(FeedbackManager.error(message="Deployment failed"))
393
- deploy_errors = result.get("errors")
394
- for deploy_error in deploy_errors:
395
- if deploy_error.get("filename", None):
396
- click.echo(
397
- FeedbackManager.error(message=f"{deploy_error.get('filename')}\n\n{deploy_error.get('error')}")
398
- )
399
- else:
400
- click.echo(FeedbackManager.error(message=f"{deploy_error.get('error')}"))
401
384
  else:
402
- click.echo(FeedbackManager.error(message=f"Unknown build result {deploy_result}"))
385
+ click.echo(FeedbackManager.error(message=f"Unknown build result {status}"))
403
386
  except Exception as e:
404
387
  click.echo(FeedbackManager.error_exception(error=e))
405
388
  finally:
@@ -1,5 +1,6 @@
1
1
  import glob
2
2
  import os
3
+ import re
3
4
  from pathlib import Path
4
5
  from typing import Dict, List, Optional
5
6
 
@@ -78,3 +79,7 @@ class Project:
78
79
  if datafile := self.get_datafile(filename):
79
80
  datafiles[filename] = datafile
80
81
  return datafiles
82
+
83
+ @staticmethod
84
+ def is_endpoint(content: str) -> bool:
85
+ return re.search(r"TYPE endpoint", content, re.IGNORECASE) is not None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev73
3
+ Version: 0.0.1.dev75
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird
@@ -15,10 +15,10 @@ tinybird/syncasync.py,sha256=IPnOx6lMbf9SNddN1eBtssg8vCLHMt76SuZ6YNYm-Yk,27761
15
15
  tinybird/tornado_template.py,sha256=KmW_VD7y-NVqrc8YZKwIaxoJB0XpCcB2izdmxmtmApM,41944
16
16
  tinybird/ch_utils/constants.py,sha256=aYvg2C_WxYWsnqPdZB1ZFoIr8ZY-XjUXYyHKE9Ansj0,3890
17
17
  tinybird/ch_utils/engine.py,sha256=AUAww-KjGOZg9h0IBlKA3FeacJYB4rOtqcTGJhFM-g8,40392
18
- tinybird/tb/__cli__.py,sha256=iBIkon30EHUzmwm7ZXmeuOtNqm--pBPvxefxoQQVbV0,251
18
+ tinybird/tb/__cli__.py,sha256=LaZ0t3yKRxZPnxqu6aulgUkaZqP4XBsgCCpRHBVb650,251
19
19
  tinybird/tb/cli.py,sha256=KpJ_-V6xVEzcdPRPnHhEdh2EgRPCyhZnfJVqeqMsftI,964
20
20
  tinybird/tb/modules/auth.py,sha256=vBA-KsrjAp77kFunGSM-4o7AFdfO7ac4dnrHKrx0alI,9020
21
- tinybird/tb/modules/build.py,sha256=mbhb-3Ga5zJx64_QkUzt-TSwKxr0jqcr8X93HZ3Am5k,9693
21
+ tinybird/tb/modules/build.py,sha256=LBLyO5bVzqOegop459-V2QM1s48yMJu2GBSWBSio_u0,10323
22
22
  tinybird/tb/modules/cicd.py,sha256=Eyut5VsOtXq5hK9g_nGCJ2epfEMDDy2cX3kI0NPJZZA,5355
23
23
  tinybird/tb/modules/cli.py,sha256=zCVzffD3YIWB9y06SUf8Ir51R_mejLVTRnwi0SONNxk,16240
24
24
  tinybird/tb/modules/common.py,sha256=f5yKjb1dgUzR-SrC4UHnpHXYIu6INcTHwNO96jW8A9w,73201
@@ -26,7 +26,7 @@ tinybird/tb/modules/config.py,sha256=mxUMLWnELkxgpWJAbAS6o0PXsL2fpG0ogdaZgr3xjvU
26
26
  tinybird/tb/modules/copy.py,sha256=MAVqKip8_QhOYq99U_XuqSO6hCLJEh5sFtbhcXtI3SI,5802
27
27
  tinybird/tb/modules/create.py,sha256=I01JDENOyGKK0Umd2_1Om_nFGP8Uk9vxaOw7PygK02o,12302
28
28
  tinybird/tb/modules/datasource.py,sha256=dNCK9iCR2xPLfwqqwg2ixyE6NuoVEiJU2mBZBmOYrVY,16906
29
- tinybird/tb/modules/deployment.py,sha256=LDFhUaC6QO7KVxtkaXOccRsksntrxladgGe-jMXlGFg,17407
29
+ tinybird/tb/modules/deployment.py,sha256=umfWZA95WPRPUsJh8wSBj7Av_PevphWF6skJ1-lvnW8,16556
30
30
  tinybird/tb/modules/endpoint.py,sha256=EhVoGAXsFz-83Fiwj1gI-I73iRRvL49d0W81un7hvPE,12080
31
31
  tinybird/tb/modules/exceptions.py,sha256=4A2sSjCEqKUMqpP3WI00zouCWW4uLaghXXLZBSw04mY,3363
32
32
  tinybird/tb/modules/feedback_manager.py,sha256=Lv5MBGWNbIFTIy4nNSi0c61bmiQRv5J0nHRiiXUqDuc,68478
@@ -41,7 +41,7 @@ tinybird/tb/modules/materialization.py,sha256=r8Q9HXcYEmfrEzP4WpiasCKDJdSkTPaAKJ
41
41
  tinybird/tb/modules/mock.py,sha256=ASJTm4p11vkevGXCvU0h57aw7Inx03CTdxd5o2uzd8k,3870
42
42
  tinybird/tb/modules/pipe.py,sha256=gcLz0qHgwKDLsWFY3yFLO9a0ETAV1dFbI8YeLHi9460,2429
43
43
  tinybird/tb/modules/playground.py,sha256=PKQKROen8sV7MaeMlxi2lIqZ8B14Sz2LgqjVMbBh0pk,4801
44
- tinybird/tb/modules/project.py,sha256=QdOG65Hcc6r_eQ938CfZeIXyp38RkiTYNPupgqy2gP0,2948
44
+ tinybird/tb/modules/project.py,sha256=YnrfDBenrzXCPO99qOtsTE21SP2vAb3FqBv6NV9Yw2g,3099
45
45
  tinybird/tb/modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
46
46
  tinybird/tb/modules/shell.py,sha256=bhp5pOw4T_4p4XamWEoGJYRgrr5MREzZN8E36aYrb5U,13924
47
47
  tinybird/tb/modules/table.py,sha256=4XrtjM-N0zfNtxVkbvLDQQazno1EPXnxTyo7llivfXk,11035
@@ -55,7 +55,7 @@ tinybird/tb/modules/workspace_members.py,sha256=Vb5XEaKmkfONyfg2MS5EcpwolMvv7GLw
55
55
  tinybird/tb/modules/datafile/build.py,sha256=seGFSvmgyRrAM1-icsKBkuog3WccfGUYFTPT-xoA5W8,50940
56
56
  tinybird/tb/modules/datafile/build_common.py,sha256=rT7VJ5mnQ68R_8US91DAtkusfvjWuG_NObOzNgtN_ko,4562
57
57
  tinybird/tb/modules/datafile/build_datasource.py,sha256=VjxaKKLZhPYt3XHOyMmfoqEAWAPI5D78T-8FOaN77MY,17355
58
- tinybird/tb/modules/datafile/build_pipe.py,sha256=-22_657DiZodJ7shSu7KvwE_m6bHesNITdUgCMniuBI,22202
58
+ tinybird/tb/modules/datafile/build_pipe.py,sha256=KSlLAXsli0k3W-LTFMmaWNRCpgchHltJBjN2_ZkX7As,16223
59
59
  tinybird/tb/modules/datafile/common.py,sha256=1sKkQnyKOaFARQzORncpL6cRVpV9GDOD4oC36daX-Hk,79343
60
60
  tinybird/tb/modules/datafile/diff.py,sha256=-0J7PsBO64T7LOZSkZ4ZFHHCPvT7cKItnJkbz2PkndU,6754
61
61
  tinybird/tb/modules/datafile/exceptions.py,sha256=8rw2umdZjtby85QbuRKFO5ETz_eRHwUY5l7eHsy1wnI,556
@@ -76,8 +76,8 @@ tinybird/tb_cli_modules/config.py,sha256=6u6B5QCdiQLbJkCkwtnKGs9H3nP-KXXhC75mF7B
76
76
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
77
77
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
78
78
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
79
- tinybird-0.0.1.dev73.dist-info/METADATA,sha256=I6j5vki_YHU9gwqs-jelfWHO3t1CcN4h9xF3REtlqH8,2585
80
- tinybird-0.0.1.dev73.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
81
- tinybird-0.0.1.dev73.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
82
- tinybird-0.0.1.dev73.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
83
- tinybird-0.0.1.dev73.dist-info/RECORD,,
79
+ tinybird-0.0.1.dev75.dist-info/METADATA,sha256=COmCCDyvvYeoOKvdYYmo8KPcoRZWtr6rqYcvZEcLLSY,2585
80
+ tinybird-0.0.1.dev75.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
81
+ tinybird-0.0.1.dev75.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
82
+ tinybird-0.0.1.dev75.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
83
+ tinybird-0.0.1.dev75.dist-info/RECORD,,