Skip to content

Commit

Permalink
fix(legacy): export sources method to local plugins
Browse files Browse the repository at this point in the history
Support legacy local plugins that invoke `snapcraft.sources.get`
by redirecting imports to `snapcraft_legacy`. This is similar
to the strategy used for V1 and V2 plugins.

Fixes #4285

Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
  • Loading branch information
cmatsuoka committed Aug 29, 2023
1 parent 24e430d commit a66bf43
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions snapcraft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import pkg_resources

# For legacy compatibility
import snapcraft.sources # noqa: F401


def _get_version():
if os.environ.get("SNAP_NAME") == "snapcraft":
Expand Down
23 changes: 23 additions & 0 deletions snapcraft/sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2023 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Legacy support for local plugins."""

from snapcraft_legacy.sources import get

__all__ = [
"get",
]
1 change: 1 addition & 0 deletions tests/spread/plugins/v1/x-local/local-plugin/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ environment:
SNAP_DIR/baseplugin: ../snaps/from-baseplugin
SNAP_DIR/nilplugin: ../snaps/from-nilplugin
SNAP_DIR/pluginv1: ../snaps/from-pluginv1
SNAP_DIR/sourceget: ../snaps/source-get

prepare: |
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2023 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import snapcraft
from snapcraft.plugins.v1 import PluginV1


class LocalPlugin(PluginV1):
@classmethod
def schema(cls):
schema = super().schema()

schema["properties"]["foo"] = {"type": "string"}

return schema

@classmethod
def get_pull_properties(cls):
return ["foo", "stage-packages"]

@classmethod
def get_build_properties(cls):
return ["foo", "stage-packages"]

def pull(self):
super().pull()
x = snapcraft.sources.get

def build(self):
return self.run(["touch", "build-stamp"], self.installdir)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: test-local-plugins
base: core18
version: "0.1"
summary: local plugin using snapcraft.sources.get
description: Tests if local plugins load and can build
confinement: strict
grade: devel

parts:
x-local-plugin:
plugin: x-local-plugin
source: .

0 comments on commit a66bf43

Please sign in to comment.