Skip to content

Commit c08310b

Browse files
committed
Merge branch 'main' into format-skip-load
Resolves the conflict with #6060, which added `--local` to `sqlmesh test`. The only conflict was tests/cli/test_cli.py, where each branch appended its own tests to the end of the file, so both blocks are kept. sqlmesh/cli/main.py merged cleanly and both changes survive: the `OPTIONAL_LOCAL_COMMANDS` gating for `test --local` from #6060, and the `("lint", "format")` scoped load from this branch. The two sit in different parts of the callback and don't interact. Verified afterwards that `format <path>` still skips `Context.load`, `format` with no paths still loads, and `test --local` still runs. Signed-off-by: Adegbite Ayoade <tripleaceme@gmail.com>
2 parents 8cf8c62 + ad2377e commit c08310b

22 files changed

Lines changed: 1101 additions & 455 deletions

File tree

.github/workflows/pr.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ jobs:
470470
path: vscode/extension/playwright-report/
471471
retention-days: 30
472472
test-dbt-versions:
473+
needs: changes
474+
if:
475+
needs.changes.outputs.python == 'true' || needs.changes.outputs.ci ==
476+
'true' || github.ref == 'refs/heads/main'
473477
runs-on: ubuntu-latest
474478
strategy:
475479
fail-fast: false

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ docs
3030
examples
3131
posts
3232
.circleci
33+
.github/
3334
README.md
3435
mkdocs.yml
3536
.readthedocs.yaml

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ See [docs/development.md](docs/development.md) for full setup instructions. Key
6565
python -m venv .venv
6666
source .venv/bin/activate
6767
make install-dev
68-
make style # Run before submitting
68+
make style # Run before submitting
6969
make fast-test # Quick test suite
7070
```
7171

72+
Optionally, `make install-pre-commit` installs git hooks so ruff and mypy run on `git commit`. Hooks do not replace `make style`: they run on staged files, while CI runs `make style` across the tree.
73+
7274
## Coding Standards
7375

7476
- Run `make style` before submitting a pull request

docs/concepts/tests.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,23 @@ You can also run tests that match a pattern or substring using a glob pathname e
463463
$ sqlmesh test tests/test_*
464464
```
465465

466+
You can pass `--local` to run tests without loading state from the configured state connection:
467+
468+
``` bash
469+
$ sqlmesh test --local
470+
```
471+
472+
This keeps offline runs and commit hooks from opening a connection to the state backend.
473+
474+
In multi-repository setups, or when running tests for only a subset of projects, models that exist only in remote state are not loaded under `--local`. Unlike [`sqlmesh lint --local`](../guides/linter.md), which reports additional errors in that situation, a test whose model is missing is **skipped with a warning and the run still succeeds**:
475+
476+
```
477+
[WARNING] Model '"memory"."bronze"."a"' was not found at tests/test_a.yaml
478+
.**Successfully Ran `1` Tests Against `duckdb`**
479+
```
480+
481+
So a passing exit code alone does not mean every test you expected actually ran. Watch the output for these warnings, and keep in mind that a hook using `--local` will not fail on them.
482+
466483
### Testing using notebooks
467484

468485
You can execute tests on demand using the `%run_test` notebook magic as follows:

docs/development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Once you have activated your virtual environment, you can install the dependenci
4242
make install-dev
4343
```
4444

45-
Optionally, you can use pre-commit to automatically run linters/formatters:
45+
Optionally, `make install-pre-commit` installs git hooks so ruff and mypy run on `git commit`. Hooks do not replace `make style`: they run on staged files, while CI runs `make style` across the tree.
4646

4747
```bash
4848
make install-pre-commit

