tinybird 0.0.1.dev5__py3-none-any.whl → 0.0.1.dev6__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.

Files changed (41) hide show
  1. tinybird/__cli__.py +7 -8
  2. tinybird/tb/cli.py +28 -0
  3. tinybird/{tb_cli_modules → tb/modules}/auth.py +5 -5
  4. tinybird/{tb_cli_modules → tb/modules}/branch.py +6 -5
  5. tinybird/{tb_cli_modules → tb/modules}/build.py +8 -8
  6. tinybird/tb/modules/cicd.py +271 -0
  7. tinybird/{tb_cli_modules → tb/modules}/cli.py +23 -23
  8. tinybird/tb/modules/common.py +2098 -0
  9. tinybird/tb/modules/config.py +352 -0
  10. tinybird/{tb_cli_modules → tb/modules}/connection.py +4 -4
  11. tinybird/{tb_cli_modules → tb/modules}/create.py +11 -7
  12. tinybird/{datafile.py → tb/modules/datafile.py} +6 -7
  13. tinybird/{tb_cli_modules → tb/modules}/datasource.py +7 -6
  14. tinybird/tb/modules/exceptions.py +91 -0
  15. tinybird/{tb_cli_modules → tb/modules}/fmt.py +3 -3
  16. tinybird/{tb_cli_modules → tb/modules}/job.py +3 -3
  17. tinybird/{tb_cli_modules → tb/modules}/llm.py +1 -1
  18. tinybird/{tb_cli_modules → tb/modules}/local.py +9 -5
  19. tinybird/{tb_cli_modules → tb/modules}/mock.py +5 -5
  20. tinybird/{tb_cli_modules → tb/modules}/pipe.py +5 -5
  21. tinybird/tb/modules/regions.py +9 -0
  22. tinybird/{tb_cli_modules → tb/modules}/tag.py +2 -2
  23. tinybird/tb/modules/telemetry.py +310 -0
  24. tinybird/{tb_cli_modules → tb/modules}/test.py +5 -5
  25. tinybird/{tb_cli_modules → tb/modules}/tinyunit/tinyunit.py +1 -1
  26. tinybird/{tb_cli_modules → tb/modules}/token.py +3 -3
  27. tinybird/{tb_cli_modules → tb/modules}/workspace.py +5 -5
  28. tinybird/{tb_cli_modules → tb/modules}/workspace_members.py +4 -4
  29. tinybird/tb_cli_modules/common.py +9 -25
  30. tinybird/tb_cli_modules/config.py +0 -8
  31. {tinybird-0.0.1.dev5.dist-info → tinybird-0.0.1.dev6.dist-info}/METADATA +1 -1
  32. tinybird-0.0.1.dev6.dist-info/RECORD +58 -0
  33. tinybird-0.0.1.dev6.dist-info/entry_points.txt +2 -0
  34. tinybird/tb_cli.py +0 -28
  35. tinybird-0.0.1.dev5.dist-info/RECORD +0 -52
  36. tinybird-0.0.1.dev5.dist-info/entry_points.txt +0 -2
  37. /tinybird/{tb_cli_modules → tb/modules}/prompts.py +0 -0
  38. /tinybird/{tb_cli_modules → tb/modules}/table.py +0 -0
  39. /tinybird/{tb_cli_modules → tb/modules}/tinyunit/tinyunit_lib.py +0 -0
  40. {tinybird-0.0.1.dev5.dist-info → tinybird-0.0.1.dev6.dist-info}/WHEEL +0 -0
  41. {tinybird-0.0.1.dev5.dist-info → tinybird-0.0.1.dev6.dist-info}/top_level.txt +0 -0
tinybird/__cli__.py CHANGED
@@ -1,8 +1,7 @@
1
-
2
- __name__ = 'tinybird'
3
- __description__ = 'Tinybird Command Line Tool'
4
- __url__ = 'https://www.tinybird.co/docs/cli/introduction.html'
5
- __author__ = 'Tinybird'
6
- __author_email__ = 'support@tinybird.co'
7
- __version__ = '0.0.1.dev5'
8
- __revision__ = 'b69dd20'
1
+ __name__ = "tinybird-cli"
2
+ __description__ = "Tinybird Command Line Tool"
3
+ __url__ = "https://www.tinybird.co/docs/cli/introduction.html"
4
+ __author__ = "Tinybird"
5
+ __author_email__ = "support@tinybird.co"
6
+ __version__ = "x.y.z"
7
+ __revision__ = "xxxxxxxxx"
tinybird/tb/cli.py ADDED
@@ -0,0 +1,28 @@
1
+ import asyncio
2
+ import sys
3
+
4
+ if sys.platform == "win32":
5
+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
6
+
7
+ import tinybird.tb.modules.auth
8
+ import tinybird.tb.modules.branch
9
+ import tinybird.tb.modules.build
10
+ import tinybird.tb.modules.cli
11
+ import tinybird.tb.modules.common
12
+ import tinybird.tb.modules.connection
13
+ import tinybird.tb.modules.create
14
+ import tinybird.tb.modules.datasource
15
+ import tinybird.tb.modules.fmt
16
+ import tinybird.tb.modules.job
17
+ import tinybird.tb.modules.mock
18
+ import tinybird.tb.modules.pipe
19
+ import tinybird.tb.modules.tag
20
+ import tinybird.tb.modules.test
21
+ import tinybird.tb.modules.token
22
+ import tinybird.tb.modules.workspace
23
+ import tinybird.tb.modules.workspace_members
24
+
25
+ cli = tinybird.tb.modules.cli.cli
26
+
27
+ if __name__ == "__main__":
28
+ cli()
@@ -11,8 +11,8 @@ import humanfriendly.tables
11
11
 
12
12
  from tinybird.config import get_display_host
13
13
  from tinybird.feedback_manager import FeedbackManager
