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

many: detect local source changes #2167

Merged
2 changes: 1 addition & 1 deletion snapcraft/internal/pluginhandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def check_pull(self):
self.plugin.statedir, steps.PULL)

# Not all sources support checking for updates
with contextlib.suppress(NotImplementedError):
with contextlib.suppress(sources.errors.SourceUpdateUnsupportedError):
if self.source_handler.check(state_file):
return OutdatedReport(source_updated=True)
return None
Expand Down
5 changes: 3 additions & 2 deletions snapcraft/internal/sources/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
download_urllib_source
)
from ._checksum import split_checksum, verify_checksum
from .errors import SourceUpdateUnsupportedError


class Base:
Expand Down Expand Up @@ -66,11 +67,11 @@ def _check(self, target: str):

:param str target: Path to target file.
"""
raise NotImplementedError
raise SourceUpdateUnsupportedError(self)

def _update(self):
"""Update pulled source."""
raise NotImplementedError
raise SourceUpdateUnsupportedError(self)


class FileBase(Base):
Expand Down
27 changes: 21 additions & 6 deletions snapcraft/internal/sources/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
from typing import List


class VCSError(errors.SnapcraftError):
class SnapcraftSourceError(errors.SnapcraftError):
pass


class VCSError(SnapcraftSourceError):
fmt = '{message}'


class SnapcraftSourceUnhandledError(errors.SnapcraftError):
class SnapcraftSourceUnhandledError(SnapcraftSourceError):

fmt = ('Failed to pull source: '
'unable to determine source type of {source!r}.\n'
Expand All @@ -36,7 +40,7 @@ def __init__(self, source):
super().__init__(source=source)


class SnapcraftSourceInvalidOptionError(errors.SnapcraftError):
class SnapcraftSourceInvalidOptionError(SnapcraftSourceError):

fmt = (
"Failed to pull source: "
Expand All @@ -48,7 +52,7 @@ def __init__(self, source_type: str, option: str) -> None:
super().__init__(source_type=source_type, option=option)


class SnapcraftSourceIncompatibleOptionsError(errors.SnapcraftError):
class SnapcraftSourceIncompatibleOptionsError(SnapcraftSourceError):

fmt = (
"Failed to pull source: "
Expand All @@ -63,7 +67,7 @@ def __init__(self, source_type: str, options: List[str]) -> None:
humanized_options=formatting_utils.humanize_list(options, 'and'))


class DigestDoesNotMatchError(errors.SnapcraftError):
class DigestDoesNotMatchError(SnapcraftSourceError):

fmt = ('Expected the digest for source to be {expected}, '
'but it was {calculated}')
Expand All @@ -72,8 +76,19 @@ def __init__(self, expected, calculated):
super().__init__(expected=expected, calculated=calculated)


class InvalidDebError(errors.SnapcraftError):
class InvalidDebError(SnapcraftSourceError):

fmt = ('The {deb_file} used does not contain valid data. '
'Ensure a proper deb file is passed for .deb files '
'as sources.')


class SourceUpdateUnsupportedError(SnapcraftSourceError):

fmt = (
'Failed to update source: '
"{source!s} sources don't support updating"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a . to end the sentence please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

)

def __init__(self, source):
super().__init__(source=source)