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

fix(remote-build): warn instead of error when using unsupported bases #4396

Merged
merged 2 commits into from
Oct 6, 2023
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
6 changes: 2 additions & 4 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ jobs:
strategy:
fail-fast: false # Run all the tests to their conclusions.
matrix:
platform: [ubuntu-20.04, ubuntu-22.04]
python_version: ["3.8", "3.10"]
platform: [ubuntu-22.04]
python_version: ["3.10"]
include:
- python_version: "3.8"
tox_python: py38
- python_version: "3.10"
tox_python: py310
runs-on: ${{ matrix.platform }}
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
TIMESTAMP_SERVICE: http://timestamp.digicert.com

matrix:
- PYTHON: C:\Python38-x64
- PYTHON: C:\Python310-x64

cache:
- '%LOCALAPPDATA%\pip\Cache\http'
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ load-plugins = "pylint_fixme_info,pylint_pytest"
min-similarity-lines=10

[tool.mypy]
python_version = 3.8
python_version = 3.10
ignore_missing_imports = true
follow_imports = "silent"
exclude = [
Expand All @@ -74,7 +74,7 @@ exclude = [
"tests/legacy",
"tests/spread",
]
pythonVersion = "3.8"
pythonVersion = "3.10"

[tool.pytest.ini_options]
minversion = 7.0
Expand Down
26 changes: 25 additions & 1 deletion snapcraft/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ def run(self, parsed_args: argparse.Namespace) -> None:
self._snapcraft_yaml = yaml_utils.get_snap_project().project_file
self._parsed_args = parsed_args
# pylint: enable=attribute-defined-outside-init
base = self._get_effective_base()
try:
base = self._get_effective_base()
except MaintenanceBase as base_err:
base = base_err.base
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting way to recover the base value.

emit.progress(_get_esm_warning_for_base(base), permanent=True)

self._run_new_or_fallback_remote_build(base)

def _run_new_or_fallback_remote_build(self, base: str) -> None:
Expand Down Expand Up @@ -279,3 +284,22 @@ def _get_effective_base(self) -> str:
)

return base


def _get_esm_warning_for_base(base: str) -> str:
"""Return a warning appropriate for the base under ESM."""
channel: Optional[str] = None
match base:
case "core":
channel = "4.x"
version = "4"
case "core18":
channel = "7.x"
version = "7"
case _:
raise RuntimeError(f"Unmatched base {base!r}")

return (
f"WARNING: base {base!r} was last supported on Snapcraft {version} available "
f"on the {channel!r} channel."
)
1 change: 1 addition & 0 deletions snapcraft/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def __init__(self, base: str) -> None:
resolution=resolution,
docs_url="https://snapcraft.io/docs/base-snaps",
)
self.base = base


class StoreCredentialsUnauthorizedError(SnapcraftError):
Expand Down
36 changes: 29 additions & 7 deletions tests/unit/commands/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_get_effective_base_with_build_base(


@pytest.mark.usefixtures("mock_argv", "mock_confirm")
@pytest.mark.parametrize("base", CURRENT_BASES | LEGACY_BASES)
@pytest.mark.parametrize("base", CURRENT_BASES | LEGACY_BASES | ESM_BASES)
def test_get_effective_base_type(
base, snapcraft_yaml, mock_run_new_or_fallback_remote_build
):
Expand Down Expand Up @@ -255,15 +255,37 @@ def test_get_effective_base_none(capsys, snapcraft_yaml):


@pytest.mark.usefixtures("mock_argv", "mock_confirm")
@pytest.mark.parametrize("base", ESM_BASES)
def test_get_effective_base_esm(base, capsys, snapcraft_yaml):
"""Raise an error if an ESM base is used."""
snapcraft_yaml(base=base)
def test_get_effective_base_core_esm_warning(
emitter, snapcraft_yaml, mock_run_new_or_fallback_remote_build
):
"""Warn if core, an ESM base, is used."""
snapcraft_yaml(base="core")

cli.run()

_, err = capsys.readouterr()
assert f"{base!r} is not supported on this version of Snapcraft." in err
mock_run_new_or_fallback_remote_build.assert_called_once_with("core")
emitter.assert_progress(
"WARNING: base 'core' was last supported on Snapcraft 4 available on the "
"'4.x' channel.",
permanent=True,
)


@pytest.mark.usefixtures("mock_argv", "mock_confirm")
def test_get_effective_base_core18_esm_warning(
emitter, snapcraft_yaml, mock_run_new_or_fallback_remote_build
):
"""Warn if core18, an ESM base, is used."""
snapcraft_yaml(base="core18")

cli.run()

mock_run_new_or_fallback_remote_build.assert_called_once_with("core18")
emitter.assert_progress(
"WARNING: base 'core18' was last supported on Snapcraft 7 available on the "
"'7.x' channel.",
permanent=True,
)


#######################
Expand Down
12 changes: 6 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
[tox]
env_list = # Environments to run when called with no parameters.
lint-{black,ruff,isort,mypy,pylint,pyright,shellcheck,codespell,yaml}
test-py38
test-legacy-py38
test-py310
test-legacy-py310
minversion = 4.5
# Tox will use these requirements to bootstrap a venv if necessary.
# tox-igore-env-name-mismatch allows us to have one virtualenv for all linting.
Expand Down Expand Up @@ -48,18 +48,18 @@ package = wheel
allowlist_externals = mkdir
commands_pre = mkdir -p results

[testenv:test-{py38,py39,py310,py311,py312}] # Configuration for all tests using pytest
[testenv:test-{py39,py310,py311,py312}] # Configuration for all tests using pytest
base = testenv, test
description = Run unit tests with pytest
labels =
py38, py310, py311: tests, unit-tests
py310, py311: tests, unit-tests
commands = pytest {tty:--color=yes} --cov=snapcraft --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml {posargs:tests/unit}

[testenv:test-legacy-{py38,py39,py310,py311,py312}]
[testenv:test-legacy-{py39,py310,py311,py312}]
base = testenv, test
description = Run legacy tests with pytest
labels =
py38, py310, py311: tests, integration-tests
py310, py311: tests, integration-tests
commands = pytest {tty:--color=yes} --cov=snapcraft_legacy --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml {posargs:tests/legacy}

[testenv:test-noreq]
Expand Down
Loading