Skip to content

Commit ccb3650

Browse files
committed
fix prefixes for project directory and targets
1 parent a7a6df3 commit ccb3650

File tree

3 files changed

+43
-33
lines changed

3 files changed

+43
-33
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
Recent and upcoming changes to dbt2looker
4+
5+
## 0.8.0
6+
### Changed
7+
- Command line interface changed argument from `--target` to `--target-dir`
8+
9+
### Added
10+
- Added the `--project-dir` flag to the command line interface to change the search directory for `dbt_project.yml`

dbt2looker/cli.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,40 @@
2323

2424

2525
def get_manifest(prefix: str):
26-
paths = list(pathlib.Path(prefix).rglob('manifest.json'))
27-
if len(paths) == 0:
28-
logging.error(f'No manifest.json file found in path {prefix}')
26+
manifest_path = os.path.join(prefix, 'manifest.json')
27+
try:
28+
with open(manifest_path, 'r') as f:
29+
raw_manifest = json.load(f)
30+
except FileNotFoundError as e:
31+
logging.error(f'Could not find manifest file at {manifest_path}. Use --target-dir to change the search path for the manifest.json file.')
2932
raise SystemExit('Failed')
30-
elif len(paths) > 1:
31-
logging.warning(f'Multiple manifest.json files found in path {prefix} this can lead to unexpected behaviour')
32-
path = paths[0]
33-
with open(path, 'r') as f:
34-
raw_manifest = json.load(f)
3533
parser.validate_manifest(raw_manifest)
36-
logging.debug(f'Detected valid manifest at {path}')
34+
logging.debug(f'Detected valid manifest at {manifest_path}')
3735
return raw_manifest
3836

3937

4038
def get_catalog(prefix: str):
41-
paths = list(pathlib.Path(prefix).rglob('catalog.json'))
42-
if len(paths) == 0:
43-
logging.error(f'No catalog.json file found in path {prefix}')
39+
catalog_path = os.path.join(prefix, 'catalog.json')
40+
try:
41+
with open(catalog_path, 'r') as f:
42+
raw_catalog = json.load(f)
43+
except FileNotFoundError as e:
44+
logging.error(f'Could not find catalog file at {catalog_path}. Use --target-dir to change the search path for the catalog.json file.')
4445
raise SystemExit('Failed')
45-
elif len(paths) > 1:
46-
logging.warning(f'Multiple catalog.json files found in path {prefix} this can lead to unexpected behaviour')
47-
path = paths[0]
48-
with open(path, 'r') as f:
49-
raw_catalog = json.load(f)
5046
parser.validate_catalog(raw_catalog)
51-
logging.debug(f'Detected valid catalog at {path}')
47+
logging.debug(f'Detected valid catalog at {catalog_path}')
5248
return raw_catalog
5349

5450

5551
def get_dbt_project_config(prefix: str):
56-
paths = list(pathlib.Path(prefix).rglob('dbt_project.yml'))
57-
if len(paths) == 0:
58-
logging.error(f'No dbt_project.yml file found in path {prefix}')
52+
project_path = os.path.join(prefix, 'dbt_project.yml')
53+
try:
54+
with open(project_path, 'r') as f:
55+
project_config = yaml.load(f, Loader=Loader)
56+
except FileNotFoundError as e:
57+
logging.error(f'Could a dbt_project.yml file at {project_path}. Use --project-dir to change the search path for the dbt_project.yml file.')
5958
raise SystemExit('Failed')
60-
elif len(paths) > 1:
61-
logging.warning(f'Multiple dbt_project.yml files found in path {prefix} this can lead to unexpected behaviour')
62-
path = paths[0]
63-
with open(path, 'r') as f:
64-
project_config = yaml.load(f, Loader=Loader)
65-
logging.debug(f'Detected valid dbt config at {path}')
59+
logging.debug(f'Detected valid dbt config at {project_path}')
6660
return project_config
6761

6862

@@ -74,11 +68,17 @@ def run():
7468
version=f'dbt2looker {version("dbt2looker")}',
7569
)
7670
argparser.add_argument(
77-
'--target',
78-
help='Path to dbt target directory containing manifest.json and catalog.json.',
71+
'--project-dir',
72+
help='Path to dbt project directory containing dbt_project.yml. Default is "."',
7973
default='./',
8074
type=str,
8175
)
76+
argparser.add_argument(
77+
'--target-dir',
78+
help='Path to dbt target directory containing manifest.json and catalog.json. Default is "./target"',
79+
default='./target',
80+
type=str,
81+
)
8282
argparser.add_argument(
8383
'--tag',
8484
help='Filter to dbt models using this tag',
@@ -105,9 +105,9 @@ def run():
105105
)
106106

107107
# Load raw manifest file
108-
raw_manifest = get_manifest(args.target)
109-
raw_catalog = get_catalog(args.target)
110-
raw_config = get_dbt_project_config(args.target)
108+
raw_manifest = get_manifest(prefix=args.target_dir)
109+
raw_catalog = get_catalog(prefix=args.target_dir)
110+
raw_config = get_dbt_project_config(prefix=args.project_dir)
111111

112112
# Get dbt models from manifest
113113
dbt_project_config = parser.parse_dbt_project_config(raw_config)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "dbt2looker"
3-
version = "0.7.3"
3+
version = "0.8.0"
44
description = "Generate lookml view files from dbt models"
55
authors = ["oliverlaslett <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)