Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write a makefile to run pylint?

I have always been a windows user and this is my first time using solaris, so don't assume I know anything about shell scripts. lets say I have some 3 different python program in a folder.

$:pwd

/pythonpgm

$:ls

1.py 2.py 3.py

I am using pylint to staticlly analyze my code

$:pylint -rn 1.py

Instead of using it individually on each file, I want to write a Makefile so that I have to do this only once. How to write a makefile for this? and call make?

like image 900
user3546301 Avatar asked Apr 17 '14 17:04

user3546301


People also ask

Does Pylint run code?

Pylint returns bit-encoded exit codes. For example, an exit code of 20 means there was at least one warning message (4) and at least one convention message (16) and nothing else.


1 Answers

Using your editor, create a file called Makefile in your current directory and put this in it:

pylint: ; @for py in *.py; do echo "Linting $$py"; pylint -rn $$py; done

Now you just run make.

That's about as simple as it gets. If you want something more sophisticated, you can use:

PYLINT = pylint
PYLINTFLAGS = -rn

PYTHONFILES := $(wildcard *.py)

pylint: $(patsubst %.py,%.pylint,$(PYTHONFILES))

%.pylint:
        $(PYLINT) $(PYLINTFLAGS) $*.py

(note, the first character on the last line above MUST BE a real TAB character, it cannot be spaces). The advantage to this one is you can run make 1.pylint to just run pylint on the single file 1.py, or run make to run it on all files.

like image 145
MadScientist Avatar answered Sep 19 '22 23:09

MadScientist