tinybird-cli 5.7.1.dev0__tar.gz → 5.8.0.dev0__tar.gz

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.
Files changed (46) hide show
  1. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/PKG-INFO +6 -1
  2. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/__cli__.py +2 -2
  3. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/client.py +28 -0
  4. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/datafile.py +171 -27
  5. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/feedback_manager.py +4 -0
  6. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird_cli.egg-info/PKG-INFO +6 -1
  7. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/setup.cfg +0 -0
  8. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/ch_utils/constants.py +0 -0
  9. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/ch_utils/engine.py +0 -0
  10. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/check_pypi.py +0 -0
  11. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/config.py +0 -0
  12. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/connectors.py +0 -0
  13. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/context.py +0 -0
  14. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/datatypes.py +0 -0
  15. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/git_settings.py +0 -0
  16. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/sql.py +0 -0
  17. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/sql_template.py +0 -0
  18. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/sql_template_fmt.py +0 -0
  19. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/sql_toolset.py +0 -0
  20. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/syncasync.py +0 -0
  21. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli.py +0 -0
  22. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/auth.py +0 -0
  23. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/branch.py +0 -0
  24. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/cicd.py +0 -0
  25. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/cli.py +0 -0
  26. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/common.py +0 -0
  27. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/config.py +0 -0
  28. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/connection.py +0 -0
  29. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/datasource.py +0 -0
  30. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/exceptions.py +0 -0
  31. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/job.py +0 -0
  32. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/pipe.py +0 -0
  33. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/regions.py +0 -0
  34. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/telemetry.py +0 -0
  35. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/test.py +0 -0
  36. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/tinyunit/tinyunit.py +0 -0
  37. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py +0 -0
  38. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/token.py +0 -0
  39. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/workspace.py +0 -0
  40. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tb_cli_modules/workspace_members.py +0 -0
  41. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird/tornado_template.py +0 -0
  42. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird_cli.egg-info/SOURCES.txt +0 -0
  43. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird_cli.egg-info/dependency_links.txt +0 -0
  44. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird_cli.egg-info/entry_points.txt +0 -0
  45. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird_cli.egg-info/requires.txt +0 -0
  46. {tinybird-cli-5.7.1.dev0 → tinybird-cli-5.8.0.dev0}/tinybird_cli.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tinybird-cli
3
- Version: 5.7.1.dev0
3
+ Version: 5.8.0.dev0
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird
@@ -18,6 +18,11 @@ The Tinybird command-line tool allows you to use all the Tinybird functionality
18
18
  Changelog
19
19
  ----------
20
20
 
21
+ 5.8.0.dev0
22
+ ***********
23
+
24
+ - `Added` support to `TAGS` in `tb pull` and `tb push`. Allows tagging resources for filtering in the UI.
25
+
21
26
  5.7.0
22
27
  **********
23
28
 
@@ -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__ = '5.7.1.dev0'
8
- __revision__ = '2608aa4'
7
+ __version__ = '5.8.0.dev0'
8
+ __revision__ = 'ea7486c'
@@ -1210,3 +1210,31 @@ class TinyB(object):
1210
1210
 
1211
1211
  async def check_auth_login(self) -> Dict[str, Any]:
1212
1212
  return await self._req("/v0/auth")
1213
+
1214
+ async def get_all_tags(self) -> Dict[str, Any]:
1215
+ return await self._req("/v0/tags")
1216
+
1217
+ async def create_tag_with_resource(self, name: str, resourceId: str, resourceName: str, resource_type: str):
1218
+ return await self._req(
1219
+ "/v0/tags",
1220
+ method="POST",
1221
+ headers={"Content-Type": "application/json"},
1222
+ data=json.dumps(
1223
+ {
1224
+ "name": name,
1225
+ "resources": [{"id": resourceId, "name": resourceName, "type": resource_type}],
1226
+ }
1227
+ ),
1228
+ )
1229
+
1230
+ async def update_tag(self, name: str, resources: List[Dict[str, Any]]):
1231
+ await self._req(
1232
+ f"/v0/tags/{name}",
1233
+ method="PUT",
1234
+ headers={"Content-Type": "application/json"},
1235
+ data=json.dumps(
1236
+ {
1237
+ "resources": resources,
1238
+ }
1239
+ ),
1240
+ )
@@ -760,6 +760,7 @@ class Datafile:
760
760
  self.includes: Dict[str, Any] = {}
761
761
  self.shared_with: List[str] = []
762
762
  self.warnings: List[str] = []
763
+ self.filtering_tags: Optional[List[str]] = None
763
764
 
764
765
  def validate(self) -> None:
765
766
  for x in self.nodes:
@@ -903,6 +904,32 @@ def eval_var(s: str, skip: bool = False) -> str:
903
904
  return Template(s).safe_substitute(os.environ)
