From 82022b09c60f6e8c7276bacdd1d85a464c7a9b32 Mon Sep 17 00:00:00 2001 From: Nicholas Deis Date: Fri, 17 Nov 2023 20:07:52 -0700 Subject: [PATCH 1/2] Output lookml results as json --- CONTRIBUTING.md | 2 +- spectacles/cli.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c6b60733..1a776837 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ Follow [these standard instructions](https://opensource.guide/how-to-contribute/ * Fork the repository on GitHub * Clone your fork to your local machine * Create a new local branch off `master` using the `feature/feature-name` branch naming convention -* Create a Python virtual environment and install dependencies with `pip install -r requirements.txt` +* Create a Python virtual environment and install dependencies with `pip install -r dev-requirements.txt` Once your local repository is set up, develop away on your feature! Double-check that you've included the following: diff --git a/spectacles/cli.py b/spectacles/cli.py index 45e64db9..4ca17093 100644 --- a/spectacles/cli.py +++ b/spectacles/cli.py @@ -343,6 +343,7 @@ def main(): remote_reset=args.remote_reset, severity=args.severity, pin_imports=pin_imports, + print_json=args.json ) ) @@ -570,6 +571,13 @@ def _build_lookml_subparser( "validator to fail. The default is 'warning'." ), ) + subparser.add_argument( + "--json", + action="store_true", + help=( + "Output the results as a json" + ) + ) _build_validator_subparser(subparser_action, subparser) @@ -747,6 +755,7 @@ async def run_lookml( remote_reset, severity, pin_imports, + print_json = False ) -> None: # Don't trust env to ignore .netrc credentials async_client = httpx.AsyncClient(trust_env=False) @@ -760,7 +769,13 @@ async def run_lookml( finally: await async_client.aclose() + if print_json: + logger.info(json.dumps(results,None,2)) + return + errors = sorted(results["errors"], key=lambda x: x["metadata"]["file_path"] or "a") + + unique_files = sorted( set( error["metadata"]["file_path"] From 06c8f9625d151de72855ff79220f48a48b5daa61 Mon Sep 17 00:00:00 2001 From: Nicholas Deis Date: Fri, 17 Nov 2023 20:12:31 -0700 Subject: [PATCH 2/2] Remove unnecessary whitespace --- spectacles/cli.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/spectacles/cli.py b/spectacles/cli.py index 4ca17093..e1e8847b 100644 --- a/spectacles/cli.py +++ b/spectacles/cli.py @@ -774,8 +774,6 @@ async def run_lookml( return errors = sorted(results["errors"], key=lambda x: x["metadata"]["file_path"] or "a") - - unique_files = sorted( set( error["metadata"]["file_path"]