14
- from tinybird.tb_cli_modules.cli import cli
15
- from tinybird.tb_cli_modules.common import (
14
+ from tinybird.tb.modules.cli import cli
15
+ from tinybird.tb.modules.common import (
16
16
  configure_connector,
17
17
  coro,
18
18
  echo_safe_humanfriendly_tables_format_smart_table,
@@ -21,9 +21,9 @@ from tinybird.tb_cli_modules.common import (
21
21
  try_authenticate,
22
22
  try_update_config_with_remote,
23
23
  )
24
- from tinybird.tb_cli_modules.config import CLIConfig, ConfigValueOrigin
25
- from tinybird.tb_cli_modules.exceptions import CLIAuthException
26
- from tinybird.tb_cli_modules.regions import Region
24
+ from tinybird.tb.modules.config import CLIConfig, ConfigValueOrigin
25
+ from tinybird.tb.modules.exceptions import CLIAuthException
26
+ from tinybird.tb.modules.regions import Region
27
27
 
28
28
 
29
29
  @cli.group(invoke_without_command=True)
@@ -11,10 +11,9 @@ import aiofiles
11
11
  import click
12
12
  import yaml
13
13
 
14
- from tinybird.datafile import create_release, wait_job
15
14
  from tinybird.feedback_manager import FeedbackManager
16
- from tinybird.tb_cli_modules.cli import cli
17
- from tinybird.tb_cli_modules.common import (
15
+ from tinybird.tb.modules.cli import cli
16
+ from tinybird.tb.modules.common import (
18
17
  MAIN_BRANCH,
19
18
  OLDEST_ROLLBACK,
20
19
  coro,
@@ -35,9 +34,11 @@ from tinybird.tb_cli_modules.common import (
35
34
  switch_to_workspace_by_user_workspace_data,
36
35
  switch_workspace,
37
36
  try_update_config_with_remote,
37
+ wait_job,
38
38
  )
39
- from tinybird.tb_cli_modules.config import CLIConfig
40
- from tinybird.tb_cli_modules.exceptions import CLIBranchException, CLIException, CLIReleaseException
39
+ from tinybird.tb.modules.config import CLIConfig
40
+ from tinybird.tb.modules.datafile import create_release
41
+ from tinybird.tb.modules.exceptions import CLIBranchException, CLIException, CLIReleaseException
41
42
 
42
43
 
43
44
  @cli.group(hidden=True)
@@ -13,7 +13,12 @@ from watchdog.observers import Observer
13
13
  import tinybird.context as context
14
14
  from tinybird.client import TinyB
15
15
  from tinybird.config import FeatureFlags
16
- from tinybird.datafile import (
16
+ from tinybird.feedback_manager import FeedbackManager, bcolors
17
+ from tinybird.tb.modules.cli import cli
18
+ from tinybird.tb.modules.common import (
19
+ coro,
20
+ )
21
+ from tinybird.tb.modules.datafile import (
17
22
  ParseException,
18
23
  folder_build,
19
24
  get_project_filenames,
@@ -21,15 +26,10 @@ from tinybird.datafile import (
21
26
  parse_datasource,
22
27
  parse_pipe,
23
28
  )
24
- from tinybird.feedback_manager import FeedbackManager, bcolors
25
- from tinybird.tb_cli_modules.cli import cli
26
- from tinybird.tb_cli_modules.common import (
27
- coro,
28
- )
29
- from tinybird.tb_cli_modules.local import (
29
+ from tinybird.tb.modules.local import (
30
30
  get_tinybird_local_client,
31
31
  )
32
- from tinybird.tb_cli_modules.table import format_table
32
+ from tinybird.tb.modules.table import format_table
33
33
 
34
34
 
35
35
  class FileChangeHandler(FileSystemEventHandler):
@@ -0,0 +1,271 @@
1
+ from enum import Enum
2
+ from os import getcwd
3
+ from pathlib import Path
4
+ from typing import Any, Dict, List, Optional, Type, Union
5
+
6
+ import click
7
+ from tornado.template import Template
8
+
9
+ from tinybird.feedback_manager import FeedbackManager
10
+
11
+
12
+ class Provider(Enum):
13
+ GitHub = 0
14
+ GitLab = 1
15
+
16
+
17
+ WORKFLOW_VERSION = "v3.1.0"
18
+
19
+ DEFAULT_REQUIREMENTS_FILE = "tinybird-cli>=5,<6"
20
+
21
+ GITHUB_CI_YML = """
22
+ name: Tinybird - CI Workflow
23
+
24
+ on:
25
+ workflow_dispatch:
26
+ pull_request:
27
+ branches:
28
+ - main
29
+ - master
30
+ types: [opened, reopened, labeled, unlabeled, synchronize, closed]{% if data_project_dir != '.' %}
31
+ paths:
32
+ - '{{ data_project_dir }}/**'{% end %}
33
+
34
+ concurrency: ${{! github.workflow }}-${{! github.event.pull_request.number }}
35
+
36
+ jobs:
37
+ ci:
38
+ runs-on: ubuntu-latest
39
+ defaults:
40
+ run:
41
+ working-directory: '{{ data_project_dir }}'
42
+ services:
43
+ tinybird:
44
+ image: tinybirdco/tinybird-local:latest
45
+ ports:
46
+ - 80:80
47
+ steps:
48
+ - uses: actions/checkout@v3
49
+ - name: Install Tinybird CLI
50
+ run: curl -LsSf https://api.tinybird.co/static/install.sh | sh
51
+ - name: Build project
52
+ run: tb build
53
+ """
54
+
55
+
56
+ GITLAB_YML = """
57
+ include:
58
+ - local: .gitlab/tinybird/*.yml
59
+
60
+ stages:
61
+ - tests
62
+ """
63
+
64
+
65
+ GITLAB_CI_YML = """
66
+ tinybird_ci_workflow:
67
+ stage: tests
68
+ interruptible: true
69
+ needs: []
70
+ rules:
71
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"{% if data_project_dir != '.' %}
72
+ changes:
73
+ - .gitlab/tinybird/*
74
+ - {{ data_project_dir }}/*
75
+ - {{ data_project_dir }}/**/*{% end %}
76
+ before_script:
77
+ - curl -LsSf https://api.tinybird.co/static/install.sh | sh
78
+ script:
79
+ - cd $CI_PROJECT_DIR/{{ data_project_dir }}
80
+ - tb build
81
+ services:
82
+ - name: tinybirdco/tinybird-local:latest
83
+ alias: tinybird-local
84
+ """
85
+
86
+
87
+ EXEC_TEST_SH = """
88
+ #!/usr/bin/env bash
89
+ set -euxo pipefail
90
+
91
+ export TB_VERSION_WARNING=0
92
+
93
+ run_test() {
94
+ t=$1
95
+ echo "** Running $t **"
96
+ echo "** $(cat $t)"
97
+ tmpfile=$(mktemp)
98
+ retries=0
99
+ TOTAL_RETRIES=3
100
+
101
+ # When appending fixtures, we need to retry in case of the data is not replicated in time
102
+ while [ $retries -lt $TOTAL_RETRIES ]; do
103
+ # Run the test and store the output in a temporary file
104
+ bash $t $2 >$tmpfile
105
+ exit_code=$?
106
+ if [ "$exit_code" -eq 0 ]; then
107
+ # If the test passed, break the loop
108
+ if diff -B ${t}.result $tmpfile >/dev/null 2>&1; then
109
+ break
110
+ # If the test failed, increment the retries counter and try again
111
+ else
112
+ retries=$((retries+1))
113
+ fi
114
+ # If the bash command failed, print an error message and break the loop
115
+ else
116
+ break
117
+ fi
118
+ done
119
+
120
+ if diff -B ${t}.result $tmpfile >/dev/null 2>&1; then
121
+ echo "✅ Test $t passed"
122
+ rm $tmpfile
123
+ return 0
124
+ elif [ $retries -eq $TOTAL_RETRIES ]; then
125
+ echo "🚨 ERROR: Test $t failed, diff:";
126
+ diff -B ${t}.result $tmpfile
127
+ rm $tmpfile
128
+ return 1
129
+ else
130
+ echo "🚨 ERROR: Test $t failed with bash command exit code $?"
131
+ cat $tmpfile
132
+ rm $tmpfile
133
+ return 1
134
+ fi
135
+ echo ""
136
+ }
137
+ export -f run_test
138
+
139
+ fail=0
140
+ find ./tests -name "*.test" -print0 | xargs -0 -I {} -P 4 bash -c 'run_test "$@"' _ {} || fail=1
141
+
142
+ if [ $fail == 1 ]; then
143
+ exit -1;
144
+ fi
145
+ """
146
+
147
+ APPEND_FIXTURES_SH = """
148
+ #!/usr/bin/env bash
149
+ set -euxo pipefail
150
+
151
+ directory="datasources/fixtures"
152
+ extensions=("csv" "ndjson")
153
+
154
+ absolute_directory=$(realpath "$directory")
155
+
156
+ for extension in "${extensions[@]}"; do
157
+ file_list=$(find "$absolute_directory" -type f -name "*.$extension")
158
+
159
+ for file_path in $file_list; do
160
+ file_name=$(basename "$file_path")
161
+ file_name_without_extension="${file_name%.*}"
162
+
163
+ command="tb datasource append $file_name_without_extension datasources/fixtures/$file_name"
164
+ echo $command
165
+ $command
166
+ done
167
+ done
168
+ """
169
+
170
+
171
+ class CICDFile:
172
+ def __init__(
173
+ self,
174
+ template: str,
175
+ file_name: str,
176
+ dir_path: Optional[str] = None,
177
+ warning_message: Optional[str] = None,
178
+ ):
179
+ self.template = template
180
+ self.file_name = file_name
181
+ self.dir_path = dir_path
182
+ self.warning_message = warning_message
183
+
184
+ @property
185
+ def full_path(self) -> str:
186
+ return f"{self.dir_path}/{self.file_name}" if self.dir_path else self.file_name
187
+
188
+
189
+ class CICDGeneratorBase:
190
+ cicd_files: List[CICDFile] = []
191
+
192
+ def __call__(self, path: str, params: Dict[str, Any]):
193
+ for cicd_file in self.cicd_files:
194
+ if cicd_file.dir_path:
195
+ Path(f"{path}/{cicd_file.dir_path}").mkdir(parents=True, exist_ok=True)
196
+ content = Template(cicd_file.template).generate(**params)
197
+ if Path(f"{path}/{cicd_file.full_path}").exists():
198
+ continue
199
+ with open(f"{path}/{cicd_file.full_path}", "wb") as f:
200
+ f.write(content)
201
+ click.echo(FeedbackManager.info_cicd_file_generated(file_path=cicd_file.full_path))
202
+ if cicd_file.warning_message is not None:
203
+ return FeedbackManager.warning_for_cicd_file(
204
+ file_name=cicd_file.file_name, warning_message=cicd_file.warning_message.format(**params)
205
+ )
206
+
207
+ def is_already_generated(self, path: str) -> bool:
208
+ for cicd_file in self.cicd_files:
209
+ if cicd_file.file_name and Path(f"{path}/{cicd_file.full_path}").exists():
210
+ return True
211
+ return False
212
+
213
+ @classmethod
214
+ def build_generator(cls, provider: str) -> Union["GitHubCICDGenerator", "GitLabCICDGenerator"]:
215
+ builder: Dict[str, Union[Type[GitHubCICDGenerator], Type[GitLabCICDGenerator]]] = {
216
+ Provider.GitHub.name: GitHubCICDGenerator,
217
+ Provider.GitLab.name: GitLabCICDGenerator,
218
+ }
219
+ return builder[provider]()
220
+
221
+
222
+ class GitHubCICDGenerator(CICDGeneratorBase):
223
+ cicd_files = [
224
+ CICDFile(
225
+ template=GITHUB_CI_YML,
226
+ file_name="tinybird-ci.yml",
227
+ dir_path=".github/workflows",
228
+ ),
229
+ ]
230
+
231
+
232
+ class GitLabCICDGenerator(CICDGeneratorBase):
233
+ cicd_files = [
234
+ CICDFile(
235
+ template=GITLAB_YML,
236
+ file_name=".gitlab-ci.yml",
237
+ dir_path=".",
238
+ ),
239
+ CICDFile(
240
+ template=GITLAB_CI_YML,
241
+ file_name="tinybird-ci.yml",
242
+ dir_path=".gitlab/tinybird",
243
+ warning_message="Make sure to import the file in your .gitlab-ci.yml file, e.g., `include: '.gitlab/tinybird/*.yml'`.",
244
+ ),
245
+ ]
246
+
247
+
248
+ async def init_cicd(
249
+ path: Optional[str] = None,
250
+ data_project_dir: Optional[str] = None,
251
+ ):
252
+ for provider in Provider:
253
+ path = path if path else getcwd()
254
+ data_project_dir = data_project_dir if data_project_dir else "."
255
+ generator = CICDGeneratorBase.build_generator(provider.name)
256
+ params = {
257
+ "data_project_dir": data_project_dir,
258
+ "workflow_version": WORKFLOW_VERSION,
259
+ }
260
+ warning_message = generator(path, params)
261
+ if warning_message:
262
+ click.echo(warning_message)
263
+
264
+
265
+ async def check_cicd_exists(path: Optional[str] = None) -> Optional[Provider]:
266
+ path = path if path else getcwd()
267
+ for provider in Provider:
268
+ generator = CICDGeneratorBase.build_generator(provider.name)
269
+ if generator.is_already_generated(path):
270
+ return provider
271
+ return None
@@ -28,28 +28,9 @@ from tinybird.client import (
28
28
  TinyB,
29
29
  )
30
30
  from tinybird.config import CURRENT_VERSION, SUPPORTED_CONNECTORS, VERSION, FeatureFlags, get_config
31
- from tinybird.datafile import (
32
- AlreadyExistsException,
33
- CLIGitRelease,
34
- CLIGitReleaseException,
35
- Datafile,
36
- ParseException,
37
- build_graph,
38
- create_release,
39
- diff_command,
40
- folder_pull,
41
- folder_push,
42
- get_project_filenames,
43
- get_resource_versions,
44
- has_internal_datafiles,
45
- parse_datasource,
46
- parse_pipe,
47
- parse_token,
48
- wait_job,
49
- )
50
31
  from tinybird.feedback_manager import FeedbackManager
51
- from tinybird.tb_cli_modules.cicd import check_cicd_exists, init_cicd
52
- from tinybird.tb_cli_modules.common import (
32
+ from tinybird.tb.modules.cicd import check_cicd_exists, init_cicd
33
+ from tinybird.tb.modules.common import (
53
34
  OLDEST_ROLLBACK,
54
35
  CatchAuthExceptions,
55
36
  CLIException,
@@ -65,9 +46,28 @@ from tinybird.tb_cli_modules.common import (
65
46
  load_connector_config,
66
47
  remove_release,
67
48
  try_update_config_with_remote,
49
+ wait_job,
50
+ )
51
+ from tinybird.tb.modules.config import CLIConfig
52
+ from tinybird.tb.modules.datafile import (
53
+ AlreadyExistsException,
54
+ CLIGitRelease,
55
+ CLIGitReleaseException,
56
+ Datafile,
57
+ ParseException,
58
+ build_graph,
59
+ create_release,
60
+ diff_command,
61
+ folder_pull,
62
+ folder_push,
63
+ get_project_filenames,
64
+ get_resource_versions,
65
+ has_internal_datafiles,
66
+ parse_datasource,
67
+ parse_pipe,
68
+ parse_token,
68
69
  )
69
- from tinybird.tb_cli_modules.config import CLIConfig
70
- from tinybird.tb_cli_modules.telemetry import add_telemetry_event
70
+ from tinybird.tb.modules.telemetry import add_telemetry_event
71
71
 
72
72
  __old_click_echo = click.echo
73
73
  __old_click_secho = click.secho