Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run autopep8 on all python files except migrations doable?

Am wondering is there a way to run autopep8 command on all python files exept the migrations? To fix all pep8 errors.

Instead of doing the command

autopep8 --in-place --aggressive --aggressive <filename>
like image 692
tobias Avatar asked Sep 20 '25 17:09

tobias


2 Answers

You can let find first look for files and then use autopep8 on these:

find -type f -name '*.py' ! -path '*/migrations/*' -exec autopep8 --in-place --aggressive --aggressive '{}' \;

Here find thus looks for files that match the *.py glob pattern, but do not satisfy the */migrations/* pattern for its path.

like image 182
Willem Van Onsem Avatar answered Sep 22 '25 11:09

Willem Van Onsem


You can write a script to automate this:

#!/usr/bin/env bash

echo "Running autopep..."
find -type f -name '*.py' ! -path '*/migrations/*' -exec autopep8 --in-place --aggressive --aggressive '{}' \;

echo "Running pycodestyle..."
find -type f -name '*.py' ! -path '*/migrations/*' -exec pycodestyle --first '{}' \;
like image 24
Emmanuel Chalo Avatar answered Sep 22 '25 12:09

Emmanuel Chalo