feat!: give clair a Python API, and make the CLI a thin wrapper - #39
Draft
OmerBaddour wants to merge 3 commits into
Draft
feat!: give clair a Python API, and make the CLI a thin wrapper#39OmerBaddour wants to merge 3 commits into
OmerBaddour wants to merge 3 commits into
Conversation
`clair.run()`, `clair.compile()`, `clair.test()`, `clair.catalog()` and `clair.serve_docs()` do the complete operation. The new module `clair/api.py` holds them. Each CLI command now parses the arguments, calls one function, and sets the exit code. A caller reads the result object, and parses no log line: * `RunResult` gives the statements that clair executed, the staging address, the effective run mode, the row count and the test results. * `RunSummary` gives the run_id, the project_root, the run mode, a `result()` lookup by address, and `test_results`. * `CompiledNodeInfo` gives the logical address, the physical address, the staging address, the effective run mode and the artifact path. * `CompileOutput` gives the run_id, the project_root, the env_name, the run mode and a `node()` lookup by address. Behaviour changes: * `clair.serve_docs()` is the name of the docs operation, because `clair.docs` is the docs package. * The routing warnings are structured log messages, not click output. The `clair validate` output does not change. * `format_run_output()` and `format_test_output()` are removed. Make a `RunSummary` or a `TestSummary` directly. * `expand_selectors()` accepts each sequence of patterns, not a tuple only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The integration tests ran the CLI as a subprocess and read the JSON log lines. A test saw the exit code and the log stream only, thus it could not ask which statement failed, or which data quality test rejected the data. The tests now call `clair.run()` and `clair.test()` in the process of the test, and they read the summary that the call gives. New assertions that the log lines could not carry: * The failed test names the Trouve, the test type and the query id. * The MERGE that fails is the statement at `failed_statement_index`, and clair ran no data quality test after it. * A staged run reports the staging address that it built at, thus a test names that object, and computes no name of its own. * An incremental run reports the effective run mode of each Trouve. Other changes: * `clair.docs()` is the name of the docs operation, and the docs package is `clair/webui/`. Each command of the CLI now has one function of the same name in `clair/api.py`. * `RunResult.failed_statement_index` gives the index in `sql` of the statement that failed. * `discover_project()` removes the modules of each project that this process loaded, and takes the other project roots off `sys.path`. Two projects can give one module the same name, for example `mydb.refined.checked`. The second discovery read the files of the first project. * `tests/unit/test_cli_commands.py` covers the CLI: the arguments that each command gives to the API, and the status code that it gives back. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The full refresh test has the summary of the run already. It therefore asserts the staging address and the statements of each Trouve there. A test of its own would start one more run on the warehouse, and prove the same thing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat!: give clair a Python API, and make the CLI a thin wrapper
clair.run(),clair.compile(),clair.test(),clair.catalog()andclair.serve_docs()do the complete operation. The new moduleclair/api.pyholds them. Each CLI command now parses the arguments, calls one function, and
sets the exit code.
A caller reads the result object, and parses no log line:
RunResultgives the statements that clair executed, the staging address,the effective run mode, the row count and the test results.
RunSummarygives the run_id, the project_root, the run mode, aresult()lookup by address, and
test_results.CompiledNodeInfogives the logical address, the physical address, thestaging address, the effective run mode and the artifact path.
CompileOutputgives the run_id, the project_root, the env_name, the runmode and a
node()lookup by address.Behaviour changes:
clair.serve_docs()is the name of the docs operation, becauseclair.docsis the docs package.
clair validateoutput does not change.format_run_output()andformat_test_output()are removed. Make aRunSummaryor aTestSummarydirectly.expand_selectors()accepts each sequence of patterns, not a tuple only.refactor!: run the integration tests through the Python API
The integration tests ran the CLI as a subprocess and read the JSON log lines.
A test saw the exit code and the log stream only, thus it could not ask which
statement failed, or which data quality test rejected the data. The tests now
call
clair.run()andclair.test()in the process of the test, and they readthe summary that the call gives.
New assertions that the log lines could not carry:
failed_statement_index, and clairran no data quality test after it.
that object, and computes no name of its own.
Other changes:
clair.docs()is the name of the docs operation, and the docs package isclair/webui/. Each command of the CLI now has one function of the samename in
clair/api.py.RunResult.failed_statement_indexgives the index insqlof the statementthat failed.
discover_project()removes the modules of each project that this processloaded, and takes the other project roots off
sys.path. Two projects cangive one module the same name, for example
mydb.refined.checked. The seconddiscovery read the files of the first project.
tests/unit/test_cli_commands.pycovers the CLI: the arguments that eachcommand gives to the API, and the status code that it gives back.
test: assert the statements of each example run, and start no extra run
The full refresh test has the summary of the run already. It therefore asserts
the staging address and the statements of each Trouve there. A test of its own
would start one more run on the warehouse, and prove the same thing.
🤖 Generated with Claude Code