cipd_roll: Add annotations
Also rename process_package() to update_package() to match the other
'*_roll' modules more closely.
Bug: b/341756093
Change-Id: I216b82adf765c8d9b0b096ae2b30d255d55357e7
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/230654
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
diff --git a/recipe_modules/cipd_roll/api.py b/recipe_modules/cipd_roll/api.py
index 1a76314..d7689ff 100644
--- a/recipe_modules/cipd_roll/api.py
+++ b/recipe_modules/cipd_roll/api.py
@@ -39,7 +39,7 @@
old_version: str
new_version: str
- def message(self):
+ def message(self) -> str:
return f'From {self.old_version}\nTo {self.new_version}'
@@ -47,7 +47,7 @@
class Commit:
rolls: List[Roll] = dataclasses.field(default_factory=list)
- def message(self, name: str | None = None):
+ def message(self, name: str | None = None) -> str:
rolls = sorted(self.rolls)
if not name:
@@ -79,7 +79,7 @@
Roll = Roll
Commit = Commit
- def is_platform(self, part):
+ def is_platform(self, part: str) -> bool:
"""Return true for platform-style strings.
Example matches: "linux-amd64", "${platform}", "${os}-amd64", "cp38".
@@ -98,7 +98,11 @@
except ValueError:
return False
- def find_shared_tags(self, package_tags, tag):
+ def find_shared_tags(
+ self,
+ package_tags: dict[str, set[str]],
+ tag: str,
+ ) -> set[str]:
"""Attempts to find a tag shared by all packages.
This function can be used if the intersection of the sets of tags
@@ -155,7 +159,11 @@
# We failed to find any tag that meets our criteria.
return set()
- def process_package(self, checkout_root, pkg):
+ def update_package(
+ self,
+ checkout_root: config_types.Path,
+ pkg: str,
+ ) -> Roll:
json_path = checkout_root.joinpath(*re.split(r'[\\/]+', pkg.json_path))
if not pkg.name:
diff --git a/recipe_modules/cipd_roll/tests/full.py b/recipe_modules/cipd_roll/tests/full.py
index 60de76c..291a977 100644
--- a/recipe_modules/cipd_roll/tests/full.py
+++ b/recipe_modules/cipd_roll/tests/full.py
@@ -42,7 +42,7 @@
commit = api.cipd_roll.Commit()
for pkg in props.packages:
with api.step.nest(pkg.spec):
- roll = api.cipd_roll.process_package(
+ roll = api.cipd_roll.update_package(
api.path.start_dir / 'checkout',
pkg,
)
diff --git a/recipes/cipd_roller.py b/recipes/cipd_roller.py
index 3148c91..b48e04c 100644
--- a/recipes/cipd_roller.py
+++ b/recipes/cipd_roller.py
@@ -47,7 +47,7 @@
for pkg in props.packages:
with api.step.nest(pkg.spec):
- roll = api.cipd_roll.process_package(checkout.root, pkg)
+ roll = api.cipd_roll.update_package(checkout.root, pkg)
if roll:
commit.rolls.append(roll)