From 2b3f48d9ee2b5fefe3d4eac7ab3acebe96d4e4cd Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 3 May 2019 19:15:25 +0200 Subject: [PATCH] build_tools/style.fish: Use black as python formatter (Also renames the silly "$f_files" to "$fish_files") --- build_tools/style.fish | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/build_tools/style.fish b/build_tools/style.fish index 71b113d6c..b3ae670ea 100755 --- a/build_tools/style.fish +++ b/build_tools/style.fish @@ -5,7 +5,8 @@ # set git_clang_format no set c_files -set f_files +set fish_files +set python_files set all no if test "$argv[1]" = "--all" @@ -30,7 +31,8 @@ if test $all = yes # For now we don't restyle all fish scripts other than completion scripts. That's because people # really like to vertically align the elements of the `complete` command and fish_indent # currently does not honor that whitespace. - set f_files (printf '%s\n' share/***.fish | grep -v /completions/) + set fish_files (printf '%s\n' share/***.fish | grep -v /completions/) + set python_files **.py else # We haven't been asked to reformat all the source. If there are uncommitted changes reformat # those using `git clang-format`. Else reformat the files in the most recent commit. @@ -49,7 +51,8 @@ else test -f $file; and set c_files $c_files $file end # Extract just the fish files. - set f_files (string match -r '^.*\.fish$' -- $files) + set fish_files (string match -r '^.*\.fish$' -- $files) + set python_files (string match -r '^.*\.py$' -- $files) end # Run the C++ reformatter if we have any C++ files. @@ -90,7 +93,7 @@ if set -q c_files[1] end # Run the fish reformatter if we have any fish files. -if set -q f_files[1] +if set -q fish_files[1] if not type -q fish_indent make fish_indent set PATH . $PATH @@ -99,7 +102,7 @@ if set -q f_files[1] echo ======================================== echo Running fish_indent echo ======================================== - for file in $f_files + for file in $fish_files cp $file $file.new # preserves mode bits fish_indent <$file >$file.new if cmp --quiet $file $file.new @@ -110,3 +113,17 @@ if set -q f_files[1] end end end + +if set -q python_files[1] + if not type -q black + echo + echo Please install "`black`" to style python + echo + else + echo + echo ======================================== + echo Running black + echo ======================================== + black $python_files + end +end