Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 4235e5a

Browse files
authored
Merge branch 'master' into master
2 parents 7e9fd16 + 2697d3a commit 4235e5a

File tree

9 files changed

+49
-8
lines changed

9 files changed

+49
-8
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Test SQL code and preview changes by comparing development/staging environment d
7777

7878
**[Get started with data-diff & dbt](https://docs.datafold.com/development_testing/open_source)**
7979

80+
Also available in a [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=Datafold.datafold-vscode)
81+
8082
Reach out on the dbt Slack in [#tools-datafold](https://getdbt.slack.com/archives/C03D25A92UU) for advice and support
8183

8284
# Supported databases

data_diff/__main__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def _get_log_handlers(is_dbt: Optional[bool] = False) -> Dict[str, logging.Handl
4848
rich_handler.setLevel(logging.WARN)
4949
handlers["rich_handler"] = rich_handler
5050

51-
# only use log_status_handler in a terminal
52-
if rich_handler.console.is_terminal and is_dbt:
51+
# only use log_status_handler in an interactive terminal session
52+
if rich_handler.console.is_interactive and is_dbt:
5353
log_status_handler = LogStatusHandler()
5454
log_status_handler.setFormatter(logging.Formatter(log_format_status, datefmt=date_format))
5555
log_status_handler.setLevel(logging.DEBUG)

data_diff/config.py

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
import toml
55

66

7+
_ARRAY_FIELDS = (
8+
"key_columns",
9+
"columns",
10+
)
11+
12+
713
class ConfigParseError(Exception):
814
pass
915

@@ -38,6 +44,11 @@ def _apply_config(config: Dict[str, Any], run_name: str, kw: Dict[str, Any]):
3844
for index in "12":
3945
run_args[index] = {attr: kw.pop(f"{attr}{index}") for attr in ("database", "table")}
4046

47+
# Make sure array fields are decoded as list, since array fields in toml are decoded as list, but TableSegment object requires tuple type.
48+
for field in _ARRAY_FIELDS:
49+
if isinstance(run_args.get(field), list):
50+
run_args[field] = tuple(run_args[field])
51+
4152
# Process databases + tables
4253
for index in "12":
4354
try:

data_diff/dbt.py

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .format import jsonify, jsonify_error
2424
from .tracking import (
2525
bool_ask_for_email,
26+
bool_notify_about_extension,
2627
create_email_signup_event_json,
2728
set_entrypoint_name,
2829
set_dbt_user_id,
@@ -48,6 +49,7 @@
4849

4950
logger = getLogger(__name__)
5051
CLOUD_DOC_URL = "https://docs.datafold.com/development_testing/cloud"
52+
EXTENSION_INSTALL_URL = "https://get.datafold.com/datafold-vs-code-install"
5153

5254

5355
class TDiffVars(pydantic.BaseModel):
@@ -155,6 +157,8 @@ def dbt_diff(
155157
for thread in diff_threads:
156158
thread.join()
157159

160+
_extension_notification()
161+
158162

159163
def _get_diff_vars(
160164
dbt_parser: "DbtParser",
@@ -517,3 +521,10 @@ def _email_signup() -> None:
517521
if email:
518522
event_json = create_email_signup_event_json(email)
519523
run_as_daemon(send_event_json, event_json)
524+
525+
526+
def _extension_notification() -> None:
527+
if bool_notify_about_extension():
528+
rich.print(
529+
f"\n\nHaving a good time diffing? :heart_eyes-emoji:\nMake sure to check out the free [bold]Datafold VS Code extension[/bold] for more a more seamless diff experience:\n{EXTENSION_INSTALL_URL}"
530+
)

data_diff/tracking.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import urllib.request
1212
from uuid import uuid4
1313
import toml
14+
from rich import get_console
1415

1516
from .version import __version__
1617

@@ -41,7 +42,7 @@ def bool_ask_for_email() -> bool:
4142
"""
4243
Checks the .datadiff.toml profile file for the asked_for_email key
4344
44-
Returns False immediately if --no-tracking
45+
Returns False immediately if --no-tracking or not in an interactive terminal
4546
4647
If found, return False (already asked for email)
4748
@@ -50,7 +51,8 @@ def bool_ask_for_email() -> bool:
5051
Returns:
5152
bool: decision on whether to prompt the user for their email
5253
"""
53-
if g_tracking_enabled:
54+
console = get_console()
55+
if g_tracking_enabled and console.is_interactive:
5456
profile = _load_profile()
5557

5658
if "asked_for_email" not in profile:
@@ -61,6 +63,17 @@ def bool_ask_for_email() -> bool:
6163
return False
6264

6365

66+
def bool_notify_about_extension() -> bool:
67+
profile = _load_profile()
68+
console = get_console()
69+
if "notified_about_extension" not in profile and console.is_interactive:
70+
profile["notified_about_extension"] = ""
71+
with open(DEFAULT_PROFILE, "w") as conf:
72+
toml.dump(profile, conf)
73+
return True
74+
return False
75+
76+
6477
g_tracking_enabled = True
6578
g_anonymous_id = None
6679

data_diff/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.8.1"
1+
__version__ = "0.8.2"

poetry.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "data-diff"
3-
version = "0.8.1"
3+
version = "0.8.2"
44
description = "Command-line tool and Python library to efficiently diff rows across two different databases."
55
authors = ["Datafold <data-diff@datafold.com>"]
66
license = "MIT"
@@ -36,7 +36,7 @@ cryptography = {version="*", optional=true}
3636
trino = {version="^0.314.0", optional=true}
3737
presto-python-client = {version="*", optional=true}
3838
clickhouse-driver = {version="*", optional=true}
39-
duckdb = {version="^0.7.0", optional=true}
39+
duckdb = {version="*", optional=true}
4040
dbt-artifacts-parser = {version="^0.4.0"}
4141
dbt-core = {version="^1.0.0"}
4242
keyring = "*"

tests/test_config.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def test_basic(self):
1515
1616
[run.default]
1717
update_column = "timestamp"
18+
key_columns = ["id"]
19+
columns = ["name", "age"]
1820
verbose = true
1921
threads = 2
2022
@@ -39,6 +41,8 @@ def test_basic(self):
3941
assert res["table2"] == "rating_del1"
4042
assert res["threads1"] == 11
4143
assert res["threads2"] == 22
44+
assert res["key_columns"] == ("id",)
45+
assert res["columns"] == ("name", "age")
4246

4347
res = apply_config_from_string(config, "pg_pg", {"update_column": "foo", "table2": "bar"})
4448
assert res["update_column"] == "foo"

0 commit comments

Comments
 (0)