1313from export .cli import export
1414from graph .cli import graph
1515from ingest .cli import ingest
16+ from shared .cache import cache_usage , expunge_cache
1617from shared .settings import LOCAL_DIR , MART_DB_VARS , env
1718from shared .storage import Storage , StoragePrefix
1819
@@ -185,7 +186,7 @@ def backup_ls(include_all: bool):
185186 help = "Model name to transform (can be used multiple times)" ,
186187)
187188@click .option ("--debug" , is_flag = True , help = "Run dbt with the debug flag" )
188- def transform (models : tuple [str ], debug : bool ):
189+ def transform (models : Optional [ tuple [str , ...] ], debug : bool ):
189190 dbt_handler = DBTHandler (debug = debug )
190191 dbt_handler .run (models )
191192
@@ -195,9 +196,18 @@ def transform(models: tuple[str], debug: bool):
195196
196197
197198@dlctl .command (name = "test" , help = "Run data tests" )
198- def test ():
199- dbt_handler = DBTHandler ()
200- dbt_handler .test ()
199+ @click .option (
200+ "--model" ,
201+ "-m" ,
202+ "models" ,
203+ multiple = True ,
204+ type = click .STRING ,
205+ help = "Model name to transform (can be used multiple times)" ,
206+ )
207+ @click .option ("--debug" , is_flag = True , help = "Run dbt with the debug flag" )
208+ def test (models : Optional [tuple [str , ...]], debug : bool ):
209+ dbt_handler = DBTHandler (debug = debug )
210+ dbt_handler .test (models )
201211
202212
203213# Documentation
@@ -243,5 +253,39 @@ def generate_init_sql(path: str):
243253 T .generate_init_sql (path )
244254
245255
256+ # Cache
257+ # =====
258+
259+
260+ @dlctl .group (help = "Manage cache (requests, etc.)" )
261+ def cache ():
262+ pass
263+
264+
265+ @cache .command (name = "clean" , help = "Expunge cache" )
266+ @click .option (
267+ "-ns" ,
268+ "--namespace" ,
269+ type = click .Choice (["requests" , "huggingface" ]),
270+ help = "Limit cache cleaning to a namespace" ,
271+ )
272+ @click .option (
273+ "-n" ,
274+ "--name" ,
275+ type = click .STRING ,
276+ help = "Limit cache cleaning to a specific name (namespace required as well)" ,
277+ )
278+ def cache_clean (namespace : Optional [str ], name : Optional [str ]):
279+ if namespace is None and name is not None :
280+ raise click .UsageError ("name requires that namespace is set" )
281+
282+ expunge_cache (namespace , name )
283+
284+
285+ @cache .command (name = "df" , help = "Calculate cache usage statistics" )
286+ def cache_df ():
287+ cache_usage ()
288+
289+
246290if __name__ == "__main__" :
247291 dlctl ()
0 commit comments