Skip to content

Commit 8a8da14

Browse files
committed
Add packages option to run-ailly
1 parent 9d6b0c4 commit 8a8da14

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

aws_doc_sdk_examples_tools/lliam/domain/commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class CreatePrompts(Command):
1717
@dataclass
1818
class RunAilly(Command):
1919
batches: List[str]
20+
packages: List[str]
2021

2122

2223
@dataclass

aws_doc_sdk_examples_tools/lliam/entry_points/lliam_app.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import logging
66
import typer
77

8-
from aws_doc_sdk_examples_tools.lliam.config import (
9-
AILLY_DIR,
10-
BATCH_PREFIX
11-
)
8+
from aws_doc_sdk_examples_tools.lliam.config import AILLY_DIR, BATCH_PREFIX
129
from aws_doc_sdk_examples_tools.lliam.domain import commands
1310
from aws_doc_sdk_examples_tools.lliam.service_layer import messagebus, unit_of_work
1411

@@ -38,18 +35,21 @@ def create_prompts(iam_tributary_root: str, system_prompts: List[str] = []):
3835
def run_ailly(
3936
batches: Annotated[
4037
Optional[str],
41-
typer.Option(
42-
help="Batch names to process (comma-separated list)"
43-
),
38+
typer.Option(help="Batch names to process (comma-separated list)"),
39+
] = None,
40+
packages: Annotated[
41+
Optional[str], typer.Option(help="Comma delimited list of packages to update")
4442
] = None,
4543
) -> None:
4644
"""
4745
Run ailly to generate IAM policy content and process the results.
4846
If batches is specified, only those batches will be processed.
4947
If batches is omitted, all batches will be processed.
48+
If packages is specified, only those packages will be processed.
5049
"""
5150
requested_batches = parse_batch_names(batches)
52-
cmd = commands.RunAilly(batches=requested_batches)
51+
package_names = parse_package_names(packages)
52+
cmd = commands.RunAilly(batches=requested_batches, packages=package_names)
5353
messagebus.handle(cmd)
5454

5555

@@ -58,9 +58,7 @@ def update_reservoir(
5858
iam_tributary_root: str,
5959
batches: Annotated[
6060
Optional[str],
61-
typer.Option(
62-
help="Batch names to process (comma-separated list)"
63-
),
61+
typer.Option(help="Batch names to process (comma-separated list)"),
6462
] = None,
6563
packages: Annotated[
6664
Optional[str], typer.Option(help="Comma delimited list of packages to update")
@@ -86,7 +84,7 @@ def parse_batch_names(batch_names_str: Optional[str]) -> List[str]:
8684
"""
8785
if not batch_names_str:
8886
return []
89-
87+
9088
batch_names = []
9189

9290
for name in batch_names_str.split(","):

aws_doc_sdk_examples_tools/lliam/service_layer/messagebus.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
Message = commands.Command
1313

1414

15-
def handle(
16-
message: commands.Command, uow: Optional[unit_of_work.FsUnitOfWork] = None
17-
):
15+
def handle(message: commands.Command, uow: Optional[unit_of_work.FsUnitOfWork] = None):
1816
queue = [message]
1917

2018
while queue:
@@ -25,9 +23,7 @@ def handle(
2523
raise Exception(f"{message} was not a Command")
2624

2725

28-
def handle_command(
29-
command: commands.Command, uow: Optional[unit_of_work.FsUnitOfWork]
30-
):
26+
def handle_command(command: commands.Command, uow: Optional[unit_of_work.FsUnitOfWork]):
3127
handler = COMMAND_HANDLERS[type(command)]
3228
handler(command, uow)
3329

aws_doc_sdk_examples_tools/lliam/service_layer/run_ailly.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
import sys
34
import time
45
from collections import defaultdict
56
from datetime import timedelta
@@ -13,6 +14,14 @@
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+
1625
logger = 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

85104
EXPECTED_KEYS: Set[str] = set(["title", "title_abbrev"])
@@ -177,7 +196,10 @@ def parse_package_name(policy_update: Dict[str, str]) -> Optional[str]:
177196

178197

179198
def 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:

aws_doc_sdk_examples_tools/lliam/service_layer/update_doc_gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def make_title_abbreviation(old: Example, new: Example, abbreviations: Counter):
4848
version = language.versions[0]
4949
source = version.source
5050
source_title = source.title if source else ""
51-
base = f"{new.title_abbrev} (from '{source_title}' docs)"
51+
base = f"{new.title_abbrev} (from '{source_title}' guide)"
5252
abbreviations[base] += 1
5353
count = abbreviations[base]
5454
return f"{base} ({count})" if count > 1 else base

0 commit comments

Comments
 (0)