11import json
22import logging
3+ import sys
34import time
45from collections import defaultdict
56from datetime import timedelta
1314 BATCH_PREFIX ,
1415)
1516
17+ AILLY_CMD_BASE = [
18+ "ailly" ,
19+ "--max-depth" ,
20+ "10" ,
21+ "--root" ,
22+ str (AILLY_DIR_PATH ),
23+ ]
24+
1625logger = logging .getLogger (__file__ )
1726
1827
@@ -23,7 +32,7 @@ def handle_run_ailly(cmd: RunAilly, uow: None):
2332 total_start_time = time .time ()
2433
2534 for batch in resolved_batches :
26- run_ailly_single_batch (batch )
35+ run_ailly_single_batch (batch , cmd . packages )
2736
2837 total_end_time = time .time ()
2938 total_duration = total_end_time - total_start_time
@@ -56,19 +65,27 @@ def resolve_requested_batches(batch_names: List[str]) -> List[Path]:
5665 return batch_paths
5766
5867
59- def run_ailly_single_batch (batch : Path ) -> None :
68+ def run_ailly_single_batch (batch : Path , packages : List [ str ] = [] ) -> None :
6069 """Run ailly and process files for a single batch."""
6170 batch_start_time = time .time ()
6271 iam_updates_path = AILLY_DIR_PATH / f"updates_{ batch .name } .json"
6372
64- cmd = [
65- "ailly" ,
66- "--max-depth" ,
67- "10" ,
68- "--root" ,
69- str (AILLY_DIR_PATH ),
70- batch .name ,
71- ]
73+ if packages :
74+ paths = []
75+ for package in packages :
76+ package_files = [
77+ f"{ batch .name } /{ p .name } " for p in batch .glob (f"*{ package } *.md" )
78+ ]
79+ paths .extend (package_files )
80+
81+ if not paths :
82+ logger .error (f"No matching files found for packages: { packages } " )
83+ sys .exit (1 )
84+
85+ cmd = AILLY_CMD_BASE + paths
86+ else :
87+ cmd = AILLY_CMD_BASE + [batch .name ]
88+
7289 logger .info (f"Running { cmd } " )
7390 run (cmd )
7491
@@ -79,7 +96,9 @@ def run_ailly_single_batch(batch: Path) -> None:
7996 )
8097
8198 logger .info (f"Processing generated content for { batch .name } " )
82- process_ailly_files (input_dir = batch , output_file = iam_updates_path )
99+ process_ailly_files (
100+ input_dir = batch , output_file = iam_updates_path , packages = packages
101+ )
83102
84103
85104EXPECTED_KEYS : Set [str ] = set (["title" , "title_abbrev" ])
@@ -177,7 +196,10 @@ def parse_package_name(policy_update: Dict[str, str]) -> Optional[str]:
177196
178197
179198def process_ailly_files (
180- input_dir : Path , output_file : Path , file_pattern : str = "*.md.ailly.md"
199+ input_dir : Path ,
200+ output_file : Path ,
201+ file_pattern : str = "*.md.ailly.md" ,
202+ packages : List [str ] = [],
181203) -> None :
182204 """
183205 Process all .md.ailly.md files in the input directory and write the results as JSON to the output file.
@@ -186,6 +208,7 @@ def process_ailly_files(
186208 input_dir: Directory containing .md.ailly.md files
187209 output_file: Path to the output JSON file
188210 file_pattern: Pattern to match files (default: "*.md.ailly.md")
211+ packages: Optional list of packages to filter by
189212 """
190213 results = defaultdict (list )
191214
@@ -197,6 +220,13 @@ def process_ailly_files(
197220 package_name = parse_package_name (policy_update )
198221 if not package_name :
199222 raise TypeError (f"Could not get package name from policy update." )
223+
224+ if packages and package_name not in packages :
225+ logger .info (
226+ f"Skipping package { package_name } (not in requested packages)"
227+ )
228+ continue
229+
200230 results [package_name ].append (policy_update )
201231
202232 with open (output_file , "w" , encoding = "utf-8" ) as out_file :
0 commit comments