Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@atombrella
Copy link
Contributor

@atombrella atombrella commented Dec 18, 2024

These were mostly unused unittest and sys from test-files and setup.py files.

I could move the # pylint: disable=arguments-differ from the Apache tests removal to a different PR. The trick to just add **kwargs seems fine, and don't use it.

I have a local branch to experiment replacing pylint with Ruff, but there are loads of things that need to be prepared. I have found https://pypi.org/project/flake8-tidy-imports/ that potentially could be used as a replacement for the custom pylint plugin to guard against import os.
My initial idea is to target E, W, F. Ruff gives instant feedback, and it's pretty powerful. It's also how I found the io.open and OSError things.

I have not done anything about this:

certbot/certbot/_internal/cli/__init__.py:31:45: F401 `certbot._internal.cli.cli_utils.CustomHelpFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias

You can install ruff in your local virtual environment, and run:

ruff check --select "F401"

@bmw has expressed interest in replacing pylint with flake8 to save ~1min in each pipeline.
Besides, there are issues that pylint does not seem to find, e.g., duplicate entries in a dictionary.

Pull Request Checklist

  • The Certbot team has recently expressed interest in reviewing a PR for this. If not, this PR may be closed due our limited resources and need to prioritize how we spend them.

@atombrella atombrella marked this pull request as draft December 18, 2024 15:50
@atombrella atombrella force-pushed the import_unused_f401 branch 2 times, most recently from 00bb6c8 to 53928d8 Compare December 23, 2024 17:26
These were mostly unused unittest and sys from test and setup.py files.
@atombrella
Copy link
Contributor Author

I wonder why the mocking is not for sys.stdout but has to forwarded to certbot._internal.main. For the same reason, I silenced import sys in certbot.certbot.cli. Anyway, I removed a large chunk of these unused imports, and will mark it as ready for review.

        with mock.patch('certbot._internal.main.sys.stdout', new=output):
            with test_util.patch_display_util() as mock_get_utility:
                mock_get_utility().notification.side_effect = write_msg
                with mock.patch('certbot._internal.main.sys.stderr'):
                    with pytest.raises(SystemExit):
                        self._unmocked_parse(args)

The local branch I have with Ruff is in atombrella@84d304a This is a POC to replace the custom pylint plugin with flake8-tidy-imports which seems to work.

@atombrella atombrella marked this pull request as ready for review December 23, 2024 18:02

def test_renew_hook_conflict(self):
with mock.patch("certbot._internal.cli.sys.stderr"):
with mock.patch("sys.stderr"):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not really sure why certbot._internal.cli.sys.stderr is required, and not just sys.stderr

Copy link
Collaborator

Choose a reason for hiding this comment

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

tbh i'm not sure why either, although IMO we should either change all occurrences of it or none -- imo none, since it feels unrelated to the rest of the PR

# NB: Each function defined in compat._path is marked with "type: ignore" to avoid mypy
# to complain that a function is redefined (because we imported if first from os.path).

# pylint: disable=function-redefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

rm this line as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pylint complains if I do so.


try:
import fcntl # pylint: disable=import-error,unused-import
import fcntl # pylint: disable=import-error,unused-import # noqa
Copy link
Collaborator

Choose a reason for hiding this comment

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

having another # in an end-of-line comment feels odd, is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ruff is fine with # noqa pylint ... But maybe since ruff/flake8 is not implemented, I can just remove it.


def test_renew_hook_conflict(self):
with mock.patch("certbot._internal.cli.sys.stderr"):
with mock.patch("sys.stderr"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

tbh i'm not sure why either, although IMO we should either change all occurrences of it or none -- imo none, since it feels unrelated to the rest of the PR

@atombrella
Copy link
Contributor Author

@wgreenberg I've updated it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants