@@ -42,17 +42,23 @@ def generate_entry(
42
42
43
43
44
44
def generate_manifest_file (
45
- json_files : list [Path ], metadata_file : Path , path_prefix : str , outfile : Path
45
+ json_files : list [Path ],
46
+ metadata_file : Path ,
47
+ path_prefix : str ,
48
+ outfile : Path ,
49
+ pretty = False ,
46
50
):
47
51
"""Generates a manifest for all vendordep json files in json_files."""
48
52
metadata_database = load_metadata (metadata_file )
49
53
entries = []
50
54
for file in json_files :
51
55
entries .append (generate_entry (file , path_prefix , metadata_database ))
52
- outfile .write_text (json .dumps (entries , indent = 2 ), newline = "\n " )
53
56
57
+ format_args = {"indent" : 2 } if pretty else {"separators" : ("," , ":" )}
58
+ outfile .write_text (json .dumps (entries , ** format_args ), newline = "\n " )
54
59
55
- def generate_bundle (year : str , root : Path , outdir : Path ):
60
+
61
+ def generate_bundle (year : str , root : Path , outdir : Path , pretty = False ):
56
62
"""Generates a 'bundle' consisting of a YEAR.json manifest and a directory named YEAR containing all of the vendordep files
57
63
58
64
Requires a metadata file YEAR_metadata.json, and a directory named YEAR containing the input vendordeps.
@@ -65,7 +71,7 @@ def generate_bundle(year: str, root: Path, outdir: Path):
65
71
manifest_file = Path (outdir ) / f"{ year } .json"
66
72
vendordeps = [file for file in json_dir .glob ("*.json" )]
67
73
68
- generate_manifest_file (vendordeps , metadata , path_prefix , manifest_file )
74
+ generate_manifest_file (vendordeps , metadata , path_prefix , manifest_file , pretty )
69
75
70
76
# Copy all vendordeps to outdir/YEAR
71
77
depsdir = outdir / year
@@ -91,10 +97,16 @@ def main():
91
97
parser .add_argument (
92
98
"year" , nargs = "+" , type = str , help = "Years to generate bundles for"
93
99
)
94
- args = parser .parse_args ()
95
100
101
+ parser .add_argument (
102
+ "--pretty" ,
103
+ "-p" ,
104
+ action = "store_true" ,
105
+ help = "Pretty-print the output. Without this option, output is minified." ,
106
+ )
107
+ args = parser .parse_args ()
96
108
for year in args .year :
97
- generate_bundle (year , args .root , args .output )
109
+ generate_bundle (year , args .root , args .output , args . pretty )
98
110
99
111
100
112
if __name__ == "__main__" :
0 commit comments