Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify extract_plugin_properties #787

Merged
merged 1 commit into from
Jul 18, 2024
Merged
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
20 changes: 7 additions & 13 deletions craft_parts/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import abc
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Type
from typing import TYPE_CHECKING, Any, Collection, Dict, List, Set, Type

from craft_parts.actions import ActionProperties

Expand Down Expand Up @@ -132,7 +132,7 @@ class PluginModel(PluginPropertiesModel):


def extract_plugin_properties(
data: Dict[str, Any], *, plugin_name: str, required: Optional[List[str]] = None
data: Dict[str, Any], *, plugin_name: str, required: Collection[str] = ()
lengau marked this conversation as resolved.
Show resolved Hide resolved
) -> Dict[str, Any]:
"""Obtain plugin-specifc entries from part properties.

Expand All @@ -143,14 +143,8 @@ def extract_plugin_properties(

:return: A dictionary with plugin properties.
"""
if required is None:
required = []

plugin_data: Dict[str, Any] = {}
prefix = f"{plugin_name}-"

for key, value in data.items():
if key.startswith(prefix) or key in required:
plugin_data[key] = value

return plugin_data
return {
key: value
for key, value in data.items()
if key.startswith(f"{plugin_name}-") or key in required
}
Loading