Skip to content

Commit 6bd9463

Browse files
use cache_dir name everywhere for clarity
1 parent a255e5f commit 6bd9463

File tree

11 files changed

+37
-31
lines changed

11 files changed

+37
-31
lines changed

sqlmesh/core/config/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def create_state_sync(self, context: GenericContext) -> StateSync:
105105

106106
schema = context.config.get_state_schema(context.gateway)
107107
return EngineAdapterStateSync(
108-
engine_adapter, schema=schema, context_path=context.cache_dir, console=context.console
108+
engine_adapter, schema=schema, cache_dir=context.cache_dir, console=context.console
109109
)
110110

111111
def state_sync_fingerprint(self, context: GenericContext) -> str:

sqlmesh/core/context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def upsert_model(self, model: t.Union[str, Model], **kwargs: t.Any) -> Model:
507507
update_model_schemas(
508508
self.dag,
509509
models=self._models,
510-
cache_path=self.cache_dir,
510+
cache_dir=self.cache_dir,
511511
)
512512

513513
if model.dialect:
@@ -647,7 +647,7 @@ def load(self, update_schemas: bool = True) -> GenericContext[C]:
647647
update_model_schemas(
648648
self.dag,
649649
models=self._models,
650-
cache_path=self.cache_dir,
650+
cache_dir=self.cache_dir,
651651
)
652652

653653
models = self.models.values()
@@ -2757,7 +2757,7 @@ def _new_selector(
27572757
dag=dag,
27582758
default_catalog=self.default_catalog,
27592759
dialect=self.default_dialect,
2760-
cache_path=self.cache_dir,
2760+
cache_dir=self.cache_dir,
27612761
)
27622762

27632763
def _register_notification_targets(self) -> None:

sqlmesh/core/model/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
def update_model_schemas(
2323
dag: DAG[str],
2424
models: UniqueKeyDict[str, Model],
25-
cache_path: Path,
25+
cache_dir: Path,
2626
) -> None:
2727
schema = MappingSchema(normalize=False)
28-
optimized_query_cache: OptimizedQueryCache = OptimizedQueryCache(cache_path)
28+
optimized_query_cache: OptimizedQueryCache = OptimizedQueryCache(cache_dir)
2929

3030
_update_model_schemas(dag, models, schema, optimized_query_cache)
3131

sqlmesh/core/selector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ def __init__(
3535
dag: t.Optional[DAG[str]] = None,
3636
default_catalog: t.Optional[str] = None,
3737
dialect: t.Optional[str] = None,
38-
cache_path: t.Optional[Path] = None,
38+
cache_dir: t.Optional[Path] = None,
3939
):
4040
self._state_reader = state_reader
4141
self._models = models
4242
self._context_path = context_path
43-
self._cache_path = cache_path if cache_path else context_path / c.CACHE
43+
self._cache_dir = cache_dir if cache_dir else context_path / c.CACHE
4444
self._default_catalog = default_catalog
4545
self._dialect = dialect
4646
self._git_client = GitClient(context_path)
@@ -160,7 +160,7 @@ def get_model(fqn: str) -> t.Optional[Model]:
160160
models[model.fqn] = model
161161

162162
if needs_update:
163-
update_model_schemas(dag, models=models, cache_path=self._cache_path)
163+
update_model_schemas(dag, models=models, cache_dir=self._cache_dir)
164164

165165
return models
166166

