-
-
Notifications
You must be signed in to change notification settings - Fork 8
Add --exit-code option and add number of files to output
#81
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 2 commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,18 +21,37 @@ def __init__(self, argv: Union[List[str], None]) -> None: | |||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| self.config = self._arguments_manager.namespace | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if argv := argv or sys.argv[1:]: | ||||||||||||||||||||||||||||||||||||||||||||||||
| self._arguments_manager.parse_options(argv) | ||||||||||||||||||||||||||||||||||||||||||||||||
| for formatter in formatting.FORMATTERS: | ||||||||||||||||||||||||||||||||||||||||||||||||
| formatter.set_config_namespace(self.config) | ||||||||||||||||||||||||||||||||||||||||||||||||
| self._check_files(self.config.files) | ||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Display help message if nothing is passed | ||||||||||||||||||||||||||||||||||||||||||||||||
| if not (argv := argv or sys.argv[1:]): | ||||||||||||||||||||||||||||||||||||||||||||||||
| self._arguments_manager.print_help() | ||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # Parse options and register on formatters | ||||||||||||||||||||||||||||||||||||||||||||||||
| self._arguments_manager.parse_options(argv) | ||||||||||||||||||||||||||||||||||||||||||||||||
| for formatter in formatting.FORMATTERS: | ||||||||||||||||||||||||||||||||||||||||||||||||
| formatter.set_config_namespace(self.config) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| def _check_files(self, arguments: List[str]) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||
| self._check_files(self.config.files) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| def _check_files(self, files: List[str]) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||
| """Find all files and perform the formatting.""" | ||||||||||||||||||||||||||||||||||||||||||||||||
| filepaths = utils._find_python_files(arguments, self.config.exclude) | ||||||||||||||||||||||||||||||||||||||||||||||||
| self._format_files(filepaths) | ||||||||||||||||||||||||||||||||||||||||||||||||
| filepaths = utils._find_python_files(files, self.config.exclude) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| is_changed = self._format_files(filepaths) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if not is_changed: # pylint: disable=consider-using-assignment-expr | ||||||||||||||||||||||||||||||||||||||||||||||||
| if len(filepaths) > 1: | ||||||||||||||||||||||||||||||||||||||||||||||||
| files_string = f"{len(filepaths)} files" | ||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
| files_string = "1 file" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| utils._print_to_console( | ||||||||||||||||||||||||||||||||||||||||||||||||
| f"Nothing to do! All docstrings in {files_string} are correct 🎉\n", | ||||||||||||||||||||||||||||||||||||||||||||||||
| self.config.quiet, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| utils._sys_exit(0, self.config.exit_code) | ||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
| utils._sys_exit(32, self.config.exit_code) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if not is_changed: # pylint: disable=consider-using-assignment-expr | |
| if len(filepaths) > 1: | |
| files_string = f"{len(filepaths)} files" | |
| else: | |
| files_string = "1 file" | |
| utils._print_to_console( | |
| f"Nothing to do! All docstrings in {files_string} are correct 🎉\n", | |
| self.config.quiet, | |
| ) | |
| utils._sys_exit(0, self.config.exit_code) | |
| else: | |
| utils._sys_exit(32, self.config.exit_code) | |
| if is_changed: # pylint: disable=consider-using-assignment-expr | |
| utils._sys_exit(32, self.config.exit_code) | |
| return # We may not sys exit depending on options | |
| files_string = f"{len(filepaths)}" | |
| files_string += "files" if len(filepaths) > 1 else "file" | |
| utils._print_to_console( | |
| f"Nothing to do! All docstrings in {files_string} are correct 🎉\n", | |
| self.config.quiet, | |
| ) | |
| utils._sys_exit(0, self.config.exit_code) |
You know my favorite thing in the world is premature return I just had to say it 😄 Depending on what you think of displaying the name of a file if it's unique there the suggestion might need some tweaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it around a little bit. You actually found a small bug: for 0 files checked due to exclude patterns we still said that 1 file was correct.
I changed it (and fixed the tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a nice little bonus ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fails with
IndexErrorin some test cases. I'll keep it in mind for a future enhancement.