Repository navigation
Expand file tree
/
Copy pathtest.py
More file actions
66 lines (45 loc) · 1.52 KB
/
Copy pathtest.py
File metadata and controls
66 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from dbt_loom.config import dbtLoomConfig
from pathlib import Path
import re
import yaml
import os
from dbt_loom.config import (
FileReferenceConfig,
LoomConfigurationError,
ManifestReference,
ManifestReferenceType,
)
def load_from_s3(config):
"""Load a manifest dictionary from an S3-compatible bucket."""
from dbt_loom.clients.s3 import S3Client, S3ReferenceConfig
gcs_client = S3Client(
bucket_name=config.bucket_name,
object_name=config.object_name,
)
return gcs_client.load_manifest()
def load(manifest_reference):
"""Load a manifest dictionary based on a ManifestReference input."""
manifest = load_from_s3(manifest_reference.config)
return manifest
def replace_env_variables(config_str: str) -> str:
"""Replace environment variable placeholders in the configuration string."""
pattern = r"\$(\w+)|\$\{([^}]+)\}"
return re.sub(
pattern,
lambda match: os.environ.get(
match.group(1) if match.group(1) is not None else match.group(2), ""
),
config_str,
)
def read_config(path: Path):
"""Read the dbt-loom configuration file."""
if not path.exists():
return None
with open(path) as file:
config_content = file.read()
config_content = replace_env_variables(config_content)
return dbtLoomConfig(**yaml.load(config_content, yaml.SafeLoader))
path = Path("dbt/dbt_loom.config.yml")
from dbt.cli.main import dbtRunner
dbt_runner = dbtRunner()
res = dbt_runner.invoke(args=["deps"])