sqlmesh/core/state_sync/db/facade.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,20 @@ class EngineAdapterStateSync(StateSync):
7979
engine_adapter: The EngineAdapter to use to store and fetch snapshots.
8080
schema: The schema to store state metadata in. If None or empty string then no schema is defined
8181
console: The console to log information to.
82-
context_path: The context path, used for caching snapshot models.
82+
cache_dir: The cache path, used for caching snapshot models.
8383
"""
8484

8585
def __init__(
8686
self,
8787
engine_adapter: EngineAdapter,
8888
schema: t.Optional[str],
8989
console: t.Optional[Console] = None,
90-
context_path: Path = Path(),
90+
cache_dir: Path = Path(),
9191
):
9292
self.plan_dags_table = exp.table_("_plan_dags", db=schema)
9393
self.interval_state = IntervalState(engine_adapter, schema=schema)
9494
self.environment_state = EnvironmentState(engine_adapter, schema=schema)
95-
self.snapshot_state = SnapshotState(
96-
engine_adapter, schema=schema, context_path=context_path
97-
)
95+
self.snapshot_state = SnapshotState(engine_adapter, schema=schema, cache_dir=cache_dir)
9896
self.version_state = VersionState(engine_adapter, schema=schema)
9997
self.migrator = StateMigrator(
10098
engine_adapter,

sqlmesh/core/state_sync/db/snapshot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
self,
5353
engine_adapter: EngineAdapter,
5454
schema: t.Optional[str] = None,
55-
context_path: Path = Path(),
55+
cache_dir: Path = Path(),
5656
):
5757
self.engine_adapter = engine_adapter
5858
self.snapshots_table = exp.table_("_snapshots", db=schema)
@@ -78,7 +78,7 @@ def __init__(
7878
"next_auto_restatement_ts": exp.DataType.build("bigint"),
7979
}
8080

81-
self._snapshot_cache = SnapshotCache(context_path)
81+
self._snapshot_cache = SnapshotCache(cache_dir)
8282

8383
def push_snapshots(self, snapshots: t.Iterable[Snapshot], overwrite: bool = False) -> None:
8484
"""Pushes snapshots to the state store.

sqlmesh/dbt/loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ def __init__(
329329
self._yaml_max_mtimes = yaml_max_mtimes
330330

331331
target = t.cast(TargetConfig, project.context.target)
332-
cache_path = loader.context.cache_dir / target.name
333-
self._model_cache = ModelCache(cache_path)
332+
cache_dir = loader.context.cache_dir / target.name
333+
self._model_cache = ModelCache(cache_dir)
334334

335335
def get_or_load_models(
336336
self, target_path: Path, loader: t.Callable[[], t.List[Model]]

sqlmesh/dbt/manifest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(
7777
profile_name: str,
7878
target: TargetConfig,
7979
variable_overrides: t.Optional[t.Dict[str, t.Any]] = None,
80-
cache_path: t.Optional[str] = None,
80+
cache_dir: t.Optional[str] = None,
8181
):
8282
self.project_path = project_path
8383
self.profiles_path = profiles_path
@@ -101,15 +101,15 @@ def __init__(
101101
self._disabled_refs: t.Optional[t.Set[str]] = None
102102
self._disabled_sources: t.Optional[t.Set[str]] = None
103103

104-
if cache_path is not None:
105-
cache_dir = Path(cache_path)
106-
if not cache_dir.is_absolute():
107-
cache_dir = self.project_path / cache_dir
104+
if cache_dir is not None:
105+
cache_path = Path(cache_dir)
106+
if not cache_path.is_absolute():
107+
cache_path = self.project_path / cache_path
108108
else:
109-
cache_dir = self.project_path / c.CACHE
109+
cache_path = self.project_path / c.CACHE
110110

111111
self._call_cache: FileCache[t.Dict[str, t.List[CallNames]]] = FileCache(
112-
cache_dir, "jinja_calls"
112+
cache_path, "jinja_calls"
113113
)
114114

115115
self._on_run_start_per_package: t.Dict[str, HookConfigs] = defaultdict(dict)

sqlmesh/dbt/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def load(cls, context: DbtContext, variables: t.Optional[t.Dict[str, t.Any]] = N
7575
profile_name,
7676
target=profile.target,
7777
variable_overrides=variable_overrides,
78-
cache_path=context.sqlmesh_config.cache_dir,
78+
cache_dir=context.sqlmesh_config.cache_dir,
7979
)
8080

8181
extra_fields = profile.target.extra

tests/core/state_sync/test_export_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def state_sync(tmp_path: Path, example_project_config: Config) -> StateSync:
3333
return EngineAdapterStateSync(
3434
engine_adapter=example_project_config.get_state_connection("main").create_engine_adapter(), # type: ignore
3535
schema=c.SQLMESH,
36-
context_path=tmp_path,
36+
cache_dir=tmp_path / c.CACHE,
3737
)
3838

3939

0 commit comments

Comments
 (0)