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

use path_empty() to reduce the complexity of main() #1

Merged
merged 1 commit into from
Apr 29, 2020
Merged
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
20 changes: 12 additions & 8 deletions black.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
Pattern,
Sequence,
Set,
Sized,
Tuple,
TypeVar,
Union,
Expand Down Expand Up @@ -472,7 +473,7 @@ def main(
report = Report(check=check, diff=diff, quiet=quiet, verbose=verbose)
root = find_project_root(src)
sources: Set[Path] = set()
path_empty(src, quiet, verbose, ctx)
path_empty(src, "No Path provided. Nothing to do 😴", quiet, verbose, ctx)
for s in src:
p = Path(s)
if p.is_dir():
Expand All @@ -497,10 +498,13 @@ def main(
else:
err(f"invalid path: {s}")

if len(sources) == 0:
if verbose or not quiet:
out("No Python files are present to be formatted. Nothing to do 😴")
ctx.exit(0)
path_empty(
sources,
"No Python files are present to be formatted. Nothing to do 😴",
quiet,
verbose,
ctx,
)

if len(sources) == 1:
reformat_one(
Expand All @@ -522,14 +526,14 @@ def main(


def path_empty(
src: Tuple[str, ...], quiet: bool, verbose: bool, ctx: click.Context
src: Sized, msg: str, quiet: bool, verbose: bool, ctx: click.Context
) -> None:
"""
Exit if there is no `src` provided for formatting
"""
if not src:
if len(src) == 0:
if verbose or not quiet:
out("No Path provided. Nothing to do 😴")
out(msg)
ctx.exit(0)


Expand Down