Skip to content

Commit 2cb01ee

Browse files
authored
feat: soft deps + catalog option (#46)
* feat: top pin dbt-artifiacts-parser to < 1.0.0 and better warning message * test: improve cov * docs: Update readme * docs: add catalog option * fix: pin poetry 1.4 in PRCI
1 parent 7aed610 commit 2cb01ee

File tree

11 files changed

+363
-73
lines changed

11 files changed

+363
-73
lines changed

.github/workflows/ci_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- name: Install dependencies
2323
run: |
24-
pip install poetry
24+
pip install "poetry~=1.4.0"
2525
poetry config virtualenvs.in-project true
2626
2727
- name: Cache the virtualenv

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pip install dbterd --upgrade
1313
```
1414

1515
Verify installation:
16+
1617
```bash
1718
dbterd --version
1819
```

dbterd/adapters/base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,21 @@ def __read_manifest(self, mp: str, mv: int = None):
3737
cli_messaging.check_existence(mp, self.filename_manifest)
3838
conditional = f" or provided version {mv} is incorrect" if mv else ""
3939
with cli_messaging.handle_read_errors(self.filename_manifest, conditional):
40-
return file_handlers.read_manifest(mp, mv)
40+
return file_handlers.read_manifest(path=mp, version=mv)
4141

42-
def __read_catalog(self, cp: str):
42+
def __read_catalog(self, cp: str, cv: int = None):
4343
"""Read the Catalog content
4444
4545
Args:
4646
cp (str): catalog.json file path
47+
cv (int, optional): Catalog version. Defaults to None.
4748
4849
Returns:
4950
dict: Catalog dict
5051
"""
5152
cli_messaging.check_existence(cp, self.filename_catalog)
5253
with cli_messaging.handle_read_errors(self.filename_catalog):
53-
return file_handlers.read_catalog(cp)
54+
return file_handlers.read_catalog(path=cp, version=cv)
5455

5556
def __run_by_strategy(self, **kwargs):
5657
"""Read artifacts and export the diagram file following the target"""
@@ -66,7 +67,8 @@ def __run_by_strategy(self, **kwargs):
6667
mv=kwargs["manifest_version"],
6768
)
6869
catalog = self.__read_catalog(
69-
cp=kwargs.get("manifest_path") or kwargs["artifacts_dir"]
70+
cp=kwargs.get("manifest_path") or kwargs["artifacts_dir"],
71+
cv=kwargs["catalog_version"],
7072
)
7173

7274
result = operation(manifest=manifest, catalog=catalog, **kwargs)

dbterd/cli/params.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def common_params(func):
6161
default=None,
6262
type=click.STRING,
6363
)
64+
@click.option(
65+
"--catalog-version",
66+
"-cv",
67+
help="Specified dbt catalog.json version",
68+
default=None,
69+
type=click.STRING,
70+
)
6471
@click.option(
6572
"--resource-type",
6673
"-rt",

dbterd/helpers/file.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from dbt_artifacts_parser import parser
66

7+
from dbterd.helpers.log import logger
8+
79

810
def get_sys_platform(): # pragma: no cover
911
return sys.platform
@@ -118,7 +120,16 @@ def read_manifest(path: str, version: int = None):
118120
dict: Manifest dict
119121
"""
120122
_dict = open_json(f"{path}/manifest.json")
121-
parser_version = f"parse_manifest_v{version}" if version else "parse_manifest"
123+
default_parser = "parse_manifest"
124+
parser_version = f"parse_manifest_v{version}" if version else default_parser
125+
if not hasattr(parser, parser_version):
126+
logger.warning(
127+
"Manifest version is NOT SUPPORTED in current `dbt-artifacts-parser` package. \n"
128+
"Please help to try `-mv {version}` option with other value, OR upgrade the package:\n"
129+
"\tpip install dbt-artifacts-parser --upgrade\n"
130+
"Try falling back to the latest one..."
131+
)
132+
parser_version = default_parser
122133
parse_func = getattr(parser, parser_version)
123134
return parse_func(manifest=_dict)
124135

@@ -134,6 +145,15 @@ def read_catalog(path: str, version: int = None):
134145
dict: Catalog dict
135146
"""
136147
_dict = open_json(f"{path}/catalog.json")
137-
parser_version = f"parse_catalog_v{version}" if version else "parse_catalog"
148+
default_parser = "parse_catalog"
149+
parser_version = f"parse_catalog_v{version}" if version else default_parser
150+
if not hasattr(parser, parser_version):
151+
logger.warning(
152+
"Catalog version is NOT SUPPORTED in current `dbt-artifacts-parser` package. \n"
153+
"Please help to try `-mv {version}` option with other value, OR upgrade the package:\n"
154+
"\tpip install dbt-artifacts-parser --upgrade\n"
155+
"Try falling back to the latest one..."
156+
)
157+
parser_version = default_parser
138158
parse_func = getattr(parser, parser_version)
139159
return parse_func(catalog=_dict)

docs/index.md

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# dbterd
22

3-
CLI to generate Diagram-as-a-code file ([DBML](https://dbdiagram.io/d), [Mermaid](https://mermaid-js.github.io/mermaid-live-editor/), [PlantUML](https://plantuml.com/ie-diagram), [GraphViz](https://graphviz.org/), [D2](https://d2lang.com/)) from dbt artifact files (required: [![dbt](https://img.shields.io/badge/manifest.json-upto--v9-3776AB.svg?style=flat&logo=dbt&logoColor=orange)](https://schemas.getdbt.com/) [![dbt](https://img.shields.io/badge/catalog.json-upto--v1-3776AB.svg?style=flat&logo=dbt&logoColor=orange)](https://schemas.getdbt.com/))
3+
CLI to generate Diagram-as-a-code file ([DBML](https://dbdiagram.io/d), [Mermaid](https://mermaid-js.github.io/mermaid-live-editor/), [PlantUML](https://plantuml.com/ie-diagram), [GraphViz](https://graphviz.org/), [D2](https://d2lang.com/)) from dbt artifact files (required: [![dbt](https://img.shields.io/badge/manifest.json-upto--v10-3776AB.svg?style=flat&logo=dbt&logoColor=orange)](https://schemas.getdbt.com/) [![dbt](https://img.shields.io/badge/catalog.json-upto--v1-3776AB.svg?style=flat&logo=dbt&logoColor=orange)](https://schemas.getdbt.com/))
44

55
[![PyPI version](https://badge.fury.io/py/dbterd.svg)](https://pypi.org/project/dbterd/)
66
![python-cli](https://img.shields.io/badge/CLI-Python-FFCE3E?labelColor=14354C&logo=python&logoColor=white)
@@ -15,42 +15,46 @@ CLI to generate Diagram-as-a-code file ([DBML](https://dbdiagram.io/d), [Mermaid
1515
<a href="#" data-terminal-control="">restart ↻</a>
1616
</div>
1717

18-
Verify installed version:
18+
Verify installation:
1919

2020
```bash
2121
dbterd --version
2222
```
2323

2424
## Quick examine with existing samples
2525

26-
```bash
27-
# select all models in dbt_resto
28-
dbterd run -ad samples/dbtresto -o target
29-
# select all models in dbt_resto, Select multiple dbt resources
30-
dbterd run -ad samples/dbtresto -o target -rt model -rt source
31-
# select only models in dbt_resto excluding staging
32-
dbterd run -ad samples/dbtresto -o target -s model.dbt_resto -ns model.dbt_resto.staging
33-
# select only models in schema name mart excluding staging
34-
dbterd run -ad samples/dbtresto -o target -s schema:mart -ns model.dbt_resto.staging
35-
# select only models in schema full name dbt.mart excluding staging
36-
dbterd run -ad samples/dbtresto -o target -s schema:dbt.mart -ns model.dbt_resto.staging
37-
38-
# other samples
39-
dbterd run -ad samples/fivetranlog -o target
40-
dbterd run -ad samples/fivetranlog -o target -rt model -rt source
41-
42-
dbterd run -ad samples/facebookad -o target
43-
dbterd run -ad samples/facebookad -o target -rt model -rt source
44-
45-
dbterd run -ad samples/shopify -o target
46-
dbterd run -ad samples/shopify -o target -rt model -rt source
47-
48-
dbterd run -ad samples/dbt-constraints \
49-
-a "test_relationship:(name:foreign_key|c_from:fk_column_name|c_to:pk_column_name)"
50-
51-
# your own sample without commiting to repo
52-
dbterd run -ad samples/local -o target -rt model -rt source
53-
```
26+
<details>
27+
<summary>Click me</summary>
28+
29+
```bash
30+
# select all models in dbt_resto
31+
dbterd run -ad samples/dbtresto
32+
# select all models in dbt_resto, Select multiple dbt resources
33+
dbterd run -ad samples/dbtresto -rt model -rt source
34+
# select only models in dbt_resto excluding staging
35+
dbterd run -ad samples/dbtresto -s model.dbt_resto -ns model.dbt_resto.staging
36+
# select only models in schema name mart excluding staging
37+
dbterd run -ad samples/dbtresto -s schema:mart -ns model.dbt_resto.staging
38+
# select only models in schema full name dbt.mart excluding staging
39+
dbterd run -ad samples/dbtresto -s schema:dbt.mart -ns model.dbt_resto.staging
40+
41+
# other samples
42+
dbterd run -ad samples/fivetranlog
43+
dbterd run -ad samples/fivetranlog -rt model -rt source
44+
45+
dbterd run -ad samples/facebookad
46+
dbterd run -ad samples/facebookad -rt model -rt source
47+
48+
dbterd run -ad samples/shopify -s wildcard:*shopify.shopify__*
49+
dbterd run -ad samples/shopify -rt model -rt source
50+
51+
dbterd run -ad samples/dbt-constraints -a "test_relationship:(name:foreign_key|c_from:fk_column_name|c_to:pk_column_name)"
52+
53+
# your own sample without commiting to repo
54+
dbterd run -ad samples/local -rt model -rt source
55+
```
56+
57+
</details>
5458

5559
## Quick DEMO
5660

docs/nav/guide/cli-references.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Command to generate diagram-as-a-code file
5151
diagram connectors [default:
5252
test_relationship]
5353
-mv, --manifest-version TEXT Specified dbt manifest.json version
54+
-cv, --catalog-version TEXT Specified dbt catalog.json version
5455
-rt, --resource-type TEXT Specified dbt resource type(seed, model,
5556
source, snapshot),default:model, use examples,
5657
-rt model -rt source
@@ -229,6 +230,23 @@ Specified dbt manifest.json version
229230
dbterd run -mv 7
230231
```
231232

233+
### --catalog-version (-cv)
234+
235+
Specified dbt catalog.json version
236+
> Auto detect if not specified
237+
238+
**Examples:**
239+
=== "CLI"
240+
241+
```bash
242+
dbterd run --catalog-version 7
243+
```
244+
=== "CLI (long style)"
245+
246+
```bash
247+
dbterd run -cv 7
248+
```
249+
232250
### --resource-type (-rt)
233251

234252
Specified dbt resource type(seed, model, source, snapshot).

0 commit comments

Comments
 (0)