@@ -49,7 +49,11 @@ async def _run(self) -> StepResult:
49
49
connector = self .context .connector
50
50
manifest_path = connector .manifest_path
51
51
python_path = connector .python_source_dir_path
52
- if connector .language not in [ConnectorLanguage .PYTHON , ConnectorLanguage .LOW_CODE , ConnectorLanguage .MANIFEST_ONLY ]:
52
+ if connector .language not in [
53
+ ConnectorLanguage .PYTHON ,
54
+ ConnectorLanguage .LOW_CODE ,
55
+ ConnectorLanguage .MANIFEST_ONLY ,
56
+ ]:
53
57
return StepResult (
54
58
step = self ,
55
59
status = StepStatus .SKIPPED ,
@@ -153,7 +157,11 @@ async def _run(self) -> StepResult:
153
157
154
158
data = read_yaml (manifest_path )
155
159
if "streams" not in data :
156
- return StepResult (step = self , status = StepStatus .SKIPPED , stderr = "No manifest streams found." )
160
+ return StepResult (
161
+ step = self ,
162
+ status = StepStatus .SKIPPED ,
163
+ stderr = "No manifest streams found." ,
164
+ )
157
165
158
166
# find the explit ones and remove or udpate
159
167
json_loaders = _find_json_loaders (data , [])
@@ -196,14 +204,43 @@ async def _run(self) -> StepResult:
196
204
_update_inline_schema (schema_loader , json_streams , stream_name )
197
205
198
206
write_yaml (data , manifest_path )
199
- await format_prettier ([manifest_path ])
207
+ await format_prettier ([manifest_path ], logger = logger )
200
208
201
209
for json_stream in json_streams .values ():
202
210
logger .info (f" !! JSON schema not found: { json_stream .name } " )
203
211
204
212
return StepResult (step = self , status = StepStatus .SUCCESS )
205
213
206
214
215
+ class RemoveUnusedJsonSchamas (Step ):
216
+ context : ConnectorContext
217
+
218
+ title = "Cleanup json schemas that are dangling but unused."
219
+
220
+ async def _run (self ) -> StepResult :
221
+ connector = self .context .connector
222
+ connector_path = connector .code_directory
223
+ manifest_path = connector .manifest_path
224
+ python_path = connector .python_source_dir_path
225
+ schemas_path = python_path / SCHEMAS_DIR_NAME
226
+ logger = self .logger
227
+
228
+ manifest = connector .manifest_path .read_text ()
229
+
230
+ if manifest .find ("JsonFileSchemaLoader" ) != - 1 :
231
+ return StepResult (
232
+ step = self ,
233
+ status = StepStatus .SKIPPED ,
234
+ stderr = "Skipping: the manifest is still using JSON Schema loader." ,
235
+ )
236
+
237
+ if schemas_path .exists ():
238
+ logger .info (f" Removing schemnas dir: { schemas_path } " )
239
+ shutil .rmtree (schemas_path )
240
+
241
+ return StepResult (step = self , status = StepStatus .SUCCESS )
242
+
243
+
207
244
@dataclass
208
245
class JsonStream :
209
246
name : str
@@ -370,7 +407,14 @@ async def run_connector_migrate_to_inline_schemas_pipeline(context: ConnectorCon
370
407
371
408
steps_to_run : STEP_TREE = []
372
409
373
- steps_to_run .append ([StepToRun (id = CONNECTOR_TEST_STEP_ID .INLINE_CANDIDATE , step = CheckIsInlineCandidate (context ))])
410
+ steps_to_run .append (
411
+ [
412
+ StepToRun (
413
+ id = CONNECTOR_TEST_STEP_ID .INLINE_CANDIDATE ,
414
+ step = CheckIsInlineCandidate (context ),
415
+ )
416
+ ]
417
+ )
374
418
375
419
steps_to_run .append (
376
420
[
@@ -382,4 +426,14 @@ async def run_connector_migrate_to_inline_schemas_pipeline(context: ConnectorCon
382
426
]
383
427
)
384
428
429
+ steps_to_run .append (
430
+ [
431
+ StepToRun (
432
+ id = CONNECTOR_TEST_STEP_ID .INLINE_CLEANUP ,
433
+ step = RemoveUnusedJsonSchamas (context ),
434
+ depends_on = [CONNECTOR_TEST_STEP_ID .INLINE_MIGRATION ],
435
+ )
436
+ ]
437
+ )
438
+
385
439
return await run_connector_steps (context , semaphore , steps_to_run , restore_original_state = restore_original_state )
0 commit comments