904
905
 
905
906
 
907
+ def parse_tags(tags: str) -> Tuple[Dict[str, str], List[str]]:
908
+ """
909
+ Parses a string of tags into:
910
+ - kv_tags: a dictionary of key-value tags: the previous tags we have for operational purposes. They
911
+ have the format key=value&key2=value2 (with_staging=true&with_last_date=true)
912
+ - filtering_tags: a list of tags that are used for filtering.
913
+
914
+ Example: "with_staging=true&with_last_date=true,billing,stats" ->
915
+ kv_tags = {"with_staging": "true", "with_last_date": "true"}
916
+ filtering_tags = ["billing", "stats"]
917
+ """
918
+ kv_tags = {}
919
+ filtering_tags = []
920
+
921
+ entries = tags.split(",")
922
+ for entry in entries:
923
+ trimmed_entry = entry.strip()
924
+ if "=" in trimmed_entry:
925
+ the_tags = {k: v[0] for k, v in urllib.parse.parse_qs(trimmed_entry).items()}
926
+ kv_tags.update(the_tags)
927
+ else:
928
+ filtering_tags.append(trimmed_entry)
929
+
930
+ return kv_tags, filtering_tags
931
+
932
+
906
933
  def parse(
907
934
  s: str,
908
935
  default_node: Optional[str] = None,
@@ -1100,6 +1127,16 @@ def parse(
1100
1127
 
1101
1128
  return _f
1102
1129
 
1130
+ def tags(*args: str, **kwargs: Any) -> None:
1131
+ # Pipe nodes or Data Sources
1132
+ if parser_state.current_node:
1133
+ assign_node_var("tags")(*args, **kwargs)
1134
+ else:
1135
+ # Pipes, at pipe level
1136
+ raw_tags = _unquote((" ".join(args)).strip())
1137
+ _, filtering_tags = parse_tags(raw_tags)
1138
+ doc.filtering_tags = filtering_tags
1139
+
1103
1140
  cmds = {
1104
1141
  "from": assign("from"),
1105
1142
  "source": sources,
@@ -1120,7 +1157,7 @@ def parse(
1120
1157
  "description": description,
1121
1158
  "type": assign_node_var("type"),
1122
1159
  "datasource": assign_node_var("datasource"),
1123
- "tags": assign_node_var("tags"),
1160
+ "tags": tags,
1124
1161
  "target_datasource": assign_node_var("target_datasource"),
1125
1162
  "copy_schedule": assign_node_var(CopyParameters.COPY_SCHEDULE),
1126
1163
  "copy_mode": assign_node_var("mode"),
@@ -1515,8 +1552,9 @@ async def process_file(
1515
1552
  del params["format"]
1516
1553
 
1517
1554
  if "tags" in node:
1518
- tags = {k: v[0] for k, v in urllib.parse.parse_qs(node["tags"]).items()}
1555
+ tags, filtering_tags = parse_tags(node["tags"])
1519
1556
  params.update(tags)
1557
+ doc.filtering_tags = filtering_tags
1520
1558
 
1521
1559
  resources: List[Dict[str, Any]] = []
1522
1560
 
@@ -1530,6 +1568,7 @@ async def process_file(
1530
1568
  "deps": deps,
1531
1569
  "tokens": doc.tokens,
1532
1570
  "shared_with": doc.shared_with,
1571
+ "filtering_tags": doc.filtering_tags,
1533
1572
  }
1534
1573
  )
1535
1574
 
@@ -1615,7 +1654,7 @@ async def process_file(
1615
1654
  sql = re.sub("([\t \\n']+|^)" + old + "([\t \\n'\\)]+|$)", "\\1" + new + "\\2", sql)
1616
1655
 
1617
1656
  if "tags" in node:
1618
- tags = {k: v[0] for k, v in urllib.parse.parse_qs(node["tags"]).items()}
1657
+ tags, _ = parse_tags(node["tags"]) # Only interested in the "old" tags
1619
1658
  params.update(tags)
1620
1659
 
1621
1660
  nodes.append(
@@ -1638,6 +1677,7 @@ async def process_file(
1638
1677
  "tokens": doc.tokens,
1639
1678
  "description": description,
1640
1679
  "warnings": doc.warnings,
1680
+ "filtering_tags": doc.filtering_tags,
1641
1681
  }
1642
1682
  ]
1643
1683
  elif DataFileExtensions.TOKEN in filename:
@@ -2646,6 +2686,107 @@ def show_materialized_view_warnings(warnings):
2646
2686
  )
2647
2687
 
2648
2688
 
2689
+ async def update_tags(resourceId: str, resourceName: str, resource_type: str, tags: List[str], tb_client: TinyB):
2690
+ def get_tags_for_resource(all_tags: dict, resource_id: str, resource_name: str) -> List[str]:
2691
+ tag_names = []
2692
+
2693
+ for tag in all_tags.get("tags", []):
2694
+ for resource in tag.get("resources", []):
2695
+ if resource.get("id") == resource_id or resource.get("name") == resource_name:
2696
+ tag_names.append(tag.get("name"))
2697
+ break # No need to check other resources in this tag
2698
+
2699
+ return tag_names
2700
+
2701
+ def get_tag(all_tags: dict, tag_name: str) -> Optional[dict]:
2702
+ for tag in all_tags.get("tags", []):
2703
+ if tag.get("name") == tag_name:
2704
+ return tag
2705
+ return None
2706
+
2707
+ def compare_tags(current_tags: List[str], new_tags: List[str]) -> Tuple[List[str], List[str]]:
2708
+ tags_to_add = list(set(new_tags) - set(current_tags))
2709
+ tags_to_remove = list(set(current_tags) - set(new_tags))
2710
+ return tags_to_add, tags_to_remove
2711
+
2712
+ try:
2713
+ all_tags = await tb_client.get_all_tags()
2714
+ except Exception as e:
2715
+ raise Exception(FeedbackManager.error_getting_tags(error=str(e)))
2716
+
2717
+ # Get all tags of that resource
2718
+ current_tags = get_tags_for_resource(all_tags, resourceId, resourceName)
2719
+
2720
+ # Get the tags to add and remove
2721
+ tags_to_add, tags_to_remove = compare_tags(current_tags, tags)
2722
+
2723
+ # Tags to add
2724
+ for tag_name in tags_to_add:
2725
+ tag = get_tag(all_tags, tag_name)
2726
+
2727
+ if not tag:
2728
+ # Create new tag
2729
+ try:
2730
+ await tb_client.create_tag_with_resource(tag_name, resourceId, resourceName, resource_type)
2731
+ except Exception as e:
2732
+ raise Exception(FeedbackManager.error_creating_tag(error=str(e)))
2733
+ else:
2734
+ # Update tag with new resource
2735
+ resources = tag.get("resources", [])
2736
+ resources.append({"id": resourceId, "name": resourceName, "type": resource_type})
2737
+ try:
2738
+ await tb_client.update_tag(tag.get("name", tag_name), resources)
2739
+ except Exception as e:
2740
+ raise Exception(FeedbackManager.error_updating_tag(error=str(e)))
2741
+
2742
+ # Tags to delete
2743
+ for tag_name in tags_to_remove:
2744
+ tag = get_tag(all_tags, tag_name)
2745
+
2746
+ if tag:
2747
+ resources = tag.get("resources", [])
2748
+ resources = [resource for resource in resources if resource.get("name") != resourceName]
2749
+ try:
2750
+ await tb_client.update_tag(tag.get("name", tag_name), resources)
2751
+ except Exception as e:
2752
+ raise Exception(FeedbackManager.error_updating_tag(error=str(e)))
2753
+
2754
+
2755
+ async def update_tags_in_resource(rs: Dict[str, Any], resource_type: str, client: TinyB):
2756
+ filtering_tags = rs.get("filtering_tags", [])
2757
+
2758
+ if not filtering_tags:
2759
+ return
2760
+
2761
+ resource_id = ""
2762
+ resource_name = ""
2763
+
2764
+ if resource_type == "datasource":
2765
+ ds_name = rs["params"]["name"]
2766
+ try:
2767
+ persisted_ds = await client.get_datasource(ds_name)
2768
+ resource_id = persisted_ds.get("id", "")
2769
+ resource_name = persisted_ds.get("name", "")
2770
+ except DoesNotExistException:
2771
+ click.echo(
2772
+ FeedbackManager.error_tag_generic("Could not get the latest Data Source info for updating its tags.")
2773
+ )
2774
+ elif resource_type == "pipe":
2775
+ pipe_name = rs["name"]
2776
+ try:
2777
+ persisted_pipe = await client.pipe(pipe_name)
2778
+ resource_id = persisted_pipe.get("id", "")
2779
+ resource_name = persisted_pipe.get("name", "")
2780
+ except DoesNotExistException:
2781
+ click.echo(FeedbackManager.error_tag_generic("Could not get the latest Pipe info for updating its tags."))
2782
+
2783
+ if resource_id and resource_name:
2784
+ try:
2785
+ await update_tags(resource_id, resource_name, resource_type, filtering_tags, client)
2786
+ except Exception as e:
2787
+ click.echo(FeedbackManager.error_tag_generic(error=str(e)))
2788
+
2789
+
2649
2790
  async def get_token_from_main_branch(branch_tb_client: TinyB) -> Optional[str]:
2650
2791
  token_from_main_branch = None
2651
2792
  current_workspace = await branch_tb_client.workspace_info()
@@ -3289,32 +3430,33 @@ async def new_ds(
3289
3430
 
3290
3431
  if alter_response and make_changes:
3291
3432
  # alter operation finished
3292
- return
3293
- # removed replacing by default. When a datasource is removed data is
3294
- # removed and all the references needs to be updated
3295
- if (
3296
- os.getenv("TB_I_KNOW_WHAT_I_AM_DOING")
3297
- and click.prompt(FeedbackManager.info_ask_for_datasource_confirmation()) == ds_name
3298
- ): # TODO move to CLI
3299
- try:
3300
- await client.datasource_delete(ds_name)
3301
- click.echo(FeedbackManager.success_delete_datasource(datasource=ds_name))
3302
- except Exception:
3303
- raise click.ClickException(FeedbackManager.error_removing_datasource(datasource=ds_name))
3304
- return
3433
+ pass
3305
3434
  else:
3306
- if alter_error_message:
3307
- raise click.ClickException(
3308
- FeedbackManager.error_datasource_already_exists_and_alter_failed(
3309
- datasource=ds_name, alter_error_message=alter_error_message
3310
- )
3311
- )
3312
- if promote_error_message:
3313
- raise click.ClickException(
3314
- FeedbackManager.error_promoting_datasource(datasource=ds_name, error=promote_error_message)
3315
- )
3435
+ # removed replacing by default. When a datasource is removed data is
3436
+ # removed and all the references needs to be updated
3437
+ if (
3438
+ os.getenv("TB_I_KNOW_WHAT_I_AM_DOING")
3439
+ and click.prompt(FeedbackManager.info_ask_for_datasource_confirmation()) == ds_name
3440
+ ): # TODO move to CLI
3441
+ try:
3442
+ await client.datasource_delete(ds_name)
3443
+ click.echo(FeedbackManager.success_delete_datasource(datasource=ds_name))
3444
+ except Exception:
3445
+ raise click.ClickException(FeedbackManager.error_removing_datasource(datasource=ds_name))
3446
+ return
3316
3447
  else:
3317
- click.echo(FeedbackManager.warning_datasource_already_exists(datasource=ds_name))
3448
+ if alter_error_message:
3449
+ raise click.ClickException(
3450
+ FeedbackManager.error_datasource_already_exists_and_alter_failed(
3451
+ datasource=ds_name, alter_error_message=alter_error_message
3452
+ )
3453
+ )
3454
+ if promote_error_message:
3455
+ raise click.ClickException(
3456
+ FeedbackManager.error_promoting_datasource(datasource=ds_name, error=promote_error_message)
3457
+ )
3458
+ else:
3459
+ click.echo(FeedbackManager.warning_datasource_already_exists(datasource=ds_name))
3318
3460
 
3319
3461
 
3320
3462
  async def new_token(token: Dict[str, Any], client: TinyB, force: bool = False):
@@ -3400,6 +3542,7 @@ async def exec_file(
3400
3542
  fork_downstream=fork_downstream,
3401
3543
  fork=fork,
3402
3544
  )
3545
+ await update_tags_in_resource(r, "pipe", tb_client)
3403
3546
  elif r["resource"] == "datasources":
3404
3547
  await new_ds(
3405
3548
  r,
@@ -3412,6 +3555,7 @@ async def exec_file(
3412
3555
  fork=fork,
3413
3556
  git_release=git_release,
3414
3557
  )
3558
+ await update_tags_in_resource(r, "datasource", tb_client)
3415
3559
  elif r["resource"] == "tokens":
3416
3560
  await new_token(r, tb_client, force)
3417
3561
  else:
@@ -392,6 +392,10 @@ class FeedbackManager:
392
392
  "Several materialized nodes in pipe {pipe}. Use --node param."
393
393
  )
394
394
  error_unlinking_pipe_not_linked = error_message("** {pipe} is not linked (MV, Copy, or Sink).")
395
+ error_getting_tags = error_message("Error getting tags: {error}")
396
+ error_creating_tag = error_message("Error creating new tag: {error}")
397
+ error_updating_tag = error_message("Error updating tag: {error}")
398
+ error_tag_generic = error_message("There was an issue updating tags. {error}")
395
399
 
396
400
  info_incl_relative_path = info_message("** Relative path {path} does not exist, skipping.")
397
401
  info_ignoring_incl_file = info_message(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tinybird-cli
3
- Version: 5.7.1.dev0
3
+ Version: 5.8.0.dev0
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird
@@ -18,6 +18,11 @@ The Tinybird command-line tool allows you to use all the Tinybird functionality
18
18
  Changelog
19
19
  ----------
20
20
 
21
+ 5.8.0.dev0
22
+ ***********
23
+
24
+ - `Added` support to `TAGS` in `tb pull` and `tb push`. Allows tagging resources for filtering in the UI.
25
+
21
26
  5.7.0
22
27
  **********
23
28