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
1 change: 1 addition & 0 deletions packages/python-ta/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Updated `SnapshotTracer` to convert snapshots to JSON with `snapshot_to_json` and pass JSON data to the webstepper template instead of SVG.
- Added configuration options for maximum name lengths of each name category in `invalid_name_checker.py`.
- Update configuration options to support `.toml` files
- Updated plain text and HTML PyTA reports to not show sections with no errors and only show 'good job' message once when there are no errors in either section.

### 💫 New checkers

Expand Down
8 changes: 8 additions & 0 deletions packages/python-ta/src/python_ta/reporters/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import os.path
import random
import sys
from collections import defaultdict
from datetime import datetime
Expand Down Expand Up @@ -70,6 +71,9 @@ class PythonTaReporter(BaseReporter):
_NUM_LENGTH_SPACES = 3
_AFTER_NUM_SPACES = 2

# List of emojis to randomly choose for the no errors message.
NO_ERR_EMOJIS = ["🎉", "🥳", "🌟", "👍", "👏", "😊", "🎊", "🙌", "🕺"]

# The error messages to report, mapping filename to a list of messages.
messages: dict[str, list[Message]]
# Whether the reporter's output stream should be closed out.
Expand All @@ -84,6 +88,10 @@ def __init__(self) -> None:
self.current_file = ""
self.should_close_out = False

def no_err_message(self) -> str:
"""Return the no errors message with a random emoji."""
return "No problems detected, good job! " + random.choice(self.NO_ERR_EMOJIS)

def print_messages(self, level: str = "all") -> None:
"""Print messages for the current file.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class HTMLReporter(PythonTaReporter):
}
_PRE_LINE_NUM_SPACES = 0

no_err_message = "No problems detected, good job!"
no_snippet = "No code to display for this message."
code_err_title = "Code Errors or Forbidden Usage (fix: high priority)"
style_err_title = "Style or Convention Errors (fix: before submission)"
Expand Down
26 changes: 12 additions & 14 deletions packages/python-ta/src/python_ta/reporters/plain_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class PlainReporter(PythonTaReporter):
_COLOURING = {}
code_err_title = "=== Code errors/forbidden usage (fix: high priority) ==="
style_err_title = "=== Style/convention errors (fix: before submission) ==="
no_err_message = "No problems detected, good job!" + _BREAK * 2
no_snippet = "No code to display for this message." + _BREAK * 2

def print_messages(self, level: str = "all") -> None:
Expand All @@ -35,20 +34,19 @@ def print_messages(self, level: str = "all") -> None:

result = "PyTA Report for: " + self._colourify("bold", self.current_file) + self._BREAK
result += self._generate_report_date_time() + self._BREAK
result += self._colourify("code-heading", self.code_err_title + self._BREAK)
messages_result = self._colour_messages_by_type(error_msgs)
if messages_result:
result += messages_result
else:
result += self.no_err_message

if level == "all":

code_msgs_result = self._colour_messages_by_type(error_msgs)
if code_msgs_result:
result += self._colourify("code-heading", self.code_err_title + self._BREAK)
result += code_msgs_result

style_msgs_result = self._colour_messages_by_type(style_msgs) if level == "all" else ""
if style_msgs_result:
result += self._colourify("style-heading", self.style_err_title + self._BREAK)
messages_result = self._colour_messages_by_type(style_msgs)
if messages_result:
result += messages_result
else:
result += self.no_err_message
result += style_msgs_result

if not code_msgs_result and (not style_msgs_result or level != "all"):
result += self.no_err_message()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to also display this message if level == "error" and there are no code messages, even when there are style messages. (This is also true of the HTML Reporter, so please double-check that.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change to plain_reporter.py. For the HTML reporter, the level argument doesn't appear to actually be utilized or affect the output, since the report is produced by display_messages which doesn't even accept level as an argument.

def print_messages(self, level="all"):
"""Do nothing to print messages, since all are displayed in a single HTML file."""
def display_messages(self, layout: BaseLayout) -> None:
"""Hook for displaying the messages of the reporter


