Skip to content

Commit 5ce6524

Browse files
committed
PR feedback
1 parent 697104d commit 5ce6524

6 files changed

Lines changed: 36 additions & 36 deletions

File tree

docs/reference/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Configuration options for SQLMesh environment creation and promotion.
3636
| `physical_schema_mapping` | A mapping from regular expressions to names of schemas in which physical tables for the corresponding models [will be placed](../guides/configuration.md#physical-table-schemas). (Default physical schema name: `sqlmesh__[model schema]`) | dict[string, string] | N |
3737
| `environment_suffix_target` | Whether SQLMesh views should append their environment name to the `schema` or `table` - [additional details](../guides/configuration.md#view-schema-override). (Default: `schema`) | string | N |
3838
| `gateway_managed_virtual_layer` | Whether SQLMesh views of the virtual layer will be created by the default gateway or model specified gateways - [additional details](../guides/multi_engine.md#gateway-managed-virtual-layer). (Default: False) | boolean | N |
39-
| `infer_python_package_requirements` | Whether SQLMesh will statically analyze Python code to automatically infer Python package requirements. (Default: True) | boolean | N |
39+
| `infer_python_dependencies` | Whether SQLMesh will statically analyze Python code to automatically infer Python package requirements. (Default: True) | boolean | N |
4040
| `environment_catalog_mapping` | A mapping from regular expressions to catalog names. The catalog name is used to determine the target catalog for a given environment. | dict[string, string] | N |
4141
| `log_limit` | The default number of logs to keep (Default: `20`) | int | N |
4242

sqlmesh/core/config/root.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Config(BaseConfig):
107107
physical_schema_mapping: A mapping from regular expressions to names of schemas in which physical tables for corresponding models will be placed.
108108
environment_suffix_target: Indicates whether to append the environment name to the schema or table name.
109109
gateway_managed_virtual_layer: Whether the models' views in the virtual layer are created by the model-specific gateway rather than the default gateway.
110-
infer_python_package_requirements: Whether to statically analyze Python code to automatically infer Python package requirements.
110+
infer_python_dependencies: Whether to statically analyze Python code to automatically infer Python package requirements.
111111
environment_catalog_mapping: A mapping from regular expressions to catalog names. The catalog name is used to determine the target catalog for a given environment.
112112
default_target_environment: The name of the environment that will be the default target for the `sqlmesh plan` and `sqlmesh run` commands.
113113
log_limit: The default number of logs to keep.
@@ -147,7 +147,7 @@ class Config(BaseConfig):
147147
default=EnvironmentSuffixTarget.default
148148
)
149149
gateway_managed_virtual_layer: bool = False
150-
infer_python_package_requirements: bool = True
150+
infer_python_dependencies: bool = True
151151
environment_catalog_mapping: RegexKeyDict = {}
152152
default_target_environment: str = c.PROD
153153
log_limit: int = c.DEFAULT_LOG_LIMIT

sqlmesh/core/context.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,6 @@ def __init__(
383383
self.pinned_environments = Environment.sanitize_names(self.config.pinned_environments)
384384
self.auto_categorize_changes = self.config.plan.auto_categorize_changes
385385
self.selected_gateway = gateway or self.config.default_gateway_name
386-
self.gateway_managed_virtual_layer = self.config.gateway_managed_virtual_layer
387-
self.infer_python_package_requirements = self.config.infer_python_package_requirements
388386

389387
gw_model_defaults = self.config.gateways[self.selected_gateway].model_defaults
390388
if gw_model_defaults:
@@ -2587,8 +2585,8 @@ def _context_diff(
25872585
ensure_finalized_snapshots=ensure_finalized_snapshots,
25882586
diff_rendered=diff_rendered,
25892587
environment_statements=self._environment_statements,
2590-
gateway_managed_virtual_layer=self.gateway_managed_virtual_layer,
2591-
infer_python_package_requirements=self.infer_python_package_requirements,
2588+
gateway_managed_virtual_layer=self.config.gateway_managed_virtual_layer,
2589+
infer_python_dependencies=self.config.infer_python_dependencies,
25922590
)
25932591

25942592
def _destroy(self) -> None:

sqlmesh/core/context_diff.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def create(
102102
diff_rendered: bool = False,
103103
environment_statements: t.Optional[t.List[EnvironmentStatements]] = [],
104104
gateway_managed_virtual_layer: bool = False,
105-
infer_python_package_requirements: bool = True,
105+
infer_python_dependencies: bool = True,
106106
) -> ContextDiff:
107107
"""Create a ContextDiff object.
108108
@@ -121,7 +121,7 @@ def create(
121121
environment_statements: A list of `before_all` or `after_all` statements associated with the environment.
122122
gateway_managed_virtual_layer: Whether the models' views in the virtual layer are created by the
123123
model-specific gateway rather than the default gateway.
124-
infer_python_package_requirements: Whether to statically analyze Python code to automatically infer Python
124+
infer_python_dependencies: Whether to statically analyze Python code to automatically infer Python
125125
package requirements.
126126
127127
Returns:
@@ -215,7 +215,7 @@ def create(
215215
provided_requirements or {},
216216
excluded_requirements or set(),
217217
snapshots.values(),
218-
infer_python_package_requirements=infer_python_package_requirements,
218+
infer_python_dependencies=infer_python_dependencies,
219219
)
220220

221221
previous_environment_statements = state_reader.get_environment_statements(environment)
@@ -483,39 +483,41 @@ def _build_requirements(
483483
provided_requirements: t.Dict[str, str],
484484
excluded_requirements: t.Set[str],
485485
snapshots: t.Collection[Snapshot],
486-
infer_python_package_requirements: bool = True,
486+
infer_python_dependencies: bool = True,
487487
) -> t.Dict[str, str]:
488488
requirements = {
489489
k: v for k, v in provided_requirements.items() if k not in excluded_requirements
490490
}
491491

492-
if infer_python_package_requirements:
493-
distributions = metadata.packages_distributions()
492+
if not infer_python_dependencies:
493+
return requirements
494494

495-
for snapshot in snapshots:
496-
if not snapshot.is_model:
495+
distributions = metadata.packages_distributions()
496+
497+
for snapshot in snapshots:
498+
if not snapshot.is_model:
499+
continue
500+
501+
for executable in snapshot.model.python_env.values():
502+
if executable.kind != "import":
497503
continue
498504

499-
for executable in snapshot.model.python_env.values():
500-
if executable.kind != "import":
505+
try:
506+
start = "from " if executable.payload.startswith("from ") else "import "
507+
lib = executable.payload.split(start)[1].split()[0].split(".")[0]
508+
if lib not in distributions:
501509
continue
502510

503-
try:
504-
start = "from " if executable.payload.startswith("from ") else "import "
505-
lib = executable.payload.split(start)[1].split()[0].split(".")[0]
506-
if lib not in distributions:
507-
continue
508-
509-
for dist in distributions[lib]:
510-
if (
511-
dist not in requirements
512-
and dist not in IGNORED_PACKAGES
513-
and dist not in excluded_requirements
514-
):
515-
requirements[dist] = metadata.version(dist)
516-
except metadata.PackageNotFoundError:
517-
from sqlmesh.core.console import get_console
518-
519-
get_console().log_warning(f"Failed to find package for {lib}.")
511+
for dist in distributions[lib]:
512+
if (
513+
dist not in requirements
514+
and dist not in IGNORED_PACKAGES
515+
and dist not in excluded_requirements
516+
):
517+
requirements[dist] = metadata.version(dist)
518+
except metadata.PackageNotFoundError:
519+
from sqlmesh.core.console import get_console
520+
521+
get_console().log_warning(f"Failed to find package for {lib}.")
520522

521523
return requirements

tests/core/test_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ def test_deactivate_automatic_requirement_inference(copy_to_temp_path: t.Callabl
12441244
context_path = copy_to_temp_path("examples/sushi")[0]
12451245
config = next(iter(load_configs("config", Config, paths=context_path).values()))
12461246

1247-
config.infer_python_package_requirements = False
1247+
config.infer_python_dependencies = False
12481248
context = Context(paths=context_path, config=config)
12491249
environment = context.plan(
12501250
"dev", no_prompts=True, skip_tests=True, skip_backfill=True, auto_apply=True

tests/core/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5050,7 +5050,7 @@ def test_multi_virtual_layer(copy_to_temp_path):
50505050
assert len(prod_environment.snapshots_) == 3
50515051

50525052
# Changing the flag should show a diff
5053-
context.gateway_managed_virtual_layer = False
5053+
context.config.gateway_managed_virtual_layer = False
50545054
plan = context.plan_builder().build()
50555055
assert not plan.requires_backfill
50565056
assert (

0 commit comments

Comments
 (0)