[UPDATED based on useful additions in the comments]
If you do not have the __init__.py file in the directory, and you do not want for various reasons, my approach
touch __init__.py; pylint $(pwd); rm __init__.py
If you already have the __init__.py file in this directory, it will be deleted .
If you often need these functions, you must create a function that does this, while preserving any previously existing __init__.py file. For example, you can put the following in your ~/.bashrc , where pylint_all_the_things exported pylint_all_the_things that it can be called from any subshell. Alternatively, you can put the function body in an executable script.
By default, this function starts pylint in the current directory, but you can specify the directory that will be used as the first argument to the function.
# Run pylint in a given directory, defaulting to the working directory pylint_all_the_things() { local d=${1:-$(pwd)} # Abort if called with a non-directory argument. if [ ! -d "${d}" ]; then echo "Not a directory: ${d}" echo "If ${d} is a module or package name, call pylint directly" exit 1 fi local module_marker="${d}/__init__.py" # Cleanup function to later remove __init__.py if it does not currently exist [[ ! -f ${module_marker} ]] && local not_a_module=1 cleanup() { (( ${not_a_module:-0} == 1 )) && rm "${module_marker}" } trap cleanup EXIT # Create __init__.py if it does not exist touch "${module_marker}" pylint "${d}" cleanup } export -f pylint_all_the_things
The trap utility is used to ensure that cleanup happens even if the call to pylint fails and you have set -e turned on, which causes the function to exit before the cleanup line is reached.
If you want to call pylint recursively for the current working directory and all subfolders, you can do something like
for dir in ./**/ ; do pylint_all_the_things "$dir"; done
Which will require that globstar be included in bash ( shopt -s globstar ).
Ryan feeley
source share