self.writeln(result)
self.out.flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ header {
}

.main-grid {
column-gap: 3rem;
display: grid;
flex: 1;
grid-template-columns: min-content 1fr;
Expand Down Expand Up @@ -363,6 +364,12 @@ code {
.style-error-id a:link {
}

.no-errors {
font-size: 1.1em;
padding: 25px;
text-align: center;
}

.line-num {
color: var(--text-secondary);
font-size: 90%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
</div>
<ul>
{% for filenum, (filename, messages) in enumerate(grouped_messages.items()) %}
{% set code_messages = messages[0] -%}
{% set style_messages = messages[1] -%}
{% set has_code_messages = code_messages|length > 0 -%}
{% set has_style_messages = style_messages|length > 0 -%}
<li class="collapsible expanded">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
Expand All @@ -41,7 +45,9 @@
{{os.path.basename(filename)}}
</a>
</span>
{% if has_code_messages or has_style_messages -%}
<ul>
{% if has_code_messages -%}
<li class="collapsible expanded">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
Expand All @@ -53,15 +59,17 @@
<strong>Code Errors or Forbidden Usage</strong>
</span>
<ul>
{% for message_id in messages[0] %}
{% for message_id in code_messages %}
<li>
<a href={{'#{}-{}'.format(filenum, message_id)}}>
{{'{} ({})'.format(message_id, messages[0][message_id][0].symbol)}}
{{'{} ({})'.format(message_id, code_messages[message_id][0].symbol)}}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endif -%}
{% if has_style_messages -%}
<li class="collapsible expanded">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
Expand All @@ -73,27 +81,34 @@
<strong>Style and Convention</strong>
</span>
<ul>
{% for message_id in messages[1] %}
{% for message_id in style_messages %}
<li>
<a href={{'#{}-{}'.format(filenum, message_id)}}>
{{'{} ({})'.format(message_id, messages[1][message_id][0].symbol)}}
{{'{} ({})'.format(message_id, style_messages[message_id][0].symbol)}}
</a>
</li>
{% endfor %}
</ul>
</li>
{%- endif %}
</ul>
{%- endif %}
</li>
{% endfor %}
</ul>
</section>
<main>
{% set limit = reporter.linter.config.pyta_number_of_messages %}
{% for filenum, (filename, messages) in enumerate(grouped_messages.items()) %}
{% set code_messages = messages[0] -%}
{% set style_messages = messages[1] -%}
{% set has_code_messages = code_messages|length > 0 -%}
{% set has_style_messages = style_messages|length > 0 -%}
<section id={{filenum}}>
<div class="section-header">
<h2> {{ filename }} </h2>
</div>
{% if has_code_messages -%}
<article class="error-output code-errors">
<h3 class="category-heading">
<span>{{ reporter.code_err_title }}</span>
Expand All @@ -107,8 +122,8 @@
</span>
</h3>
<div class="content collapsible expanded">
{% for message_id in messages[0] %}
{% set occurrences = messages[0][message_id] %}
{% for message_id in code_messages %}
{% set occurrences = code_messages[message_id] %}
<div class="error-instance" id={{'{}-{}'.format(filenum, message_id)}}>
<div class="info">
{% set mid = message_id.lower() %}
Expand Down Expand Up @@ -165,11 +180,11 @@
{% endfor %}
</div>
</div>
{% else %}
<span class="empty-placeholder">{{ reporter.no_err_message }}</span>
{% endfor %}
</div>
</article>
{% endif -%}
{% if has_style_messages -%}
<article class="error-output style-errors">
<h3 class="category-heading">
<span>{{ reporter.style_err_title }}</span>
Expand All @@ -183,7 +198,7 @@
</span>
</h3>
<div class="content collapsible expanded">
{% for message_id, occurrences in messages[1].items() %}
{% for message_id, occurrences in style_messages.items() %}
<div class="error-instance" id={{'{}-{}'.format(filenum, message_id)}}>
<div class="info">
{% set mid = message_id.lower() %}
Expand Down Expand Up @@ -241,11 +256,13 @@
</div>

</div>
{% else %}
<span class="empty-placeholder">{{ reporter.no_err_message }}</span>
{% endfor %}
</div>
</article>
{%- endif %}
{%- if not has_code_messages and not has_style_messages -%}
<div class="no-errors">{{ reporter.no_err_message() }}</div>
{%- endif %}
</section>
{% endfor %}
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
}

.main-grid {
column-gap: 3rem;
display: grid;
flex: 1;
grid-template-columns: min-content 1fr;
Expand Down Expand Up @@ -369,6 +370,12 @@
.style-error-id a:link {
}

.no-errors {
font-size: 1.1em;
padding: 25px;
text-align: center;
}

.line-num {
color: var(--text-secondary);
font-size: 90%;
Expand Down Expand Up @@ -1072,20 +1079,6 @@ <h2>Table of Contents</h2>
</a>
</span>
<ul>
<li class="collapsible expanded">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="10" height="10">
<path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" />
</svg>
</button>
<span>
<strong>Code Errors or Forbidden Usage</strong>
</span>
<ul>

</ul>
</li>
<li class="collapsible expanded">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
Expand Down Expand Up @@ -1135,24 +1128,6 @@ <h2>Table of Contents</h2>
<section id=0>
<div class="section-header">
</div>
<article class="error-output code-errors">
<h3 class="category-heading">
<span>Code Errors or Forbidden Usage (fix: high priority)</span>
<span class="slider">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
<svg class="collapse-trigger" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="60" height="30">
<path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" />
</svg>
</button>
</span>
</h3>
<div class="content collapsible expanded">

<span class="empty-placeholder">No problems detected, good job!</span>

</div>
</article>
<article class="error-output style-errors">
<h3 class="category-heading">
<span>Style or Convention Errors (fix: before submission)</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
}

.main-grid {
column-gap: 3rem;
display: grid;
flex: 1;
grid-template-columns: min-content 1fr;
Expand Down Expand Up @@ -369,6 +370,12 @@
.style-error-id a:link {
}

.no-errors {
font-size: 1.1em;
padding: 25px;
text-align: center;
}

.line-num {
color: var(--text-secondary);
font-size: 90%;
Expand Down Expand Up @@ -1072,20 +1079,6 @@ <h2>Table of Contents</h2>
</a>
</span>
<ul>
<li class="collapsible expanded">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="10" height="10">
<path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" />
</svg>
</button>
<span>
<strong>Code Errors or Forbidden Usage</strong>
</span>
<ul>

</ul>
</li>
<li class="collapsible expanded">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
Expand Down Expand Up @@ -1141,24 +1134,6 @@ <h2>Table of Contents</h2>
<section id=0>
<div class="section-header">
</div>
<article class="error-output code-errors">
<h3 class="category-heading">
<span>Code Errors or Forbidden Usage (fix: high priority)</span>
<span class="slider">
<button>
<!-- Chevron down icon from heroicons at https://heroicons.com/ -->
<svg class="collapse-trigger" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="60" height="30">
<path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" />
</svg>
</button>
</span>
</h3>
<div class="content collapsible expanded">

<span class="empty-placeholder">No problems detected, good job!</span>

</div>
</article>
<article class="error-output style-errors">
<h3 class="category-heading">
<span>Style or Convention Errors (fix: before submission)</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
}

.main-grid {
column-gap: 3rem;
display: grid;
flex: 1;
grid-template-columns: min-content 1fr;
Expand Down Expand Up @@ -369,6 +370,12 @@
.style-error-id a:link {
}

.no-errors {
font-size: 1.1em;
padding: 25px;
text-align: center;
}

.line-num {
color: var(--text-secondary);
font-size: 90%;
Expand Down
Loading