How to use pylint for all the files with non py extension in a directory for windows environment

264 Views Asked by At

I am using pylint version 2.16.1 on Python version 3.9 on windows.

I need to execute pylint for all the files of non ".py" extension (example .abc extension) in directory and its subdirectories. I could not find an option as part of the pylint to perform the same.

I could run pylint on a specific file of non py extension (example .abc extension) and it successfully gives the output. For example: pylint my_file_name.abc

But if I try to run pylint with wildcard '*.abc" , it gives an error:

************* Module *.abc *.abc:1:0: F0001: No module named *.abc (fatal)

Note: I do have the init.py in the folder I am trying run from the folder.

1

There are 1 best solutions below

2
Piyush Aggarwal On

Looks like there is not a direct approach in pylint (at-least in windows) to run it on all the files of non py extension with a wild-cards. But pylint does work on the list of files mentioned in a single command and provide the consolidated score.

The approach is to have batch file which can first parse the the directory (recursively) for all the files of the desired extension. The filenames are stored in the variable (not an array) in a concatenated approach. pylint command can then be executed on this variable of filenames.

The following snippet of code shows the approach:

@echo off
setlocal enabledelayedexpansion

set "abc_files_path=my_project_path\*.abc"

set files=

set "fileCount=0"
for /f "delims=" %%f in ('dir /b /s %abc_files_path%') do (
set "files[!fileCount!]=%%f"

set "files=!files! %%f"
)

pylint %files%