Skip to content

Commit

Permalink
use relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
alyiwang committed Dec 16, 2024
1 parent f9d7a98 commit e9a4a05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions metaphor/looker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ alternative_base_url: <looker_base_url> // e.g. https://looker.my_company.com

#### Ignored Model Files

You can also specify a list of model files to ignore by using the following config:
You can also specify a list of model files to ignore by using the following config. The pattern is matched against the relative path of the model file from the project base directory.

```yaml
ignored_model_files:
- "/foo/bar/model1.model.lkml"
- "/abc/tmp*/*"
- "model1.model.lkml"
- "tmp/*"
```

#### SSL Verification
Expand Down
9 changes: 6 additions & 3 deletions metaphor/looker/lookml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,13 @@ def _load_model(
return raw_model, entity_urls, connection


def _is_ignored_model_file(model_path: str, ignored_model_files: List[str]) -> bool:
def _is_ignored_model_file(
model_path: str, base_dir: str, ignored_model_files: List[str]
) -> bool:
"""Check if the model file is ignored by the config"""
relative_path = os.path.relpath(model_path, base_dir)
for ignored_model_file in ignored_model_files:
if fnmatch(model_path, ignored_model_file):
if fnmatch(relative_path, ignored_model_file):
return True
return False

Expand All @@ -636,7 +639,7 @@ def parse_project(
virtual_views = []

for model_path in glob.glob(f"{base_dir}/**/*.model.lkml", recursive=True):
if _is_ignored_model_file(model_path, ignored_model_files):
if _is_ignored_model_file(model_path, base_dir, ignored_model_files):
logger.info(f"Ignoring model file {model_path} by config")
continue

Expand Down
12 changes: 11 additions & 1 deletion tests/looker/test_lookml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ def test_ignored_model(test_root_dir):
f"{test_root_dir}/looker/empty_model",
connection_map,
VIEW_EXPLORE_FOLDER,
ignored_model_files=[f"{test_root_dir}/looker/empty_model/*.model.lkml"],
ignored_model_files=["model1.model.lkml"],
)

assert models_map == {}
assert virtual_views == []

models_map, virtual_views = parse_project(
f"{test_root_dir}/looker/empty_model",
connection_map,
VIEW_EXPLORE_FOLDER,
ignored_model_files=["model*"],
)

assert models_map == {}
Expand Down

0 comments on commit e9a4a05

Please sign in to comment.