I am trying to write a simple pylint parser that, given a python project, extracts the information on code smells, class names, and scores.
In particular, the script must analyze each python file and generate a data frame with the previously indicated information (code smells, project name, and score). I wrote the following snippet:
import os
import pandas as pd
from pylint.lint import Run
def pylint_project(project_name):
global project_df
pylint_options = ["--disable=F0010"]
python_files = [f for f in os.listdir(project_name) if f.endswith('.py')]
for file in python_files:
file_path = os.path.join(project_name, file)
pylint_output = Run([file_path] + pylint_options)
smell_count = pylint_output.lstrip().split()[1]
score = pylint_output.split()[-2]
project_df = pd.DataFrame({
"project_name": [project_name],
"smell_count": [smell_count],
"score": [score]
})
return project_df
path = "path/to/analyze"
com = pylint_project(path)
com.to_csv("path/to/save")
However, this snippet doesn't work correctly. Indeed, it only prints:
********* Module setup
E:\python_projects\machine_learning_projects\alibi\setup.py:17:0: C0301: Line too long (110/100) (line-too-long)
E:\python_projects\machine_learning_projects\alibi\setup.py:1:0: C0114: Missing module docstring (missing-module-docstring)
E:\python_projects\machine_learning_projects\alibi\setup.py:4:0: C0116: Missing function or method docstring (missing-function-docstring)
E:\python_projects\machine_learning_projects\alibi\setup.py:5:48: C0103: Variable name "f" doesn't conform to snake_case naming style (invalid-name)
E:\python_projects\machine_learning_projects\alibi\setup.py:10:0: W0122: Use of exec (exec-used)
E:\python_projects\machine_learning_projects\alibi\setup.py:10:5: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
E:\python_projects\machine_learning_projects\alibi\setup.py:10:5: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
E:\python_projects\machine_learning_projects\alibi\setup.py:34:18: E0602: Undefined variable '__version__' (undefined-variable)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00
But, without saving the data set, and in addition, it seems that it only analyzes a single file (setup.py)
How can I fix it?