-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Lint all files in a directory by expanding arguments #5682
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
Changes from 1 commit
e44977d
9b23124
20ad408
2aceafb
404bb9b
44f1919
b42df9c
3ebb1d7
6520a4e
8741104
91fe106
6623eb1
bc45736
8ae1438
756acc5
e83f9fc
ca13575
c9e571e
68529b5
b5e5bb6
6199d4e
59480dc
f47c9b8
03a0890
1de1999
a86cf14
3d96598
20dcce4
1aa4fdc
154f7d9
0864585
8bf62cb
5735618
ca79dae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -515,6 +515,13 @@ def make_options() -> Tuple[Tuple[str, OptionDict], ...]: | |
), | ||
}, | ||
), | ||
( | ||
"recursive", | ||
{ | ||
"action": "store_true", | ||
"help": ("Discover python files in file system subtree."), | ||
}, | ||
), | ||
( | ||
"py-version", | ||
{ | ||
|
@@ -1005,6 +1012,22 @@ def initialize(self): | |
if not msg.may_be_emitted(): | ||
self._msgs_state[msg.msgid] = False | ||
|
||
def _discover_files(self, files_or_modules): | ||
for something in files_or_modules: | ||
if os.path.isdir(something) and not os.path.isfile(os.path.join(something, '__init__.py')): | ||
skip_subtrees = [] | ||
for root, dirs, files in os.walk(something): | ||
if any(root.startswith(s) for s in skip_subtrees): | ||
# Skip subtree of already discovered package | ||
continue | ||
elif '__init__.py' in files: | ||
skip_subtrees.append(root) | ||
yield root | ||
else: | ||
yield from (os.path.join(root, file) for file in files if file.endswith('.py')) | ||
else: | ||
yield something | ||
|
||
def check(self, files_or_modules: Union[Sequence[str], str]) -> None: | ||
"""main checking entry: check a list of files or modules from their name. | ||
|
||
|
@@ -1019,6 +1042,8 @@ def check(self, files_or_modules: Union[Sequence[str], str]) -> None: | |
DeprecationWarning, | ||
) | ||
files_or_modules = (files_or_modules,) # type: ignore[assignment] | ||
if self.config.recursive: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to happen before in the initialization but should we make recursive true, if pylint is called without directory ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think
I agree that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
pytest does this I think it's a nice default value. It was asked here and has currently 12 upvotes
I meant both You made me realize that in fact we can make recursive true when there is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My expectation is that just running the command also gives a short help message. I know so many CLI tool that do this. Edit: Let me rephrase, I know that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, this is what happen when the tool can't work without providing arguments. For example
Imo, pylint should work without any argument (like flake8). But I wonder why mypy do not though. Do you know the rational behind it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For 1, no, it should show the help like before, we did not reach a consensus on this with @DanielNoord and I'm going to create an issue to settle it by popular vote, once we merge this one. (By the way, what do you think of defaulting to "." ? :) ) For 2. yes exactly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for myself but perhaps helpful for others. I think for now this is the summary: When in When in parent without When in parent without For When in When in parent without When in parent without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I would say those should indeed be recursive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last commit implements default recursive mode when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's leave this comment as unresolved as it is quite important for future people looking back at this PR and it might get easily lost. |
||
files_or_modules = tuple(self._discover_files(files_or_modules)) | ||
matusvalo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if self.config.from_stdin: | ||
if len(files_or_modules) != 1: | ||
raise exceptions.InvalidArgsError( | ||
|
Uh oh!
There was an error while loading. Please reload this page.