Commit 21dc1c91 authored by Charles Ferguson's avatar Charles Ferguson
Browse files

Add cleaning of python files to 'clean' action.

When python files are cleaned, we will clear out all the .pyc, .pyo
files, and any __pycache__ directories.
parent 65a5762c
...@@ -28,6 +28,23 @@ function bool() { ...@@ -28,6 +28,23 @@ function bool() {
} }
##
# Trim leading and trailing whitespace from a string.
#
# @param $1 String to trim
function trim() {
local var="$1"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
echo -n "$var"
}
## ##
# Read a configuration parameter from the project's config. # Read a configuration parameter from the project's config.
# #
......
...@@ -75,11 +75,17 @@ function python_active() { ...@@ -75,11 +75,17 @@ function python_active() {
files="$(config -e lint_python_files '*.py')" files="$(config -e lint_python_files '*.py')"
elif [[ "$action" == 'docs' ]] ; then elif [[ "$action" == 'docs' ]] ; then
files="$(config -e docs_python_files '*.py')" files="$(config -e docs_python_files '*.py')"
elif [[ "$action" == 'clean' ]] ; then
files="$(config -e docs_python_files '*.py')"
files="$files $(config -e lint_python_files '*.py') "
files="$files $(config -e test_python_files '*_test.py')"
else else
# Unrecognised type # Unrecognised type
return 1 return 1
fi fi
files="$(trim "$files")"
if [[ -n "$files" ]] ; then if [[ -n "$files" ]] ; then
return 0 return 0
fi fi
...@@ -221,6 +227,39 @@ function python_run_docs() { ...@@ -221,6 +227,39 @@ function python_run_docs() {
docs_total=$(( docs_total+1 )) docs_total=$(( docs_total+1 ))
} }
function python_run_clean() {
local files=''
local lastdir=''
local thisdir
files="$(config -e docs_python_files '*.py')"
files="$files $(config -e lint_python_files '*.py') "
files="$files $(config -e test_python_files '*_test.py')"
lastdir=''
for file in $files ; do
file="./$file"
if [[ "${file: -3}" == '.py' ]] ; then
if [[ -f "${file//.py/.pyc}" ]] ; then
rm "${file//.py/.pyc}"
fi
if [[ -f "${file//.py/.pyo}" ]] ; then
rm "${file//.py/.pyo}"
fi
# Only check each directory once.
if [[ "${file:0:${#lastdir} + 1}" != "${lastdir}/" ]] || \
[[ "${file:${#lastdir} + 1}" =~ / ]] ; then
thisdir="$(dirname "$file")"
if [[ -d "${thisdir}/__pycache__" ]] ; then
rmtree "${thisdir:-THISDIR_NOT_SET}/__pycache__"
fi
lastdir="$thisdir"
fi
fi
done
}
function python_process_test() { function python_process_test() {
: # Nothing to do : # Nothing to do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment