Skip to content

Commit 9ae880c

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

File tree

5 files changed

+55
-31
lines changed

5 files changed

+55
-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: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
BATCH_PREFIX,
1414
)
1515

16+
AILLY_CMD_BASE = [
17+
"ailly",
18+
"--max-depth",
19+
"10",
20+
"--root",
21+
str(AILLY_DIR_PATH),
22+
]
23+
1624
logger = logging.getLogger(__file__)
1725

1826

@@ -23,7 +31,7 @@ def handle_run_ailly(cmd: RunAilly, uow: None):
2331
total_start_time = time.time()
2432

2533
for batch in resolved_batches:
26-
run_ailly_single_batch(batch)
34+
run_ailly_single_batch(batch, cmd.packages)
2735

2836
total_end_time = time.time()
2937
total_duration = total_end_time - total_start_time
@@ -56,19 +64,27 @@ def resolve_requested_batches(batch_names: List[str]) -> List[Path]:
5664
return batch_paths
5765

5866

59-
def run_ailly_single_batch(batch: Path) -> None:
67+
def run_ailly_single_batch(batch: Path, packages: List[str] = []) -> None:
6068
"""Run ailly and process files for a single batch."""
6169
batch_start_time = time.time()
6270
iam_updates_path = AILLY_DIR_PATH / f"updates_{batch.name}.json"
6371

64-
cmd = [
65-
"ailly",
66-
"--max-depth",
67-
"10",
68-
"--root",
69-
str(AILLY_DIR_PATH),
70-
batch.name,
71-
]
72+
if packages:
73+
paths = []
74+
for package in packages:
75+
package_files = [
76+
f"{batch.name}/{p.name}" for p in batch.glob(f"*{package}*.md")
77+
]
78+
paths.extend(package_files)
79+
80+
if not paths:
81+
logger.warning(f"No matching files found for packages: {packages}")
82+
return
83+
84+
cmd = AILLY_CMD_BASE + paths
85+
else:
86+
cmd = AILLY_CMD_BASE + [batch.name]
87+
7288
logger.info(f"Running {cmd}")
7389
run(cmd)
7490

@@ -79,7 +95,9 @@ def run_ailly_single_batch(batch: Path) -> None:
7995
)
8096

8197
logger.info(f"Processing generated content for {batch.name}")
82-
process_ailly_files(input_dir=batch, output_file=iam_updates_path)
98+
process_ailly_files(
99+
input_dir=batch, output_file=iam_updates_path, packages=packages
100+
)
83101

84102

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

178196

179197
def process_ailly_files(
180-
input_dir: Path, output_file: Path, file_pattern: str = "*.md.ailly.md"
198+
input_dir: Path,
199+
output_file: Path,
200+
file_pattern: str = "*.md.ailly.md",
201+
packages: List[str] = [],
181202
) -> None:
182203
"""
183204
Process all .md.ailly.md files in the input directory and write the results as JSON to the output file.
@@ -186,6 +207,7 @@ def process_ailly_files(
186207
input_dir: Directory containing .md.ailly.md files
187208
output_file: Path to the output JSON file
188209
file_pattern: Pattern to match files (default: "*.md.ailly.md")
210+
packages: Optional list of packages to filter by
189211
"""
190212
results = defaultdict(list)
191213

@@ -197,6 +219,13 @@ def process_ailly_files(
197219
package_name = parse_package_name(policy_update)
198220
if not package_name:
199221
raise TypeError(f"Could not get package name from policy update.")
222+
223+
if packages and package_name not in packages:
224+
logger.info(
225+
f"Skipping package {package_name} (not in requested packages)"
226+
)
227+
continue
228+
200229
results[package_name].append(policy_update)
201230

202231
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)