Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/+api_quirk.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed deprecated `api_quirk` decorator. Use `api_spec_quirk` instead.
39 changes: 3 additions & 36 deletions pulp-glue/src/pulp_glue/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,34 +139,9 @@ def preprocess_payload(payload: EntityDefinition) -> EntityDefinition:
)


_REGISTERED_API_QUIRKS: list[tuple[PluginRequirement, t.Callable[[OpenAPI], None]]] = []
_REGISTERED_API_SPEC_QUIRKS: list[tuple[PluginRequirement, t.Callable[[t.Any], t.Any]]] = []


@deprecated("This decorator is deprecated. Please use api_spec_quirk instead.")
def api_quirk(
req: PluginRequirement,
) -> t.Callable[[t.Callable[[OpenAPI], None]], None]:
"""
A function decorator to allow manipulating API specs based on the availability of plugins.

Parameters:
req: The plugin specifier to determine when the quirk should be applied.

Examples:
```
@api_quirk(PluginRequirement("catdog", specifier="<1.5.2"))
def patch_barking_filter_type(api: OpenAPI) -> None:
# fixup api.api_spec here
```
"""

def _decorator(patch: t.Callable[[OpenAPI], None]) -> None:
_REGISTERED_API_QUIRKS.append((req, patch))

return _decorator


def api_spec_quirk(
req: PluginRequirement,
) -> t.Callable[[t.Callable[[t.Any], t.Any]], None]:
Expand All @@ -178,8 +153,8 @@ def api_spec_quirk(

Examples:
```
@api_quirk(PluginRequirement("catdog", specifier="<1.5.2"))
def patch_barking_filter_type(api_spec: t.Any) -> None:
@api_spec_quirk(PluginRequirement("catdog", specifier="<1.5.2"))
def patch_barking_filter_type(api_spec: t.Any) -> t.Any:
# Fixup api_spec here.
# This can be destructive on api_spec.
return api_spec
Expand Down Expand Up @@ -407,14 +382,6 @@ def from_config(cls, config: dict[str, t.Any]) -> "t.Self":
api_kwargs=api_kwargs,
)

def _patch_api_spec(self) -> None:
# A place for last minute fixes to the api_spec.
# WARNING: Operations are already indexed at this point.
assert self._api is not None
for req, patch in _REGISTERED_API_QUIRKS:
if self.has_plugin(req):
patch(self._api)

@property
def domain_enabled(self) -> bool:
return t.cast(bool, self.api.api_spec.get("info", {}).get("x-pulp-domain-enabled", False))
Expand Down Expand Up @@ -457,7 +424,6 @@ def api(self) -> OpenAPI:
)
except OpenAPIError as e:
raise PulpException(str(e))
self._patch_api_spec()
# Rerun scheduled version checks
for plugin_requirement in self._needed_plugins:
self.needs_plugin(plugin_requirement)
Expand Down Expand Up @@ -1743,6 +1709,7 @@ def delete(self, non_blocking: bool = False) -> None:
assert self.repository_ctx is not None
self.repository_ctx.modify(remove_content=[self.pulp_href])

@deprecated("The create call can handle the upload logic transparently.")
def upload(
self,
file: t.IO[bytes],
Expand Down
Loading