| 
									
										
										
										
											2021-01-23 05:44:05 +13:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							| 
									
										
										
										
											2021-01-03 19:08:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | set -e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P) | 
					
						
							|  |  |  | cd "${script_path}/.." || exit 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-22 07:24:42 -04:00
										 |  |  | check_argument="--check" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ "$#" -gt "0" ]; then | 
					
						
							|  |  |  |     if  [ "--overwrite-inplace" = "$1" ] ; then | 
					
						
							|  |  |  |         check_argument="" | 
					
						
							|  |  |  |         shift | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-03 19:08:26 -07:00
										 |  |  | if [ "$#" -eq "0" ]; then | 
					
						
							| 
									
										
										
										
											2024-07-16 20:41:50 +09:00
										 |  |  |     files=() | 
					
						
							|  |  |  |     while IFS= read -r file; do | 
					
						
							|  |  |  |         files+=("$file") | 
					
						
							|  |  |  |     done <  <( | 
					
						
							| 
									
										
										
										
											2021-01-03 19:08:26 -07:00
										 |  |  |         git ls-files '*.py' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     files=() | 
					
						
							|  |  |  |     for file in "$@"; do | 
					
						
							|  |  |  |         if [[ "${file}" == *".py" ]]; then | 
					
						
							|  |  |  |             files+=("${file}") | 
					
						
							|  |  |  |         fi | 
					
						
							|  |  |  |     done | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (( ${#files[@]} )); then | 
					
						
							| 
									
										
										
										
											2025-05-22 07:24:42 -04:00
										 |  |  |     if ! command -v black >/dev/null 2>&1 ; then | 
					
						
							|  |  |  |         echo "black is not available, but python files need linting! Either skip this script, or install black." | 
					
						
							| 
									
										
										
										
											2021-01-10 00:20:21 -07:00
										 |  |  |         exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-22 07:24:42 -04:00
										 |  |  |     black ${check_argument} "${files[@]}" | 
					
						
							| 
									
										
										
										
											2021-01-03 19:08:26 -07:00
										 |  |  | else | 
					
						
							|  |  |  |     echo "No py files to check." | 
					
						
							|  |  |  | fi |