tinybird 0.0.1.dev169__py3-none-any.whl → 0.0.1.dev171__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.dev169'
8
- __revision__ = '0e591e6'
7
+ __version__ = '0.0.1.dev171'
8
+ __revision__ = 'a5eb91f'
@@ -71,6 +71,9 @@ VERSION = f"{__cli__.__version__} (rev {__cli__.__revision__})"
71
71
  @click.option("--show-tokens", is_flag=True, default=False, help="Enable the output of tokens.")
72
72
  @click.option("--cloud/--local", is_flag=True, default=False, help="Run against cloud or local.")
73
73
  @click.option("--staging", is_flag=True, default=False, help="Run against a staging deployment.")
74
+ @click.option(
75
+ "--output", type=click.Choice(["json", "human"], case_sensitive=False), default="human", help="Output format"
76
+ )
74
77
  @click.version_option(version=VERSION)
75
78
  @click.pass_context
76
79
  @coro
@@ -84,15 +87,19 @@ async def cli(
84
87
  show_tokens: bool,
85
88
  cloud: bool,
86
89
  staging: bool,
90
+ output: str,
87
91
  ) -> None:
88
92
  """
89
93
  Use `OBFUSCATE_REGEX_PATTERN` and `OBFUSCATE_PATTERN_SEPARATOR` environment variables to define a regex pattern and a separator (in case of a single string with multiple regex) to obfuscate secrets in the CLI output.
90
94
  """
91
95
  # We need to unpatch for our tests not to break
92
- if show_tokens or not cloud or ctx.invoked_subcommand == "build":
93
- __unpatch_click_output()
96
+ if output == "json":
97
+ __hide_click_output()
94
98
  else:
95
- __patch_click_output()
99
+ if show_tokens or not cloud or ctx.invoked_subcommand == "build":
100
+ __unpatch_click_output()
101
+ else:
102
+ __patch_click_output()
96
103
 
97
104
  if getenv_bool("TB_DISABLE_SSL_CHECKS", False):
98
105
  click.echo(FeedbackManager.warning_disabled_ssl_checks())
