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

pylint equivalent to pylint . #9072

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/5701.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``pylint`` is now equivalent to ``pylint .`` and won't show the help by default anymore.
The help is still available with ``pylint --help`` or ``pylint --long-help``.
Comment on lines +1 to +2
Copy link
Member

@jacobtylerwalls jacobtylerwalls Sep 26, 2023

Choose a reason for hiding this comment

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

Let's not promise equivalence with pylint .. I'm showing a behavior difference. Before, cd to a directory you haven't installed with pip, invoke pylint ., you get a quick lint of the __init__.py only; now you get the whole package linted.


Closes #5701
3 changes: 0 additions & 3 deletions pylint/config/arguments_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,9 @@ def _parse_command_line_configuration(
self, arguments: Sequence[str] | None = None
) -> list[str]:
"""Parse the arguments found on the command line into the namespace."""
arguments = sys.argv[1:] if arguments is None else arguments
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved

self.config, parsed_args = self._arg_parser.parse_known_args(
arguments, self.config
)

return parsed_args

def _generate_config(
Expand Down
16 changes: 12 additions & 4 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,14 @@ def check(self, files_or_modules: Sequence[str]) -> None:
files_or_modules is either a string or list of strings presenting modules to check.
"""
self.initialize()
if not files_or_modules and not self.config.from_stdin:
files_or_modules = (str(Path(".").resolve()),)
if self.config.recursive:
files_or_modules = tuple(self._discover_files(files_or_modules))
if self.config.from_stdin:
if len(files_or_modules) != 1:
raise exceptions.InvalidArgsError(
"Missing filename required for --from-stdin"
)
print("Missing filename required for --from-stdin")
sys.exit(32)
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved

extra_packages_paths = list(
{
Expand Down Expand Up @@ -989,7 +990,14 @@ def get_ast(
confidence=HIGH,
)
except astroid.AstroidBuildingError as ex:
self.add_message("parse-error", args=ex)
msg = str(ex)
if "Unable to load file" in msg and "__init__.py" in msg:
msg = (
"No '__init__.py' in the given directory, give a python module, "
"or use '--recursive=y' with the proper ignore option (in order"
" to not lint your virtualenv)"
)
self.add_message("parse-error", args=msg)
except Exception as ex:
traceback.print_exc()
# We raise BuildingError here as this is essentially an astroid issue
Expand Down
6 changes: 2 additions & 4 deletions pylint/lint/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ def __init__(
return

# Display help if there are no files to lint or no checks enabled
Copy link
Member

Choose a reason for hiding this comment

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

May as well clean up this comment, as we're not displaying help (right?)

if not args or len(linter.config.disable) == len(
linter.msgs_store._messages_definitions
):
print("No files to lint: exiting.")
if len(linter.config.disable) == len(linter.msgs_store._messages_definitions):
print("No messages to check: exiting.")
sys.exit(32)

if linter.config.jobs < 0:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ def test_nonexistent_config_file(self) -> None:
self._runtest(["--rcfile=/tmp/this_file_does_not_exist"], code=32)

def test_error_missing_arguments(self) -> None:
self._runtest([], code=32)
self._runtest([], code=1)

def test_disable_all(self) -> None:
out = StringIO()
self._runtest([UNNECESSARY_LAMBDA, "--disable=all"], out=out, code=32)
assert "No files to lint: exiting." in out.getvalue().strip()
assert "No messages to check: exiting." in out.getvalue().strip()

def test_no_out_encoding(self) -> None:
"""Test redirection of stdout with non ascii characters."""
Expand Down Expand Up @@ -491,8 +491,9 @@ def test_pylintrc_comments_in_values(self) -> None:
)

def test_no_crash_with_formatting_regex_defaults(self) -> None:
path = join(HERE, "regrtest_data", "empty.py")
self._runtest(
["--ignore-patterns=a"], reporter=TextReporter(StringIO()), code=32
Copy link
Member

Choose a reason for hiding this comment

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

What was making the prior code emit 32?

[path, "--ignore-patterns=a"], reporter=TextReporter(StringIO()), code=0
)

def test_getdefaultencoding_crashes_with_lc_ctype_utf8(self) -> None:
Expand Down