Skip to content

Commit 9919f6a

Browse files
committed
Rename to formatting
1 parent d4c4339 commit 9919f6a

10 files changed

Lines changed: 28 additions & 24 deletions

File tree

docs/concepts/models/overview.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ to `false` causes SQLMesh to disable query canonicalization & simplification. Th
457457
### ignored_rules
458458
: Specifies which linter rules should be ignored/excluded for this model.
459459

460+
### formatting
461+
: Whether the model will be formatted. All models are formatted by default. Setting this to `false` causes SQLMesh to ignore this model during `sqlmesh format`.
462+
460463
## Incremental Model Properties
461464

462465
These properties can be specified in an incremental model's `kind` definition.

docs/reference/model_configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Configuration options for SQLMesh model properties. Supported by all model kinds
4040
| `gateway` | Specifies the gateway to use for the execution of this model. When not specified, the default gateway is used. | str | N |
4141
| `optimize_query` | Whether the model's query should be optimized. This attribute is `true` by default. Setting it to `false` causes SQLMesh to disable query canonicalization & simplification. This should be turned off only if the optimized query leads to errors such as surpassing text limit. | bool | N |
4242
| `ignored_rules` | A list of linter rule names (or "ALL") to be ignored/excluded for this model | str \| array[str] | N |
43-
43+
| `formatting` | Whether the model will be formatted. All models are formatted by default. Setting this to `false` causes SQLMesh to ignore this model during `sqlmesh format`. | bool | N |
4444
### Model defaults
4545

4646
The SQLMesh project-level configuration must contain the `model_defaults` key and must specify a value for its `dialect` key. Other values are set automatically unless explicitly overridden in the model definition. Learn more about project-level configuration in the [configuration guide](../guides/configuration.md).

sqlmesh/core/audit/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class AuditMixin(AuditCommonMetaMixin):
7171
defaults: t.Dict[str, exp.Expression]
7272
expressions_: t.Optional[t.List[exp.Expression]]
7373
jinja_macros: JinjaMacroRegistry
74-
format: t.Optional[bool] = Field(default=None, exclude=True)
74+
formatting: t.Optional[bool] = Field(default=None, exclude=True)
7575

7676
@property
7777
def expressions(self) -> t.List[exp.Expression]:

sqlmesh/core/config/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ModelDefaultsConfig(BaseConfig):
6060
allow_partials: t.Optional[t.Union[str, bool]] = None
6161
interval_unit: t.Optional[t.Union[str, IntervalUnit]] = None
6262
enabled: t.Optional[t.Union[str, bool]] = None
63-
format: t.Optional[t.Union[str, bool]] = None
63+
formatting: t.Optional[t.Union[str, bool]] = None
6464

6565
_model_kind_validator = model_kind_validator
6666
_on_destructive_change_validator = on_destructive_change_validator

sqlmesh/core/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ def format(
10891089

10901090
for target in filtered_targets:
10911091
if (
1092-
target._path is None or target.format is False
1092+
target._path is None or target.formatting is False
10931093
): # introduced to satisfy type checker as still want to pull filter out as many targets as possible before loop
10941094
continue
10951095

sqlmesh/core/model/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def sorted_python_env_payloads(python_env: t.Dict[str, Executable]) -> t.List[st
386386
"allow_partials",
387387
"enabled",
388388
"optimize_query",
389-
"format",
389+
"formatting",
390390
mode="before",
391391
check_fields=False,
392392
)(parse_bool)

sqlmesh/core/model/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ModelMeta(_Node):
8080
ignored_rules_: t.Optional[t.Set[str]] = Field(
8181
default=None, exclude=True, alias="ignored_rules"
8282
)
83-
format: t.Optional[bool] = Field(default=None, exclude=True)
83+
formatting: t.Optional[bool] = Field(default=None, exclude=True)
8484

8585
_bool_validator = bool_validator
8686
_model_kind_validator = model_kind_validator

tests/core/test_audit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,13 +962,13 @@ def test_multiple_audits_with_same_name():
962962
assert model.audits[1][1] == model.audits[2][1]
963963

964964

965-
def test_audit_format_flag_serde():
965+
def test_audit_formatting_flag_serde():
966966
expressions = parse(
967967
"""
968968
AUDIT (
969969
name my_audit,
970970
dialect bigquery,
971-
format false,
971+
formatting false,
972972
);
973973
974974
SELECT * FROM db.table WHERE col = @VAR('test_var')
@@ -984,7 +984,7 @@ def test_audit_format_flag_serde():
984984

985985
audit_json = audit.json()
986986

987-
assert "format" not in json.loads(audit_json)
987+
assert "formatting" not in json.loads(audit_json)
988988

989989
deserialized_audit = ModelAudit.parse_raw(audit_json)
990990
assert deserialized_audit.dict() == audit.dict()

tests/core/test_format.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,23 @@ def test_format_files(tmp_path: pathlib.Path, mocker: MockerFixture):
103103
)
104104

105105

106-
def test_ignore_format_files(tmp_path: pathlib.Path):
106+
def test_ignore_formating_files(tmp_path: pathlib.Path):
107107
models_dir = pathlib.Path("models")
108108
audits_dir = pathlib.Path("audits")
109109

110110
# Case 1: Model and Audit are not formatted if the flag is set to false (overriding defaults)
111-
model1_text = "MODEL(name this.model1, dialect 'duckdb', format false); SELECT 1 col"
111+
model1_text = "MODEL(name this.model1, dialect 'duckdb', formatting false); SELECT 1 col"
112112
model1 = create_temp_file(tmp_path, pathlib.Path(models_dir, "model_1.sql"), model1_text)
113113

114-
audit1_text = "AUDIT(name audit1, dialect 'duckdb', format false); SELECT col1 col2 FROM @this_model WHERE foo < 0;"
114+
audit1_text = "AUDIT(name audit1, dialect 'duckdb', formatting false); SELECT col1 col2 FROM @this_model WHERE foo < 0;"
115115
audit1 = create_temp_file(tmp_path, pathlib.Path(audits_dir, "audit_1.sql"), audit1_text)
116116

117-
audit2_text = "AUDIT(name audit2, dialect 'duckdb', standalone true, format false); SELECT col1 col2 FROM @this_model WHERE foo < 0;"
117+
audit2_text = "AUDIT(name audit2, dialect 'duckdb', standalone true, formatting false); SELECT col1 col2 FROM @this_model WHERE foo < 0;"
118118
audit2 = create_temp_file(tmp_path, pathlib.Path(audits_dir, "audit_2.sql"), audit2_text)
119119

120-
Context(paths=tmp_path, config=Config(model_defaults=ModelDefaultsConfig(format=True))).format()
120+
Context(
121+
paths=tmp_path, config=Config(model_defaults=ModelDefaultsConfig(formatting=True))
122+
).format()
121123

122124
assert model1.read_text(encoding="utf-8") == model1_text
123125
assert audit1.read_text(encoding="utf-8") == audit1_text
@@ -127,20 +129,19 @@ def test_ignore_format_files(tmp_path: pathlib.Path):
127129
model2_text = "MODEL(name this.model2, dialect 'duckdb'); SELECT 1 col"
128130
model2 = create_temp_file(tmp_path, pathlib.Path(models_dir, "model_2.sql"), model2_text)
129131

130-
model3_text = (
131-
"MODEL(name this.model3, dialect 'duckdb', format false, format true); SELECT 1 col"
132-
)
132+
model3_text = "MODEL(name this.model3, dialect 'duckdb', formatting true); SELECT 1 col"
133133
model3 = create_temp_file(tmp_path, pathlib.Path(models_dir, "model_3.sql"), model3_text)
134134

135135
Context(
136-
paths=tmp_path, config=Config(model_defaults=ModelDefaultsConfig(format=False))
136+
paths=tmp_path, config=Config(model_defaults=ModelDefaultsConfig(formatting=False))
137137
).format()
138138

139-
# Model is not formatted if the defaults flag is set to false
139+
# Case 2.1: Model is not formatted if the defaults flag is set to false
140140
assert model2.read_text(encoding="utf-8") == model2_text
141141

142-
# Model is formatted if it's flag is set to true, overriding defaults
142+
print(f"model3: {model3.read_text(encoding='utf-8')}")
143+
# Case 2.2: Model is formatted if it's flag is set to true, overriding defaults
143144
assert (
144145
model3.read_text(encoding="utf-8")
145-
== "MODEL (\n name this.model3,\n dialect 'duckdb',\n format FALSE,\n format TRUE\n);\n\nSELECT\n 1 AS col"
146+
== "MODEL (\n name this.model3,\n dialect 'duckdb',\n formatting TRUE\n);\n\nSELECT\n 1 AS col"
146147
)

tests/core/test_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9031,12 +9031,12 @@ def test_var_in_def(assert_exp_eq):
90319031
)
90329032

90339033

9034-
def test_format_flag_serde():
9034+
def test_formatting_flag_serde():
90359035
expressions = d.parse(
90369036
"""
90379037
MODEL(
90389038
name test_model,
9039-
format False,
9039+
formatting False,
90409040
);
90419041
SELECT * FROM tbl;
90429042
""",
@@ -9047,7 +9047,7 @@ def test_format_flag_serde():
90479047

90489048
model_json = model.json()
90499049

9050-
assert "format" not in json.loads(model_json)
9050+
assert "formatting" not in json.loads(model_json)
90519051

90529052
deserialized_model = SqlModel.parse_raw(model_json)
90539053
assert deserialized_model.dict() == model.dict()

0 commit comments

Comments
 (0)