1111import argparse
1212import json
1313import os
14- from typing import Any , IO , MutableMapping , Set , Union , cast
14+ from typing import IO , Any , MutableMapping , Set , Union , cast
1515
1616from cwlformat .formatter import stringify_dict
17- from ruamel import yaml
17+ from ruamel .yaml .main import YAML , dump
18+ from ruamel .yaml .representer import RoundTripRepresenter
19+ from ruamel .yaml .dumper import RoundTripDumper
1820from schema_salad .sourceline import SourceLine , add_lc_filename
1921
2022
@@ -72,7 +74,9 @@ def run(
7274 sourceIO : IO [str ], output_dir : str , output_format : str , mainfile : str , pretty : bool
7375) -> None :
7476 """Loop over the provided packed CWL document and split it up."""
75- source = yaml .main .round_trip_load (sourceIO , preserve_quotes = True )
77+ yaml = YAML (typ = "rt" )
78+ yaml .preserve_quotes = True # type: ignore[assignment]
79+ source = yaml .load (sourceIO )
7680 add_lc_filename (source , sourceIO .name )
7781
7882 if "$graph" not in source :
@@ -87,7 +91,7 @@ def my_represent_none(
8791 """Force clean representation of 'null'."""
8892 return self .represent_scalar ("tag:yaml.org,2002:null" , "null" )
8993
90- yaml . representer . RoundTripRepresenter .add_representer (type (None ), my_represent_none )
94+ RoundTripRepresenter .add_representer (type (None ), my_represent_none )
9195
9296 for entry in source ["$graph" ]:
9397 entry_id = entry .pop ("id" )[1 :]
@@ -205,9 +209,7 @@ def rewrite_schemadef(document: MutableMapping[str, Any]) -> Set[str]:
205209 field ["name" ] = field ["name" ].split ("/" )[2 ]
206210 rewrite_types (field , entry_file , True )
207211 with open (entry_file [1 :], "a" , encoding = "utf-8" ) as entry_handle :
208- yaml .main .dump (
209- [entry ], entry_handle , Dumper = yaml .dumper .RoundTripDumper
210- )
212+ dump ([entry ], entry_handle , Dumper = RoundTripDumper )
211213 entry ["$import" ] = entry_file [1 :]
212214 del entry ["name" ]
213215 del entry ["type" ]
@@ -236,16 +238,17 @@ def json_dump(entry: Any, output_file: str) -> None:
236238
237239def yaml_dump (entry : Any , output_file : str , pretty : bool ) -> None :
238240 """Output object as YAML."""
241+ yaml = YAML (typ = "rt" )
242+ yaml .default_flow_style = False
243+ yaml .map_indent = 4 # type: ignore[assignment]
244+ yaml .sequence_indent = 2 # type: ignore[assignment]
239245 with open (output_file , "w" , encoding = "utf-8" ) as result_handle :
240246 if pretty :
241247 result_handle .write (stringify_dict (entry ))
242248 else :
243- yaml .main . round_trip_dump (
249+ yaml .dump (
244250 entry ,
245251 result_handle ,
246- default_flow_style = False ,
247- indent = 4 ,
248- block_seq_indent = 2 ,
249252 )
250253
251254
0 commit comments