Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
prospector[with_everything]==1.19.1
jsonpickle==4.1.2
Django==6.0.7
pylint==4.0.6
Django==6.1
pylint==4.0.7
Flask==3.1.3
mypy==2.3.0
mypy==2.3.1
53 changes: 7 additions & 46 deletions src/codacy_prospector.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,11 @@

def runProspector(options, files, cwd=None):
process = Popen(
['python3', '-W', 'ignore::DeprecationWarning', '-m', 'prospector'] + options + files,
['python3', '-m', 'prospector'] + options + files,
stdout=PIPE,
stderr=PIPE,
cwd=cwd
)
stdout, stderr = process.communicate()
if stderr:
stderr_text = stderr.decode('utf-8', errors='replace')
# Filter out deprecation warnings about [pep8] -> [pycodestyle]
filtered_stderr = '\n'.join(
line for line in stderr_text.split('\n')
if not any(skip in line for skip in ['[pep8]', 'pycodestyle', 'DeprecationWarning'])
).strip()
if filtered_stderr:
print(f"Prospector stderr: {filtered_stderr}", file=sys.stderr)
stdout = process.communicate()[0]
Comment thread
DMarinhoCodacy marked this conversation as resolved.
return stdout.decode('utf-8')

def isPython3(f):
Expand All @@ -83,44 +73,15 @@
return True

def parseResult(json_text):
json_text = json_text.strip()
if not json_text:
print("Prospector produced no output", file=sys.stderr)
return []
try:
data = json.loads(json_text)
except json.JSONDecodeError as e:
# Prospector failed or output is not JSON (e.g., due to E101 errors with pydocstyle)
print(f"Failed to parse Prospector output: {e}", file=sys.stderr)
return []

if not isinstance(data, dict):
print(f"Unexpected Prospector output type: {type(data).__name__}", file=sys.stderr)
return []

messages = data.get('messages', [])
messages = json.loads(json_text).get('messages',[])
denylist_codes = {'failure', "django-not-configured", "import-error", 'D203'}

def createResults():
for res in messages:
try:
if res['code'] in denylist_codes:
continue
if res['code'] not in denylist_codes:
location = res['location']
yield Result(
filename=location['path'],
message=f"{res['message']} ({res['code']})",
patternId=res['source'],
line=location['line'],
sourceId=res['code'],
)
except (KeyError, TypeError) as e:
code = res.get('code', 'UNKNOWN')
message = res.get('message', 'NO_MESSAGE')
print(f"Skipping malformed message for {code}: {message} - Missing/invalid field: {e}", file=sys.stderr)
print(f" Full message object: {json.dumps(res, indent=2)}", file=sys.stderr)
continue

filename=location['path'],

Check notice on line 83 in src/codacy_prospector.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/codacy_prospector.py#L83

Trailing whitespace
message=f"{res['message']} ({res['code']})", patternId=res['source'], line=location['line'] if location['line'] is not None else 1, sourceId=res['code'])

Check notice on line 84 in src/codacy_prospector.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/codacy_prospector.py#L84

line too long (173 > 159 characters) (E501)
return list(createResults())

def walkDirectory(directory):
Expand Down Expand Up @@ -183,4 +144,4 @@
print(resultsToJson(results))
except Exception:
traceback.print_exc()
sys.exit(1)
sys.exit(1)