Skip to content

Commit

Permalink
Merge 419a001 into 5dde15d
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdavis90 committed Aug 6, 2019
2 parents 5dde15d + 419a001 commit 4639bc5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG
Expand Up @@ -2,11 +2,15 @@
# All notable changes to this project will be documented in this file.
# This project adheres to [Semantic Versioning](http://semver.org/).

## [0.28.1] UNRELEASED
## [0.29.0] UNRELEASED
### Added
- Add the `--quiet` flag to suppress output. The return code is 1 if there are
changes, similarly to the `--diff` flag.
### Changed
- Collect a parameter list into a single object. This allows us to track how a
parameter list is formatted, keeping state along the way. This helps when
supporting Python 3 type annotations.
- Catch and report `UnicodeDecodeError` exceptions.
### Fixed
- Format subscript lists so that splits are essentially free after a comma.
- Don't add a space between a string and its subscript.
Expand All @@ -24,7 +28,6 @@
### Changed
- Set `INDENT_DICTIONARY_VALUE` for Google style.
- Set `JOIN_MULTIPLE_LINES = False` for Google style.
- Catch and report `UnicodeDecodeError` exceptions.
### Fixed
- `BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=False` wasn't honored because the
number of newlines was erroneously calculated beforehand.
Expand Down
26 changes: 18 additions & 8 deletions yapf/__init__.py
Expand Up @@ -64,17 +64,22 @@ def main(argv):
action='store_true',
help='show version number and exit')

diff_inplace_group = parser.add_mutually_exclusive_group()
diff_inplace_group.add_argument(
diff_inplace_quiet_group = parser.add_mutually_exclusive_group()
diff_inplace_quiet_group.add_argument(
'-d',
'--diff',
action='store_true',
help='print the diff for the fixed source')
diff_inplace_group.add_argument(
diff_inplace_quiet_group.add_argument(
'-i',
'--in-place',
action='store_true',
help='make changes to files in place')
diff_inplace_quiet_group.add_argument(
'-q',
'--quiet',
action='store_true',
help='output nothing and set return value')

lines_recursive_group = parser.add_mutually_exclusive_group()
lines_recursive_group.add_argument(
Expand Down Expand Up @@ -217,8 +222,9 @@ def main(argv):
print_diff=args.diff,
verify=args.verify,
parallel=args.parallel,
quiet=args.quiet,
verbose=args.verbose)
return 1 if changed and args.diff else 0
return 1 if changed and (args.diff or args.quiet) else 0


def FormatFiles(filenames,
Expand All @@ -229,6 +235,7 @@ def FormatFiles(filenames,
print_diff=False,
verify=False,
parallel=False,
quiet=False,
verbose=False):
"""Format a list of files.
Expand All @@ -246,6 +253,7 @@ def FormatFiles(filenames,
diff that turns the formatted source into reformatter source.
verify: (bool) True if reformatted code should be verified for syntax.
parallel: (bool) True if should format multiple files in parallel.
quiet: (bool) True if should output nothing.
verbose: (bool) True if should print out filenames while processing.
Returns:
Expand All @@ -259,15 +267,16 @@ def FormatFiles(filenames,
with concurrent.futures.ProcessPoolExecutor(workers) as executor:
future_formats = [
executor.submit(_FormatFile, filename, lines, style_config,
no_local_style, in_place, print_diff, verify, verbose)
no_local_style, in_place, print_diff, verify,
quiet, verbose)
for filename in filenames
]
for future in concurrent.futures.as_completed(future_formats):
changed |= future.result()
else:
for filename in filenames:
changed |= _FormatFile(filename, lines, style_config, no_local_style,
in_place, print_diff, verify, verbose)
in_place, print_diff, verify, quiet, verbose)
return changed


Expand All @@ -278,9 +287,10 @@ def _FormatFile(filename,
in_place=False,
print_diff=False,
verify=False,
quiet=False,
verbose=False):
"""Format an individual file."""
if verbose:
if verbose and not quiet:
print('Reformatting %s' % filename)
if style_config is None and not no_local_style:
style_config = file_resources.GetDefaultStyleForDir(
Expand All @@ -294,7 +304,7 @@ def _FormatFile(filename,
print_diff=print_diff,
verify=verify,
logger=logging.warning)
if not in_place and reformatted_code:
if not in_place and not quiet and reformatted_code:
file_resources.WriteReformattedCode(filename, reformatted_code, encoding,
in_place)
return has_change
Expand Down

0 comments on commit 4639bc5

Please sign in to comment.