docs/reference/cli.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ Options:
634634
useful for debugging.
635635
--select-model TEXT Select specific models to run unit tests for. Can be
636636
specified multiple times.
637+
--local Run tests using only locally loaded project files
638+
without loading state. Tests whose model is not loaded
639+
are skipped with a warning rather than failing.
637640
--help Show this message and exit.
638641
```
639642

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
},
66
"scripts": {
77
"ci": "pnpm run lint && pnpm run -r ci",
8-
"fmt": "prettier --write .",
9-
"fmt:check": "prettier --check .",
8+
"fmt": "prettier --write vscode web/client web/common",
9+
"fmt:check": "prettier --check vscode web/client web/common",
1010
"lint": "pnpm run fmt:check && pnpm run -r lint",
1111
"lint:fix": "pnpm run fmt && pnpm run -r lint:fix"
1212
},

pnpm-lock.yaml

Lines changed: 777 additions & 440 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqlmesh/cli/main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
)
4343
SKIP_CONTEXT_COMMANDS = ("init", "ui")
4444
LOCAL_ONLY_COMMANDS = ("format",)
45+
# Commands that are local-only when they're passed --local.
46+
OPTIONAL_LOCAL_COMMANDS = ("lint", "test")
4547

4648

4749
class _SQLMeshGroup(click.Group):
@@ -129,8 +131,12 @@ def cli(
129131
load = True
130132
# Local-only gating must hold for any number of --paths, so it stays outside the block below.
131133
load_state = ctx.invoked_subcommand not in LOCAL_ONLY_COMMANDS
132-
# The parent callback constructs Context before Click invokes `lint`, so inspect its parsed args here.
133-
if ctx.invoked_subcommand == "lint" and "--local" in ctx.meta["subcommand_args"]:
134+
# The parent callback constructs Context before Click invokes the subcommand, so inspect its
135+
# parsed args here.
136+
if (
137+
ctx.invoked_subcommand in OPTIONAL_LOCAL_COMMANDS
138+
and "--local" in ctx.meta["subcommand_args"]
139+
):
134140
load_state = False
135141

136142
if len(paths) == 1:
@@ -817,6 +823,12 @@ def create_test(
817823
multiple=True,
818824
help="Select specific models to run unit tests for.",
819825
)
826+
@click.option(
827+
"--local",
828+
is_flag=True,
829+
expose_value=False,
830+
help="Run tests using only locally loaded project files without loading state. Tests whose model is not loaded are skipped with a warning rather than failing.",
831+
)
820832
@click.argument("tests", nargs=-1)
821833
@click.pass_obj
822834
@error_handler

sqlmesh/core/engine_adapter/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ def clone_table(
10941094
replace: bool = False,
10951095
exists: bool = True,
10961096
clone_kwargs: t.Optional[t.Dict[str, t.Any]] = None,
1097+
table_format: t.Optional[str] = None,
1098+
table_kind: t.Optional[str] = None,
10971099
**kwargs: t.Any,
10981100
) -> None:
10991101
"""Creates a table with the target name by cloning the source table.
@@ -1103,6 +1105,10 @@ def clone_table(
11031105
source_table_name: The name of the source table that should be cloned.
11041106
replace: Whether or not to replace an existing table.
11051107
exists: Indicates whether to include the IF NOT EXISTS check.
1108+
clone_kwargs: Additional arguments for the CLONE clause.
1109+
table_format: The table format of the source table, if any. Engines that require
1110+
format-specific DDL to clone a table use it to derive `table_kind`.
1111+
table_kind: The kind of table to create. Defaults to `TABLE`.
11061112
"""
11071113
if not self.SUPPORTS_CLONING:
11081114
raise NotImplementedError(f"Engine does not support cloning: {type(self)}")
@@ -1111,7 +1117,7 @@ def clone_table(
11111117
self.execute(
11121118
exp.Create(
11131119
this=exp.to_table(target_table_name),
1114-
kind="TABLE",
1120+
kind=table_kind or "TABLE",
11151121
replace=replace,
11161122
exists=exists,
11171123
clone=exp.Clone(
@@ -1214,9 +1220,15 @@ def get_alter_operations(
12141220
def alter_table(
12151221
self,
12161222
alter_expressions: t.Union[t.List[exp.Alter], t.List[TableAlterOperation]],
1223+
table_format: t.Optional[str] = None,
12171224
) -> None:
12181225
"""
12191226
Performs the alter statements to change the current table into the structure of the target table.
1227+
1228+
Args:
1229+
alter_expressions: The alter operations to apply.
1230+
table_format: The table format of the target table, if any. Engines that require
1231+
format-specific DDL to alter a table use it to adjust the generated statements.
12201232
"""
12211233
with self.transaction():
12221234
for alter_expression in [

0 commit comments

Comments
 (0)