I am using the line_profiler, which allows you to drop @profile decorators anywhere in a python codebase and returns line output.
However, if you try to execute python code that contains one such @profile decorator without loading this line_profiler module, the code will fail with a NameError, for such a decorator is defined and injected by this external library.
I'd like a bash command that attempts to run my python script with vanilla python. Then, if and only if the error consists of NameError, I want to give it a second try. This is what I have got so far:
python -u $file || python -m kernprof -l -v --outfile=/dev/null $file"
The problem is of course that if my python code has ANY errors at all, be it ValueError or IndentationError or anything, it tries the profiler. I want to ONLY run the profiler if the error contains a string NameError: name 'profile' is not defined is found within stderr.
grep?grepingstderr, but I can't quite get things working.cmd 2> >(grep -v "WARNING" >&2)which seems along the right lines. I need another mini-program that either "fails" or "succeeds" based onstderrI guess?