Skip to content

Commit

Permalink
fixup! refactor: generalize _StandardRecipe
Browse files Browse the repository at this point in the history
  • Loading branch information
tigarmo committed Dec 10, 2024
1 parent 724c648 commit 8a606f1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions craft_application/launchpad/models/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import enum
import time
from abc import abstractmethod
from collections.abc import Collection, Iterable
from typing import TYPE_CHECKING, ClassVar, Literal

Expand Down Expand Up @@ -333,9 +334,10 @@ class _StandardRecipe(_StoreRecipe):
"""The artifact type this recipe creates: charm, rock, etc."""

@classmethod
def _lp_recipe(cls, lp: Launchpad) -> Any: # noqa: ANN401 (use of any)
@abstractmethod
def _get_lp_recipe(cls, lp: Launchpad) -> Any: # noqa: ANN401 (use of any)
"""Get the launchpad utility to manipulate recipes."""
raise NotImplementedError
raise NotImplementedError("Must be implemented by subclass.")

@classmethod
def new( # noqa: PLR0913
Expand Down Expand Up @@ -389,7 +391,7 @@ def new( # noqa: PLR0913
created_entry = retry(
f"create {cls.ARTIFACT} recipe {name!r}",
lazr.restfulclient.errors.BadRequest,
cls._lp_recipe(lp).new,
cls._get_lp_recipe(lp).new,
name=name,
owner=util.get_person_link(owner),
project=f"/{project}",
Expand All @@ -413,7 +415,7 @@ def get( # pyright: ignore[reportIncompatibleMethodOverride]
retry(
f"get {cls.ARTIFACT} recipe {name!r}",
lazr.restfulclient.errors.NotFound,
cls._lp_recipe(lp).getByName,
cls._get_lp_recipe(lp).getByName,
name=name,
owner=util.get_person_link(owner),
project=f"/{project}",
Expand All @@ -430,7 +432,9 @@ def find( # pyright: ignore[reportIncompatibleMethodOverride]
) -> Iterable[Self]:
"""Find a recipe by the owner."""
owner = util.get_person_link(owner)
lp_recipes = cls._lp_recipe(lp).findByOwner(owner=util.get_person_link(owner))
lp_recipes = cls._get_lp_recipe(lp).findByOwner(
owner=util.get_person_link(owner)
)
for recipe in lp_recipes:
if name and recipe.name != name:
continue
Expand All @@ -456,7 +460,7 @@ class CharmRecipe(_StandardRecipe):

@override
@classmethod
def _lp_recipe(cls, lp: Launchpad) -> Any:
def _get_lp_recipe(cls, lp: Launchpad) -> Any:
"""https://api.launchpad.net/devel.html#charm_recipes."""
return lp.lp.charm_recipes

Expand Down

0 comments on commit 8a606f1

Please sign in to comment.