@@ -167,6 +174,7 @@ async def cli(
167
174
 
168
175
  ctx.ensure_object(dict)["project"] = project
169
176
  ctx.ensure_object(dict)["env"] = get_target_env(cloud)
177
+ ctx.ensure_object(dict)["output"] = output
170
178
 
171
179
 
172
180
  @cli.command(hidden=True)
@@ -316,6 +324,24 @@ def __unpatch_click_output():
316
324
  click.secho = __old_click_secho
317
325
 
318
326
 
327
+ def __hide_click_output() -> None:
328
+ """
329
+ Modify click.echo and click.secho to only output when explicitly requested.
330
+ Adds a 'force_output' parameter to both functions that defaults to False.
331
+ """
332
+
333
+ def silent_echo(msg: Any, *args: Any, force_output: bool = False, **kwargs: Any) -> None:
334
+ if force_output:
335
+ __old_click_echo(msg, *args, **kwargs)
336
+
337
+ def silent_secho(msg: Any, *args: Any, force_output: bool = False, **kwargs: Any) -> None:
338
+ if force_output:
339
+ __old_click_secho(msg, *args, **kwargs)
340
+
341
+ click.echo = silent_echo # type: ignore
342
+ click.secho = silent_secho # type: ignore
343
+
344
+
319
345
  async def create_ctx_client(ctx: Context, config: Dict[str, Any], cloud: bool, staging: bool):
320
346
  commands_without_ctx_client = [
321
347
  "auth",
@@ -2227,3 +2227,7 @@ def get_error_event(error: str) -> Tuple[str, str]:
2227
2227
  error_event = "error"
2228
2228
  silent_error_msg = "Unknown error"
2229
2229
  return error_event, silent_error_msg
2230
+
2231
+
2232
+ def echo_json(data: Dict[str, Any]) -> None:
2233
+ click.echo(json.dumps(data), force_output=True) # type: ignore
@@ -435,13 +435,8 @@ def save_context(prompt: str, feedback: str):
435
435
 
436
436
 
437
437
  def get_resources_xml(project: Project) -> str:
438
- folder = project.folder
439
- datasource_paths = [
440
- Path(folder) / "datasources" / f for f in os.listdir(Path(folder) / "datasources") if f.endswith(".datasource")
441
- ]
442
- pipes_paths = [
443
- Path(folder) / "endpoints" / f for f in os.listdir(Path(folder) / "endpoints") if f.endswith(".pipe")
444
- ]
438
+ datasource_paths = [Path(f) for f in project.get_datasource_files()]
439
+ pipes_paths = [Path(f) for f in project.get_pipe_files()]
445
440
  resources_xml = "\n".join(
446
441
  [
447
442
  f"<resource><type>{resource_type}</type><name>{resource_name}</name><content>{resource_content}</content></resource>"
@@ -1,12 +1,12 @@
1
1
  import os
2
- from typing import Any, Dict, Iterable, List, Optional
2
+ from typing import Any, Dict, Iterable, List, Optional, Tuple
3
3
 
4
4
  import click
5
5
 
6
6
  from tinybird.tb.client import TinyB
7
7
  from tinybird.tb.config import get_display_cloud_host
8
8
  from tinybird.tb.modules.cli import CLIConfig, cli
9
- from tinybird.tb.modules.common import coro, format_robust_table
9
+ from tinybird.tb.modules.common import coro, echo_json, format_robust_table
10
10
  from tinybird.tb.modules.feedback_manager import FeedbackManager
11
11
  from tinybird.tb.modules.local_common import TB_LOCAL_ADDRESS, get_tinybird_local_config
12
12
  from tinybird.tb.modules.project import Project
@@ -19,15 +19,29 @@ async def info(ctx: click.Context) -> None:
19
19
  """Get information about the project that is currently being used"""
20
20
  ctx_config = ctx.ensure_object(dict)["config"]
21
21
  project: Project = ctx.ensure_object(dict)["project"]
22
+ is_json = ctx.ensure_object(dict)["output"] == "json"
22
23
  click.echo(FeedbackManager.highlight(message="» Tinybird Cloud:"))
23
- await get_cloud_info(ctx_config)
24
+ cloud_table, cloud_columns = await get_cloud_info(ctx_config)
24
25
  click.echo(FeedbackManager.highlight(message="\n» Tinybird Local:"))
25
- await get_local_info(ctx_config)
26
+ local_table, local_columns = await get_local_info(ctx_config)
26
27
  click.echo(FeedbackManager.highlight(message="\n» Project:"))
27
- await get_project_info(project.folder)
28
+ project_table, project_columns = await get_project_info(project.folder)
29
+ if is_json:
30
+ cloud_data = {}
31
+ if cloud_columns and cloud_table and isinstance(cloud_table, list) and len(cloud_table) > 0:
32
+ cloud_data = {column: cloud_table[0][i] for i, column in enumerate(cloud_columns)}
28
33
 
34
+ local_data = {}
35
+ if local_columns and local_table and isinstance(local_table, list) and len(local_table) > 0:
36
+ local_data = {column: local_table[0][i] for i, column in enumerate(local_columns)}
29
37
 
30
- async def get_cloud_info(ctx_config: Dict[str, Any]) -> None:
38
+ project_data = {}
39
+ if project_columns and project_table and isinstance(project_table, list) and len(project_table) > 0:
40
+ project_data = {column: project_table[0][i] for i, column in enumerate(project_columns)}
41
+ echo_json({"cloud": cloud_data, "local": local_data, "project": project_data})
42
+
43
+
44
+ async def get_cloud_info(ctx_config: Dict[str, Any]) -> Tuple[Iterable[Any], List[str]]:
31
45
  config = CLIConfig.get_project_config()
32
46
 
33
47
  try:
@@ -37,16 +51,17 @@ async def get_cloud_info(ctx_config: Dict[str, Any]) -> None:
37
51
  ui_host = get_display_cloud_host(api_host)
38
52
  user_email = config.get("user_email") or "No user email found"
39
53
  user_token = config.get_user_token() or "No user token found"
40
- await get_env_info(client, ctx_config, user_email, token, user_token, api_host, ui_host)
54
+ return await get_env_info(client, ctx_config, user_email, token, user_token, api_host, ui_host)
41
55
  except Exception:
42
56
  click.echo(
43
57
  FeedbackManager.warning(
44
58
  message="\n⚠ Could not retrieve Tinybird Cloud info. Please run `tb login` first or check that you are located in the correct directory."
45
59
  )
46
60
  )
61
+ return [], []
47
62
 
48
63
 
49
- async def get_local_info(config: Dict[str, Any]) -> None:
64
+ async def get_local_info(config: Dict[str, Any]) -> Tuple[Iterable[Any], List[str]]:
50
65
  try:
51
66
  local_config = await get_tinybird_local_config(config, test=False, silent=False)
52
67
  local_client = local_config.get_client(host=TB_LOCAL_ADDRESS, staging=False)
@@ -55,19 +70,19 @@ async def get_local_info(config: Dict[str, Any]) -> None:
55
70
  user_token = local_config.get_user_token() or "No user token found"
56
71
  api_host = TB_LOCAL_ADDRESS
57
72
  ui_host = get_display_cloud_host(api_host)
58
- await get_env_info(local_client, config, user_email, token, user_token, api_host, ui_host)
73
+ return await get_env_info(local_client, config, user_email, token, user_token, api_host, ui_host)
59
74
  except Exception:
60
75
  click.echo(
61
76
  FeedbackManager.warning(
62
77
  message="\n⚠ Could not retrieve Tinybird Local info. Please run `tb local start` first."
63
78
  )
64
79
  )
65
- return
80
+ return [], []
66
81
 
67
82
 
68
83
  async def get_env_info(
69
84
  client: TinyB, config: Dict[str, Any], user_email: str, token: str, user_token: str, api_host: str, ui_host: str
70
- ) -> None:
85
+ ) -> Tuple[List[Any], List[str]]:
71
86
  user_workspaces = await client.user_workspaces(version="v1")
72
87
  current_workspace = await client.workspace_info(version="v1")
73
88
 
@@ -94,9 +109,10 @@ async def get_env_info(
94
109
  ]
95
110
 
96
111
  click.echo(format_robust_table(table, column_names=columns))
112
+ return table, columns
97
113
 
98
114
 
99
- async def get_project_info(project_path: Optional[str] = None) -> None:
115
+ async def get_project_info(project_path: Optional[str] = None) -> Tuple[Iterable[Any], List[str]]:
100
116
  config = CLIConfig.get_project_config()
101
117
  tinyb_path = config.get_tinyb_file()
102
118
  current_path = os.getcwd()
@@ -110,3 +126,4 @@ async def get_project_info(project_path: Optional[str] = None) -> None:
110
126
  columns = ["current", ".tinyb", "project"]
111
127
  table: Iterable[Any] = [(current_path, tinyb_path, project_path)]
112
128
  click.echo(format_robust_table(table, column_names=columns))
129
+ return table, columns
@@ -38,32 +38,26 @@ class Project:
38
38
  return None
39
39
  return Path(full_path).relative_to(self.path).as_posix()
40
40
 
41
- def get_vendor_files(self) -> List[str]:
42
- vendor_files: List[str] = []
43
- for project_file in glob.glob(f"{self.vendor_path}/**/*.datasource", recursive=False):
44
- vendor_files.append(project_file)
45
- return vendor_files
46
-
47
41
  @property
48
42
  def datasources(self) -> List[str]:
49
- return sorted([Path(f).stem for f in glob.glob(f"{self.path}/**/*.datasource", recursive=False)])
43
+ return sorted([Path(f).stem for f in self.get_datasource_files()])
50
44
 
51
45
  @property
52
46
  def pipes(self) -> List[str]:
53
- return sorted([Path(f).stem for f in glob.glob(f"{self.path}/**/*.pipe", recursive=False)])
47
+ return sorted([Path(f).stem for f in self.get_pipe_files()])
54
48
 
55
49
  @property
56
50
  def connections(self) -> List[str]:
57
- return sorted([Path(f).stem for f in glob.glob(f"{self.path}/**/*.connection", recursive=False)])
51
+ return sorted([Path(f).stem for f in self.get_connection_files()])
58
52
 
59
53
  def get_datasource_files(self) -> List[str]:
60
- return glob.glob(f"{self.path}/**/*.datasource", recursive=False)
54
+ return glob.glob(f"{self.path}/**/*.datasource", recursive=True)
61
55
 
62
56
  def get_pipe_files(self) -> List[str]:
63
- return glob.glob(f"{self.path}/**/*.pipe", recursive=False)
57
+ return glob.glob(f"{self.path}/**/*.pipe", recursive=True)
64
58
 
65
59
  def get_connection_files(self) -> List[str]:
66
- return glob.glob(f"{self.path}/**/*.connection", recursive=False)
60
+ return glob.glob(f"{self.path}/**/*.connection", recursive=True)
67
61
 
68
62
  def get_pipe_datafile(self, filename: str) -> Optional[Datafile]:
69
63
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev169
3
+ Version: 0.0.1.dev171
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -12,19 +12,19 @@ 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=X4tE9OrfaUy6kO9cqVEzyI9cDcmOF3IAssRRzsTsfEQ,40781
15
- tinybird/tb/__cli__.py,sha256=ZH5ERxlrrIxkPa1I9WBJ4oyLFiovbeyQfBGE3VKBdds,247
15
+ tinybird/tb/__cli__.py,sha256=hKG-5atm5V0pGi635mfMITsiz00-mtLOQQlbU2c3LwA,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=vADGfvo8lOp9-VIYD_d3KVIlcYfQk0ciJawthn-LFaw,14449
23
- tinybird/tb/modules/common.py,sha256=12SMmfOlEwQZGBUR22KNVNdTXhEMc0BjvDJ7bbqhZf4,83122
22
+ tinybird/tb/modules/cli.py,sha256=3gDO1smcH1e2qEvbFCGbo4oNdgubDr3hC3fsKlB4ylY,15373
23
+ tinybird/tb/modules/common.py,sha256=lu1Z3VYImwocaHvqOW2FzBJP6F3Ev7RuXsItkCZ6jpo,83237
24
24
  tinybird/tb/modules/config.py,sha256=ziqW_t_mRVvWOd85VoB4vKyvgMkEfpXDf9H4v38p2xc,11422
25
25
  tinybird/tb/modules/connection.py,sha256=7oOR7x4PhBcm1ETFFCH2YJ_3oeGXjAbmx1cnZX9_L70,9014
26
26
  tinybird/tb/modules/copy.py,sha256=2Mm4FWKehOG7CoOhiF1m9UZJgJn0W1_cMolqju8ONYg,5805
27
- tinybird/tb/modules/create.py,sha256=OHUvuHuvP0iecPPGI4eVOHOgR20qy7a_Sw7sbJKuG8g,17411
27
+ tinybird/tb/modules/create.py,sha256=_s_vdb9pjq1ORajE_gFMxSGVuns1imNgiD5H8KuI2gQ,17231
28
28
  tinybird/tb/modules/datasource.py,sha256=V314rkpdVxVMjsp5qcSCTqDlmp4Vu--qM07BoWh-aqs,17783
29
29
  tinybird/tb/modules/deployment.py,sha256=z2xK8EwKbx_a-rIOxIo3o_IQibcBASOaFfeWWosQFhs,26841
30
30
  tinybird/tb/modules/deprecations.py,sha256=rrszC1f_JJeJ8mUxGoCxckQTJFBCR8wREf4XXXN-PRc,4507
@@ -32,7 +32,7 @@ tinybird/tb/modules/dev_server.py,sha256=57FCKuWpErwYUYgHspYDkLWEm9F4pbvVOtMrFXX
32
32
  tinybird/tb/modules/endpoint.py,sha256=XySDt3pk66vxOZ0egUfz4bY8bEk3BjOXkv-L0OIJ3sc,12083
33
33
  tinybird/tb/modules/exceptions.py,sha256=5jK91w1LPmtqIUfDpHe_Op5OxGz8-p1BPgtLREMIni0,5217
34
34
  tinybird/tb/modules/feedback_manager.py,sha256=c0ZOpG7IHFq3doodezctX64cTcTquIOhO38w9uPuU8Q,76798
35
- tinybird/tb/modules/info.py,sha256=AThOatkAjN1HbmARIU0MaQ-N4ZmZlZqoAxN18FQRa6M,4797
35
+ tinybird/tb/modules/info.py,sha256=iKeFbFkos7vYaBU7Vr5SI-fa1x7AbuUHB748jsGsaA4,5944
36
36
  tinybird/tb/modules/infra.py,sha256=fve30Gj3mG9zbquGxS2e4ipcOYOxviWQCpNFfEzJN_Q,33195
37
37
  tinybird/tb/modules/job.py,sha256=n4dSSBgnA8NqD7srGahf2xRj6wxkmX9Vl0J-QJ_a2w0,2966
38
38
  tinybird/tb/modules/llm.py,sha256=KfsCYmKeW1VQz0iDZhGKCRkQv_Y3kTHh6JuxvofOguE,1076
@@ -45,7 +45,7 @@ tinybird/tb/modules/materialization.py,sha256=QJX5kCPhhm6IXBO1JsalVfbQdypCe_eOUD
45
45
  tinybird/tb/modules/mock.py,sha256=IyHweMUM6bUH8IhyiX2tTMpdVpTFUeAJ41lZ5P42-HQ,5303
46
46
  tinybird/tb/modules/open.py,sha256=OuctINN77oexpSjth9uoIZPCelKO4Li-yyVxeSnk1io,1371
47
47
  tinybird/tb/modules/pipe.py,sha256=AQKEDagO6e3psPVjJkS_MDbn8aK-apAiLp26k7jgAV0,2432
48
- tinybird/tb/modules/project.py,sha256=PwEG8Ob9bW4HZxh1jQq2LyDfIoitqF69Jdu0WsWHMCg,3568
48
+ tinybird/tb/modules/project.py,sha256=yENgJAqRx_eH_n7qalPMWWMZpjEWhAf0CMfGM6ChQrM,3220
49
49
  tinybird/tb/modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
50
50
  tinybird/tb/modules/secret.py,sha256=WsqzxxLh9W_jkuHL2JofMXdIJy0lT5WEI-7bQSIDgAc,2921
51
51
  tinybird/tb/modules/shell.py,sha256=Zd_4Ak_5tKVX-cw6B4ag36xZeEGHeh-jZpAsIXkoMoE,14116
@@ -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.dev169.dist-info/METADATA,sha256=PHcgQ16C8kZsxmtwhnhQMgwRGE5SHb0X8rLHosCD324,1607
84
- tinybird-0.0.1.dev169.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
85
- tinybird-0.0.1.dev169.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
86
- tinybird-0.0.1.dev169.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
87
- tinybird-0.0.1.dev169.dist-info/RECORD,,
83
+ tinybird-0.0.1.dev171.dist-info/METADATA,sha256=DZAvrAPILrw9XpHmGv6LUrVlhFvm7Qy_57YsHR2sA_U,1607
84
+ tinybird-0.0.1.dev171.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
85
+ tinybird-0.0.1.dev171.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
86
+ tinybird-0.0.1.dev171.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
87
+ tinybird-0.0.1.dev171.dist-info/RECORD,,