dbt-common 0.1.4__py3-none-any.whl → 0.1.6__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.
- dbt_common/__about__.py +1 -1
- dbt_common/context.py +3 -3
- dbt_common/events/contextvars.py +9 -9
- dbt_common/events/functions.py +0 -7
- dbt_common/utils/executor.py +13 -1
- {dbt_common-0.1.4.dist-info → dbt_common-0.1.6.dist-info}/METADATA +2 -2
- {dbt_common-0.1.4.dist-info → dbt_common-0.1.6.dist-info}/RECORD +9 -9
- {dbt_common-0.1.4.dist-info → dbt_common-0.1.6.dist-info}/WHEEL +0 -0
- {dbt_common-0.1.4.dist-info → dbt_common-0.1.6.dist-info}/licenses/LICENSE +0 -0
dbt_common/__about__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
version = "0.1.
|
1
|
+
version = "0.1.6"
|
dbt_common/context.py
CHANGED
@@ -26,7 +26,7 @@ class InvocationContext:
|
|
26
26
|
_INVOCATION_CONTEXT_VAR: ContextVar[InvocationContext] = ContextVar("DBT_INVOCATION_CONTEXT_VAR")
|
27
27
|
|
28
28
|
|
29
|
-
def
|
29
|
+
def reliably_get_invocation_var() -> ContextVar:
|
30
30
|
invocation_var: Optional[ContextVar] = next(
|
31
31
|
(cv for cv in copy_context() if cv.name == _INVOCATION_CONTEXT_VAR.name), None
|
32
32
|
)
|
@@ -38,11 +38,11 @@ def _reliably_get_invocation_var() -> ContextVar:
|
|
38
38
|
|
39
39
|
|
40
40
|
def set_invocation_context(env: Mapping[str, str]) -> None:
|
41
|
-
invocation_var =
|
41
|
+
invocation_var = reliably_get_invocation_var()
|
42
42
|
invocation_var.set(InvocationContext(env))
|
43
43
|
|
44
44
|
|
45
45
|
def get_invocation_context() -> InvocationContext:
|
46
|
-
invocation_var =
|
46
|
+
invocation_var = reliably_get_invocation_var()
|
47
47
|
ctx = invocation_var.get()
|
48
48
|
return ctx
|
dbt_common/events/contextvars.py
CHANGED
@@ -58,12 +58,12 @@ def set_task_contextvars(**kwargs: Any) -> Mapping[str, contextvars.Token]:
|
|
58
58
|
def set_contextvars(prefix: str, **kwargs: Any) -> Mapping[str, contextvars.Token]:
|
59
59
|
cvar_tokens = {}
|
60
60
|
for k, v in kwargs.items():
|
61
|
-
|
61
|
+
prefix_key = f"{prefix}{k}"
|
62
62
|
try:
|
63
|
-
var = _context_vars[
|
63
|
+
var = _context_vars[prefix_key]
|
64
64
|
except KeyError:
|
65
|
-
var = contextvars.ContextVar(
|
66
|
-
_context_vars[
|
65
|
+
var = contextvars.ContextVar(prefix_key, default=Ellipsis)
|
66
|
+
_context_vars[prefix_key] = var
|
67
67
|
|
68
68
|
cvar_tokens[k] = var.set(v)
|
69
69
|
|
@@ -73,17 +73,17 @@ def set_contextvars(prefix: str, **kwargs: Any) -> Mapping[str, contextvars.Toke
|
|
73
73
|
# reset by Tokens
|
74
74
|
def reset_contextvars(prefix: str, **kwargs: contextvars.Token) -> None:
|
75
75
|
for k, v in kwargs.items():
|
76
|
-
|
77
|
-
var = _context_vars[
|
76
|
+
prefix_key = f"{prefix}{k}"
|
77
|
+
var = _context_vars[prefix_key]
|
78
78
|
var.reset(v)
|
79
79
|
|
80
80
|
|
81
81
|
# remove from contextvars
|
82
82
|
def unset_contextvars(prefix: str, *keys: str) -> None:
|
83
83
|
for k in keys:
|
84
|
-
|
85
|
-
|
86
|
-
_context_vars[
|
84
|
+
prefix_key = f"{prefix}{k}"
|
85
|
+
if prefix_key in _context_vars:
|
86
|
+
_context_vars[prefix_key].set(Ellipsis)
|
87
87
|
|
88
88
|
|
89
89
|
# Context manager or decorator to set and unset the context vars
|
dbt_common/events/functions.py
CHANGED
@@ -132,13 +132,6 @@ def fire_event_if(
|
|
132
132
|
fire_event(lazy_e(), level=level)
|
133
133
|
|
134
134
|
|
135
|
-
# a special case of fire_event_if, to only fire events in our unit/functional tests
|
136
|
-
def fire_event_if_test(
|
137
|
-
lazy_e: Callable[[], BaseEvent], level: Optional[EventLevel] = None
|
138
|
-
) -> None:
|
139
|
-
fire_event_if(conditional=("pytest" in sys.modules), lazy_e=lazy_e, level=level)
|
140
|
-
|
141
|
-
|
142
135
|
# top-level method for accessing the new eventing system
|
143
136
|
# this is where all the side effects happen branched by event type
|
144
137
|
# (i.e. - mutating the event history, printing to stdout, logging
|
dbt_common/utils/executor.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
import concurrent.futures
|
2
2
|
from contextlib import contextmanager
|
3
|
+
from contextvars import ContextVar
|
3
4
|
from typing import Protocol, Optional
|
4
5
|
|
6
|
+
from dbt_common.context import get_invocation_context, reliably_get_invocation_var
|
7
|
+
|
5
8
|
|
6
9
|
class ConnectingExecutor(concurrent.futures.Executor):
|
7
10
|
def submit_connected(self, adapter, conn_name, func, *args, **kwargs):
|
@@ -60,8 +63,17 @@ class HasThreadingConfig(Protocol):
|
|
60
63
|
threads: Optional[int]
|
61
64
|
|
62
65
|
|
66
|
+
def _thread_initializer(invocation_context: ContextVar) -> None:
|
67
|
+
invocation_var = reliably_get_invocation_var()
|
68
|
+
invocation_var.set(invocation_context)
|
69
|
+
|
70
|
+
|
63
71
|
def executor(config: HasThreadingConfig) -> ConnectingExecutor:
|
64
72
|
if config.args.single_threaded:
|
65
73
|
return SingleThreadedExecutor()
|
66
74
|
else:
|
67
|
-
return MultiThreadedExecutor(
|
75
|
+
return MultiThreadedExecutor(
|
76
|
+
max_workers=config.threads,
|
77
|
+
initializer=_thread_initializer,
|
78
|
+
initargs=(get_invocation_context(),),
|
79
|
+
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: dbt-common
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.6
|
4
4
|
Summary: The shared common utilities that dbt-core and adapter implementations use
|
5
5
|
Project-URL: Homepage, https://github.com/dbt-labs/dbt-common
|
6
6
|
Project-URL: Repository, https://github.com/dbt-labs/dbt-common.git
|
@@ -30,7 +30,7 @@ Requires-Dist: jinja2~=3.0
|
|
30
30
|
Requires-Dist: jsonschema~=4.0
|
31
31
|
Requires-Dist: mashumaro[msgpack]~=3.9
|
32
32
|
Requires-Dist: pathspec<0.12,>=0.9
|
33
|
-
Requires-Dist: protobuf
|
33
|
+
Requires-Dist: protobuf<5.0.0,>=4.0.0
|
34
34
|
Requires-Dist: python-dateutil~=2.0
|
35
35
|
Requires-Dist: requests<3.0.0
|
36
36
|
Requires-Dist: typing-extensions~=4.4
|
@@ -1,7 +1,7 @@
|
|
1
|
-
dbt_common/__about__.py,sha256=
|
1
|
+
dbt_common/__about__.py,sha256=zZ37Z2ygBlDoFI8XD8N8oJHJfXG829j4Pj3mtr-lDDM,18
|
2
2
|
dbt_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
dbt_common/constants.py,sha256=DJIVuTBl5OZpjdFINHon8MNj_XT-Rrp41dAoAuQL2QI,38
|
4
|
-
dbt_common/context.py,sha256=
|
4
|
+
dbt_common/context.py,sha256=XaxjooEU8uHp61TZqZ9jGmKtjjQm81nxJnSjdJmEo8E,1453
|
5
5
|
dbt_common/dataclass_schema.py,sha256=CRSQQmzY4QIBzL54aomPT34o3u8T6Zu6W1XZmWfKs-A,5254
|
6
6
|
dbt_common/helper_types.py,sha256=jW5Yv0Gwx4M14IEX4RID7k4s0hJiKHIzU8CxACQ1Y7k,3491
|
7
7
|
dbt_common/invocation.py,sha256=Zw8jRPn75oi2VrUD6qGvaCDtSyIfqm5pJlPpRjs3s1E,202
|
@@ -25,12 +25,12 @@ dbt_common/contracts/config/properties.py,sha256=K8Ut_q4U6pPY1ZJoFKEA6FUCLR1zb2k
|
|
25
25
|
dbt_common/events/README.md,sha256=CSwVajoxCAqOug2UCnXldH1EUK7Kjf3rcq7z9ACjrss,3023
|
26
26
|
dbt_common/events/__init__.py,sha256=av08vfpxo0ek7PqZNtMxY8FODJ3xwph4ehRxgInx4LA,383
|
27
27
|
dbt_common/events/base_types.py,sha256=E--Fl-KMdJd_UZCN93AuLxnJcQoys2MJjiJxkV03HpM,5448
|
28
|
-
dbt_common/events/contextvars.py,sha256=
|
28
|
+
dbt_common/events/contextvars.py,sha256=Jx2J_Nkx0DH8EE1Sno_mbv7PMLBfCzm7byeFlUeflLA,3079
|
29
29
|
dbt_common/events/event_handler.py,sha256=jfi0PyqIOGnXCG9HEa0VIVULqNvXs1RYmAg0b50ChQs,1385
|
30
30
|
dbt_common/events/event_manager.py,sha256=ZXJ-N4NsfQTnkEpvuedTjHD8Gt8DgYHbz601eTVCm-o,2175
|
31
31
|
dbt_common/events/event_manager_client.py,sha256=etDlUv-3iIwM5IXXuzc1cmQID2fHOXw8dE9snp39-jk,1014
|
32
32
|
dbt_common/events/format.py,sha256=x1RWDZ8G7ZMHmxdld6Q4VXca4kvnhiQOIaQXkC6Uo0Q,1609
|
33
|
-
dbt_common/events/functions.py,sha256=
|
33
|
+
dbt_common/events/functions.py,sha256=TfHUn8nfosEGfIik4pyDDnJDI0HrQ899eH9DiVdINJQ,4756
|
34
34
|
dbt_common/events/helpers.py,sha256=CfsWwNDjsLJkPIgOtAfuLEnZ3rGUKeYsH8aDtCW12OA,410
|
35
35
|
dbt_common/events/interfaces.py,sha256=hEDeDoB0FW2RYHVZBG7gebEt_mUVBzkn1yPubpaxs-s,147
|
36
36
|
dbt_common/events/logger.py,sha256=6LLH8aLoRziFLBmwu-TCR5-EMpBtD28pSaL0FmKpeGA,6159
|
@@ -51,10 +51,10 @@ dbt_common/utils/casting.py,sha256=TVWHO5ct-foNBH-pj4vDZ84jVU-hPQll52X9YSjz2Zs,6
|
|
51
51
|
dbt_common/utils/connection.py,sha256=J5zxWFpGHpUbe-F04S9bVLLO3HLvHB6INOkAey0k76c,1373
|
52
52
|
dbt_common/utils/dict.py,sha256=unI-kJs2yvw7ic2U71-6H8koVRknkb0jCk7W_FCq6_I,4014
|
53
53
|
dbt_common/utils/encoding.py,sha256=6_kSY2FvGNYMg7oX7PrbvVioieydih3Kl7Ii802LaHI,1705
|
54
|
-
dbt_common/utils/executor.py,sha256=
|
54
|
+
dbt_common/utils/executor.py,sha256=W-DtjSPdbnm5bssT3EUo6SbGVi3VePD4LcvgKH1NhZM,2414
|
55
55
|
dbt_common/utils/formatting.py,sha256=JUn5rzJ-uajs9wPCN0-f2iRFY1pOJF5YjTD9dERuLoc,165
|
56
56
|
dbt_common/utils/jinja.py,sha256=XNfZHuZhLM_R_yPmzYojPm6bF7QOoxIjSWrkJRw6wks,965
|
57
|
-
dbt_common-0.1.
|
58
|
-
dbt_common-0.1.
|
59
|
-
dbt_common-0.1.
|
60
|
-
dbt_common-0.1.
|
57
|
+
dbt_common-0.1.6.dist-info/METADATA,sha256=l7QdlkHqicJ_xG4YQRoWBw2yrq1kOUBfPpj9N8ikzLQ,3655
|
58
|
+
dbt_common-0.1.6.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
|
59
|
+
dbt_common-0.1.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
60
|
+
dbt_common-0.1.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|