Skip to content

Commit

Permalink
remove pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
tigarmo committed Aug 29, 2023
1 parent baa19b5 commit 7808971
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 606 deletions.
551 changes: 0 additions & 551 deletions .pylintrc

This file was deleted.

4 changes: 2 additions & 2 deletions craft_cli/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _get_commands_info(commands_groups: list[CommandGroup]) -> dict[str, type[Ba
return commands


class Dispatcher: # pylint: disable=too-many-instance-attributes
class Dispatcher:
"""Set up infrastructure and let the needed command run.
♪♫"Leeeeeet, the command ruuun"♪♫ https://www.youtube.com/watch?v=cv-0mmVnxPA
Expand Down Expand Up @@ -323,7 +323,7 @@ def _get_requested_help( # noqa: PLR0912 (too many branches)

# produce the complete help message for the command
command_options = self._get_global_options()
for action in parser._actions: # pylint: disable=protected-access
for action in parser._actions:
# store the different options if present, otherwise it's just the dest
help_text = "" if action.help is None else action.help
if action.option_strings:
Expand Down
4 changes: 1 addition & 3 deletions craft_cli/helptexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,7 @@ def get_command_help(
else:
raise RuntimeError("Internal inconsistency in commands groups")
other_command_names = [
c.name
for c in command_group.commands # pylint: disable=undefined-loop-variable
if not isinstance(command, c)
c.name for c in command_group.commands if not isinstance(command, c)
]

if output_format == OutputFormat.markdown:
Expand Down
14 changes: 5 additions & 9 deletions craft_cli/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _get_traceback_lines(exc: BaseException) -> Generator[str, None, None]:
yield real_line


class _Progresser: # pylint: disable=too-many-instance-attributes
class _Progresser:
"""A context manager to follow progress on any specific action."""

def __init__( # noqa: PLR0913 (too many arguments)
Expand Down Expand Up @@ -200,7 +200,7 @@ def __init__(
# on the platform
if _WINDOWS_MODE:
# parameters: default security, default buffer size, binary mode
binary_mode = os.O_BINARY # pylint: disable=no-member # (it does exist in Windows!)
binary_mode = os.O_BINARY
# ignoring the type of the first parameter below, as documentation allows to use None
# to make it use a NULL security descriptor:
# https://www.markjour.com/docs/pywin32-docs/PySECURITY_ATTRIBUTES.html
Expand Down Expand Up @@ -404,12 +404,10 @@ def _active_guard(ignore_when_stopped: bool = False) -> Callable[..., Any]: # n
"""

def decorator(wrapped_func: FuncT) -> FuncT:
def func( # pylint: disable=inconsistent-return-statements
self: Emitter, *args: Any, **kwargs: Any
) -> Any:
if not self._initiated: # pylint: disable=protected-access
def func(self: Emitter, *args: Any, **kwargs: Any) -> Any:
if not self._initiated:
raise RuntimeError("Emitter needs to be initiated first")
if self._stopped: # pylint: disable=protected-access
if self._stopped:
if ignore_when_stopped:
return None
raise RuntimeError("Emitter is stopped already")
Expand Down Expand Up @@ -443,8 +441,6 @@ class Emitter:
the application behaviour and/or logs forensics.
"""

# pylint: disable=too-many-instance-attributes

def __init__(self) -> None:
# these attributes will be set at "real init time", with the `init` method below
self._greeting: str = None # type: ignore[assignment]
Expand Down
4 changes: 2 additions & 2 deletions craft_cli/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@


@dataclass
class _MessageInfo: # pylint: disable=too-many-instance-attributes
class _MessageInfo:
"""Comprehensive information for a message that may go to screen and log."""

stream: TextIO | None
Expand Down Expand Up @@ -138,7 +138,7 @@ def supervise(self, message: _MessageInfo | None) -> None:
"""Supervise a message to spin it if it remains too long."""
self.queue.put(message)
# (maybe) wait for the spinner to exit spinning state (which does some cleaning)
self.lock.acquire() # pylint: disable=consider-using-with
self.lock.acquire()
self.lock.release()

def stop(self) -> None:
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ dev = [
lint = [
"black==23.7.0",
"codespell[toml]==2.2.5",
"pylint==2.17.5",
"pylint-fixme-info==1.0.3",
"pylint-pytest==1.1.2",
"ruff==0.0.269",
"yamllint==1.32.0"
]
Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_messages_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def assert_outputs(capsys, emit, expected_out=None, expected_err=None, expected_
@pytest.mark.parametrize("output_is_terminal", [None])
def test_exposed_api():
"""Verify names are properly exposed."""
# pylint: disable=import-outside-toplevel
from craft_cli import emit

assert isinstance(emit, messages.Emitter)
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ class MyCommandControl(BaseCommand):

help_msg = "some help"
overview = "fake overview"
_executed = []

def run(self, parsed_args):
self._executed.append(parsed_args) # type: ignore # pylint: disable=no-member
self._executed.append(parsed_args)

class MyCommand1(MyCommandControl):
"""Specifically defined command."""
Expand Down Expand Up @@ -470,7 +471,7 @@ class MyCommand2(BaseCommand):
help_msg = "some help"
overview = "fake overview"

def __init__(self, *args): # pylint: disable=super-init-not-called
def __init__(self, *args):
raise AssertionError

def fill_parser(self, parser):
Expand Down Expand Up @@ -552,7 +553,7 @@ def run(self, parsed_args):
def test_basecommand_run_mandatory():
"""BaseCommand subclasses must override run."""

class TestCommand(BaseCommand): # pylint: disable=abstract-method # yes, 'run' is not there
class TestCommand(BaseCommand):
"""Specifically defined command."""

help_msg = "help message"
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def test_tool_exec_command_dash_help_reverse(help_option):
def test_tool_exec_command_dash_help_missing_params(help_option):
"""Execute a command (which needs params) asking for help."""

def fill_parser(self, parser): # pylint: disable=unused-argument
def fill_parser(self, parser):
parser.add_argument("mandatory")

cmd = create_command("somecommand", "This command does that.")
Expand Down Expand Up @@ -931,7 +931,7 @@ def test_tool_exec_command_wrong_option():
def test_tool_exec_command_bad_option_type():
"""Execute a correct command but giving the valid option a bad value."""

def fill_parser(self, parser): # pylint: disable=unused-argument
def fill_parser(self, parser):
parser.add_argument("--number", type=int)

cmd = create_command("somecommand", "This command does that.")
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def test_tool_exec_help_command_on_command_format_markdown():
def test_tool_exec_help_command_on_command_complex():
"""Execute the app asking for help on a command with parameters and options."""

def fill_parser(self, parser): # pylint: disable=unused-argument
def fill_parser(self, parser):
parser.add_argument("param1", help="help on param1")
parser.add_argument("param2", help="help on param2")
parser.add_argument("param3", metavar="transformed3", help="help on param2")
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def fill_parser(self, parser): # pylint: disable=unused-argument
def test_tool_exec_help_command_on_command_no_help():
"""Execute the app asking for help on a command with an options and params without help."""

def fill_parser(self, parser): # pylint: disable=unused-argument
def fill_parser(self, parser):
parser.add_argument("param")
parser.add_argument("--option")

Expand Down
12 changes: 7 additions & 5 deletions tests/unit/test_messages_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ def test_reporterror_detailed_info_developer_modes(mode, get_initiated_emitter):
def test_reporterror_chained_exception_final_user_modes(mode, get_initiated_emitter):
"""Report an error that was originated after other exception, in final user modes."""
emitter = get_initiated_emitter(mode)
orig_exception = None
try:
try:
raise ValueError("original")
Expand All @@ -865,7 +866,7 @@ def test_reporterror_chained_exception_final_user_modes(mode, get_initiated_emit

with patch("craft_cli.messages._get_traceback_lines") as tblines_mock:
tblines_mock.return_value = ["traceback line 1", "traceback line 2"]
emitter.error(error) # pylint: disable=used-before-assignment
emitter.error(error)

full_log_message = f"Full execution log: {repr(emitter._log_filepath)}"
assert emitter.printer_calls == [
Expand All @@ -877,13 +878,14 @@ def test_reporterror_chained_exception_final_user_modes(mode, get_initiated_emit
]

# check the traceback lines are generated using the original exception
tblines_mock.assert_called_with(orig_exception) # type: ignore # pylint: disable=used-before-assignment
tblines_mock.assert_called_with(orig_exception)


@pytest.mark.parametrize("mode", [EmitterMode.DEBUG, EmitterMode.TRACE])
def test_reporterror_chained_exception_developer_modes(mode, get_initiated_emitter):
"""Report an error that was originated after other exception, in developer intended modes."""
emitter = get_initiated_emitter(mode)
orig_exception = None
try:
try:
raise ValueError("original")
Expand All @@ -895,7 +897,7 @@ def test_reporterror_chained_exception_developer_modes(mode, get_initiated_emitt

with patch("craft_cli.messages._get_traceback_lines") as tblines_mock:
tblines_mock.return_value = ["traceback line 1", "traceback line 2"]
emitter.error(error) # pylint: disable=used-before-assignment
emitter.error(error)

full_log_message = f"Full execution log: {repr(emitter._log_filepath)}"
assert emitter.printer_calls == [
Expand All @@ -907,7 +909,7 @@ def test_reporterror_chained_exception_developer_modes(mode, get_initiated_emitt
]

# check the traceback lines are generated using the original exception
tblines_mock.assert_called_with(orig_exception) # type: ignore # pylint: disable=used-before-assignment
tblines_mock.assert_called_with(orig_exception)


@pytest.mark.parametrize("mode", [EmitterMode.QUIET, EmitterMode.BRIEF, EmitterMode.VERBOSE])
Expand Down Expand Up @@ -994,7 +996,7 @@ def test_reporterror_full_complete(get_initiated_emitter):

with patch("craft_cli.messages._get_traceback_lines") as tblines_mock:
tblines_mock.return_value = ["traceback line 1", "traceback line 2"]
emitter.error(error) # pylint: disable=used-before-assignment
emitter.error(error)

full_log_message = f"Full execution log: {repr(emitter._log_filepath)}"
full_docs_message = "For more information, check out: https://charmhub.io/docs/whatever"
Expand Down
5 changes: 1 addition & 4 deletions tests/unit/test_messages_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,7 @@ def test_traceback_lines_simple():
except ValueError as err:
tbacklines = list(_get_traceback_lines(err))

# disable 'black' here otherwise it complains about pylint comment (which we need for
# pylint to shut up about the false positive)
# fmt: off
assert tbacklines[0] == "Traceback (most recent call last):" # pylint: disable=used-before-assignment
assert tbacklines[0] == "Traceback (most recent call last):"
assert tbacklines[1].startswith(" File ")
assert tbacklines[1].endswith(", in test_traceback_lines_simple")
assert tbacklines[2] == ' raise ValueError("pumba")'
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_messages_stream_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_streamcm_init_with_stream(recording_printer, stream):
)

# initial message
(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.stream == stream
assert msg.text == "initial text"
assert msg.use_timestamp is False
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_streamcm_init_with_stream_and_timestamp(recording_printer, stream):
)

# initial message
(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.stream == stream
assert msg.text == "initial text"
assert msg.use_timestamp is True
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_streamcm_init_with_stream_ephemeral(recording_printer, stream):
)

# initial message
(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.stream == stream
assert msg.text == "initial text"
assert msg.use_timestamp is False
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_pipereader_simple(recording_printer, stream):
os.write(prt.write_pipe, b"123\n")
prt.stop()

(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.stream == stream
assert msg.text == ":: 123" # unicode, with the prefix, and without the newline
assert msg.use_timestamp is False
Expand All @@ -215,7 +215,7 @@ def test_pipereader_with_timestamp(recording_printer, stream):
os.write(prt.write_pipe, b"123\n")
prt.stop()

(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.stream == stream
assert msg.text == ":: 123" # unicode, with the prefix, and without the newline
assert msg.use_timestamp is True
Expand All @@ -234,7 +234,7 @@ def test_pipereader_ephemeral(recording_printer, stream):
os.write(prt.write_pipe, b"123\n")
prt.stop()

(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.stream == stream
assert msg.text == ":: 123" # unicode, with the prefix, and without the newline
assert msg.use_timestamp is False
Expand All @@ -253,7 +253,7 @@ def test_pipereader_tabs(recording_printer, stream):
os.write(prt.write_pipe, b"\t123\t456\n")
prt.stop()

(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.text == ":: 123 456" # tabs expanded into 2 spaces


Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def test_show_defaults_no_stream(recording_printer):
recording_printer.show(None, "test text")

# check message logged
(msg,) = recording_printer.logged # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.logged
assert msg.stream is None
assert msg.text == "test text"
assert msg.use_timestamp is False
Expand Down Expand Up @@ -706,7 +706,7 @@ def test_show_defaults_terminal(stream, monkeypatch, recording_printer):
assert not recording_printer.written_terminal_bars
assert not recording_printer.written_captured_bars
assert not recording_printer.written_captured_lines
(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.stream == stream
assert msg.text == "test text"
assert msg.use_timestamp is False
Expand Down Expand Up @@ -738,7 +738,7 @@ def test_show_defaults_captured(stream, monkeypatch, recording_printer):
assert not recording_printer.written_terminal_bars
assert not recording_printer.written_captured_bars
assert not recording_printer.written_terminal_lines
(msg,) = recording_printer.written_captured_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_captured_lines
assert msg.stream == stream
assert msg.text == "test text"
assert msg.use_timestamp is False
Expand All @@ -763,15 +763,15 @@ def test_show_use_timestamp(recording_printer, monkeypatch):
"""Control on message's use_timestamp flag."""
monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
recording_printer.show(sys.stdout, "test text", use_timestamp=True)
(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.use_timestamp is True


def test_show_end_line(recording_printer, monkeypatch):
"""Control on message's end_line flag."""
monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
recording_printer.show(sys.stdout, "test text", end_line=True)
(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.end_line is True


Expand All @@ -785,7 +785,7 @@ def test_show_ephemeral(recording_printer, monkeypatch):
"""Control if some message is ephemeral."""
monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
recording_printer.show(sys.stdout, "test text", ephemeral=True)
(msg,) = recording_printer.written_terminal_lines # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_lines
assert msg.ephemeral is True


Expand All @@ -807,7 +807,7 @@ def test_progress_bar_valid_streams_terminal(stream, recording_printer, monkeypa
assert not recording_printer.written_captured_lines
assert not recording_printer.written_captured_bars
assert not recording_printer.logged
(msg,) = recording_printer.written_terminal_bars # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_terminal_bars
assert msg.stream == stream
assert msg.text == "test text"
assert msg.bar_progress == 20
Expand Down Expand Up @@ -842,7 +842,7 @@ def test_progress_bar_valid_streams_captured(stream, recording_printer, monkeypa
assert not recording_printer.written_captured_lines
assert not recording_printer.written_terminal_bars
assert not recording_printer.logged
(msg,) = recording_printer.written_captured_bars # pylint: disable=unbalanced-tuple-unpacking
(msg,) = recording_printer.written_captured_bars
assert msg.stream == stream
assert msg.text == "test text"
assert msg.bar_progress == 20
Expand Down
Loading

0 comments on commit 7808971

Please sign in to comment.