Skip to content

Commit

Permalink
feat(extensions): pass app name to get_app_snippet()
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>
  • Loading branch information
mr-cal committed Jul 17, 2024
1 parent fa1043d commit d65754b
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions snapcraft/extensions/_ros2_humble_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def get_root_snippet(self) -> Dict[str, Any]:
return root_snippet

@overrides
def get_app_snippet(self) -> Dict[str, Any]:
app_snippet = super().get_app_snippet()
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
app_snippet = super().get_app_snippet(app_name=app_name)
python_paths = app_snippet["environment"]["PYTHONPATH"]
new_python_paths = [
f"$SNAP/opt/ros/underlay_ws/opt/ros/{self.ROS_DISTRO}/lib/python3.10/site-packages",
Expand Down
4 changes: 2 additions & 2 deletions snapcraft/extensions/_ros2_jazzy_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def get_root_snippet(self) -> Dict[str, Any]:
return root_snippet

@overrides
def get_app_snippet(self) -> Dict[str, Any]:
app_snippet = super().get_app_snippet()
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
app_snippet = super().get_app_snippet(app_name=app_name)
python_paths = app_snippet["environment"]["PYTHONPATH"]
new_python_paths = [
f"$SNAP/opt/ros/underlay_ws/opt/ros/{self.ROS_DISTRO}/lib/python3.12/site-packages",
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/extensions/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def _apply_extension(
)

# Apply the app-specific components of the extension (if any)
app_extension = extension.get_app_snippet()
for app_name in app_names:
app_extension = extension.get_app_snippet(app_name=app_name)
app_definition = yaml_data["apps"][app_name]
for property_name, property_value in app_extension.items():
app_definition[property_name] = _apply_extension_property(
Expand Down
7 changes: 5 additions & 2 deletions snapcraft/extensions/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def get_root_snippet(self) -> Dict[str, Any]:
"""Return the root snippet to apply."""

@abc.abstractmethod
def get_app_snippet(self) -> Dict[str, Any]:
"""Return the app snippet to apply."""
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
"""Return the app snippet to apply.
:param app_name: the name of the app where the snippet will be applied
"""

@abc.abstractmethod
def get_part_snippet(self, *, plugin_name: str) -> Dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/extensions/gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def is_experimental(base: Optional[str]) -> bool:
return False

@overrides
def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
command_chain = ["snap/command-chain/desktop-launch"]
if self.yaml_data["base"] == "core24":
command_chain.insert(0, "snap/command-chain/gpu-2404-wrapper")
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/extensions/kde_neon.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def is_experimental(base: Optional[str]) -> bool:
return False

@overrides
def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
return {
"command-chain": ["snap/command-chain/desktop-launch"],
"plugs": ["desktop", "desktop-legacy", "opengl", "wayland", "x11"],
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/extensions/kde_neon_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def is_experimental(base: Optional[str]) -> bool:
return False

@overrides
def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
return {
"command-chain": ["snap/command-chain/desktop-launch6"],
"plugs": [
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/extensions/ros2_humble.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_root_snippet(self) -> Dict[str, Any]:
}

@overrides
def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
python_paths = [
f"$SNAP/opt/ros/{self.ROS_DISTRO}/lib/python3.10/site-packages",
"$SNAP/usr/lib/python3/dist-packages",
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/extensions/ros2_jazzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_root_snippet(self) -> Dict[str, Any]:
}

@overrides
def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
python_paths = [
f"$SNAP/opt/ros/{self.ROS_DISTRO}/lib/python3.12/site-packages",
"$SNAP/usr/lib/python3/dist-packages",
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def is_experimental(base: Optional[str] = None) -> bool:
def get_root_snippet(self) -> Dict[str, Any]:
return {"grade": "fake-grade"}

def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
return {"plugs": ["fake-plug"]}

def get_part_snippet(self, *, plugin_name: str) -> Dict[str, Any]:
Expand Down Expand Up @@ -136,7 +136,7 @@ def is_experimental(base: Optional[str] = None) -> bool:
def get_root_snippet(self) -> Dict[str, Any]:
return {}

def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
return {"plugs": ["fake-plug", "fake-plug-extra"]}

def get_part_snippet(self, *, plugin_name: str) -> Dict[str, Any]:
Expand Down Expand Up @@ -170,7 +170,7 @@ def is_experimental(base: Optional[str] = None) -> bool:
def get_root_snippet(self) -> Dict[str, Any]:
return {"grade": "fake-grade"}

def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
return {"plugs": ["fake-plug"]}

def get_part_snippet(self, *, plugin_name: str) -> Dict[str, Any]:
Expand Down Expand Up @@ -206,7 +206,7 @@ def is_experimental(base: Optional[str] = None) -> bool:
def get_root_snippet(self) -> Dict[str, Any]:
return {}

def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
return {}

def get_part_snippet(self, *, plugin_name: str) -> Dict[str, Any]:
Expand Down Expand Up @@ -242,7 +242,7 @@ def is_experimental(base: Optional[str] = None) -> bool:
def get_root_snippet(self) -> Dict[str, Any]:
return {}

def get_app_snippet(self) -> Dict[str, Any]:
def get_app_snippet(self, *, app_name: str) -> Dict[str, Any]:
return {"plugs": ["fake-plug", "fake-plug-extra"]}

def get_part_snippet(self, *, plugin_name: str) -> Dict[str, Any]:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/extensions/test_gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def test_is_experimental(base):


def test_get_app_snippet(gnome_extension):
assert gnome_extension.get_app_snippet() == {
assert gnome_extension.get_app_snippet(app_name="test-app") == {
"command-chain": ["snap/command-chain/desktop-launch"],
"plugs": ["desktop", "desktop-legacy", "gsettings", "opengl", "wayland", "x11"],
}


def test_get_app_snippet_core24(gnome_extension_core24):
assert gnome_extension_core24.get_app_snippet() == {
assert gnome_extension_core24.get_app_snippet(app_name="test-app") == {
"command-chain": [
"snap/command-chain/gpu-2404-wrapper",
"snap/command-chain/desktop-launch",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/extensions/test_kde_neon.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_is_experimental():


def test_get_app_snippet(kde_neon_extension):
assert kde_neon_extension.get_app_snippet() == {
assert kde_neon_extension.get_app_snippet(app_name="test-app") == {
"command-chain": ["snap/command-chain/desktop-launch"],
"plugs": ["desktop", "desktop-legacy", "opengl", "wayland", "x11"],
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/extensions/test_kde_neon_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_is_experimental():


def test_get_app_snippet(kde_neon_6_extension):
assert kde_neon_6_extension.get_app_snippet() == {
assert kde_neon_6_extension.get_app_snippet(app_name="test-app") == {
"command-chain": ["snap/command-chain/desktop-launch6"],
"plugs": [
"desktop",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/parts/extensions/test_ros2_humble.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_get_app_snippet(self, setup_method_fixture):
"${PYTHONPATH}",
]
extension = setup_method_fixture()
assert extension.get_app_snippet() == {
assert extension.get_app_snippet(app_name="test-app") == {
"command-chain": ["snap/command-chain/ros2-launch"],
"environment": {
"ROS_VERSION": "2",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/parts/extensions/test_ros2_humble_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_get_app_snippet(self, extension_name, extension_class, meta, meta_dev):
"$SNAP/opt/ros/underlay_ws/usr/lib/python3/dist-packages",
]
extension = setup_method_fixture(extension_class)
assert extension.get_app_snippet() == {
assert extension.get_app_snippet(app_name="test-app") == {
"command-chain": ["snap/command-chain/ros2-launch"],
"environment": {
"ROS_VERSION": "2",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/parts/extensions/test_ros2_jazzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_get_app_snippet(self, setup_method_fixture):
"${PYTHONPATH}",
]
extension = setup_method_fixture()
assert extension.get_app_snippet() == {
assert extension.get_app_snippet(app_name="test-app") == {
"command-chain": ["snap/command-chain/ros2-launch"],
"environment": {
"ROS_VERSION": "2",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/parts/extensions/test_ros2_jazzy_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_get_app_snippet(self, extension_name, extension_class, meta, meta_dev):
"$SNAP/opt/ros/underlay_ws/usr/lib/python3/dist-packages",
]
extension = setup_method_fixture(extension_class)
assert extension.get_app_snippet() == {
assert extension.get_app_snippet(app_name="test-app") == {
"command-chain": ["snap/command-chain/ros2-launch"],
"environment": {
"ROS_VERSION": "2",
Expand Down

0 comments on commit d65754b

Please sign in to comment.