Skip to content

Commit

Permalink
feat(lint): migrate lint command
Browse files Browse the repository at this point in the history
  • Loading branch information
syu-w committed Apr 12, 2024
1 parent 9a5dbfa commit 1627106
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 63 deletions.
6 changes: 5 additions & 1 deletion snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ def _get_dispatcher(self) -> craft_cli.Dispatcher:
# project's base (if any). Here, we handle the case where there *is*
# a project and it's core24, which means it should definitely fall into
# the craft-application-based flow.
if "lint" in sys.argv:
# We don't need to check for core24 if we're just linting
return super()._get_dispatcher()

if self._snapcraft_yaml_path:
with self._snapcraft_yaml_path.open() as file:
yaml_data = util.safe_yaml_load(file)
Expand Down Expand Up @@ -280,7 +284,7 @@ def create_app() -> Snapcraft:
"Other",
list(craft_app_commands.get_other_command_group().commands)
+ [
unimplemented.Lint,
commands.LintCommand,
unimplemented.Init,
],
)
Expand Down
1 change: 0 additions & 1 deletion snapcraft/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
craft_cli.CommandGroup(
"Other",
[
commands.core22.LintCommand,
commands.core22.InitCommand,
],
),
Expand Down
2 changes: 2 additions & 0 deletions snapcraft/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
StoreLegacyValidateCommand,
)
from .lifecycle import SnapCommand
from .lint import LintCommand
from .manage import StoreCloseCommand, StoreReleaseCommand
from .names import (
StoreLegacyListCommand,
Expand All @@ -58,6 +59,7 @@

__all__ = [
"ExpandExtensions",
"LintCommand",
"ListExtensions",
"RemoteBuildCommand",
"SnapCommand",
Expand Down
2 changes: 0 additions & 2 deletions snapcraft/commands/core22/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
StageCommand,
TryCommand,
)
from .lint import LintCommand
from .remote import RemoteBuildCommand

__all__ = [
Expand All @@ -42,7 +41,6 @@
"ExpandExtensionsCommand",
"ExtensionsCommand",
"InitCommand",
"LintCommand",
"ListExtensionsCommand",
"ListPluginsCommand",
"PackCommand",
Expand Down
15 changes: 8 additions & 7 deletions snapcraft/commands/core22/lint.py → snapcraft/commands/lint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2023 Canonical Ltd.
# Copyright 2023-2024 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
Expand All @@ -24,9 +24,10 @@
import textwrap
from contextlib import contextmanager
from pathlib import Path, PurePosixPath
from typing import Iterator, Optional
from typing import Any, Iterator, Optional

from craft_cli import BaseCommand, emit
from craft_application.commands import ExtensibleCommand
from craft_cli import emit
from craft_cli.errors import ArgumentParsingError
from craft_providers.multipass import MultipassProvider
from craft_providers.util import snap_cmd
Expand All @@ -42,9 +43,10 @@
)


class LintCommand(BaseCommand):
class LintCommand(ExtensibleCommand):
"""Lint-related commands."""

always_load_project = False
name = "lint"
help_msg = "Lint a snap file"
overview = textwrap.dedent(
Expand All @@ -58,7 +60,7 @@ class LintCommand(BaseCommand):
)

@overrides
def fill_parser(self, parser: "argparse.ArgumentParser") -> None:
def _fill_parser(self, parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"snap_file",
metavar="snap-file",
Expand All @@ -78,8 +80,7 @@ def fill_parser(self, parser: "argparse.ArgumentParser") -> None:
help="Set https proxy",
)

@overrides
def run(self, parsed_args: argparse.Namespace):
def _run(self, parsed_args: argparse.Namespace, **kwargs: Any) -> None:
"""Run the linter command.
:param parsed_args: snapcraft's argument namespace
Expand Down
6 changes: 0 additions & 6 deletions snapcraft/commands/unimplemented.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,3 @@ class Try(
UnimplementedMixin, commands.core22.TryCommand
): # noqa: D101 (missing docstring)
pass


class Lint(
UnimplementedMixin, commands.core22.LintCommand
): # noqa: D101 (missing docstring)
pass
2 changes: 0 additions & 2 deletions tests/spread/core24/linters-file/task.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
summary: Run snapcraft lint on a snap file.
# Disabled from regular CI runs until we have "snapcraft lint" in core24
manual: true

environment:
SNAP: lint-file
Expand Down
Loading

0 comments on commit 1627106

Please sign in to comment.