Skip to content

Commit

Permalink
Rename module to tracerite. Change images to WebP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tronic committed Feb 2, 2023
1 parent 7ab8cb5 commit d25d487
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 66 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Other languages such as C++ have gotten quite useful error messages and
diagnostics with tips on how the fix the problems but Python is still stuck
with the bare stacktraces that are very intimidating and often not very helpful.

![Niceback](https://raw.githubusercontent.com/Tronic/niceback/master/docs/with-niceback.png)
**Niceback backtrace shows where the user has terminated the program.**
![TraceRite](https://raw.githubusercontent.com/sanic-org/tracerite/master/docs/with-tracerite.webp)
**TraceRite backtrace shows where the user has terminated the program.**

Niceback hides the irrelevant IPython/notebook internals and concisely shows
TraceRite hides the irrelevant IPython/notebook internals and concisely shows
what happened (the program was interrupted) and where that happened. This could
further be improved by converting the KeyboardInterrupt message into something
more suitable, like "You stopped the program", but what you see above is just
Expand All @@ -16,28 +16,28 @@ the default handling that never considered this particular error.
Although IPython and Google Colab developers have done their tweaks to improve
backtraces, it is all too apparent that much remains to be done:

![Colab](https://raw.githubusercontent.com/Tronic/niceback/master/docs/without-niceback.png)
![Colab](https://raw.githubusercontent.com/sanic-org/tracerite/master/docs/without-tracerite.webp)
**Standard backtrace from Google Colab.**

Even for the experienced programmer, it is tedious to read through the wall of
text to find the relevant details of what went wrong.

In more complex situations where one might get many screenfuls of standard
traceback, Niceback produces scrollable outputs that concentrate on the relevant
traceback, TraceRite produces scrollable outputs that concentrate on the relevant
details but also provide variable inspectors on each frame where it may be
relevant:

![Nested exceptions](https://raw.githubusercontent.com/Tronic/niceback/master/docs/nested.png)
**Niceback output with nested exceptions.**
![Nested exceptions](https://raw.githubusercontent.com/sanic-org/tracerite/master/docs/nested.webp)
**TraceRite output with nested exceptions.**


## Usage

At the beginning of your Notebook:

```ipython
!pip install niceback
%load_ext niceback
!pip install tracerite
%load_ext tracerite
```

## Background
Expand Down
Binary file removed docs/nested.png
Binary file not shown.
Binary file added docs/nested.webp
Binary file not shown.
Binary file removed docs/with-niceback.png
Binary file not shown.
Binary file added docs/with-tracerite.webp
Binary file not shown.
Binary file removed docs/without-niceback.png
Binary file not shown.
Binary file added docs/without-tracerite.webp
Binary file not shown.
10 changes: 0 additions & 10 deletions niceback/__init__.py

This file was deleted.

10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from setuptools import setup, find_packages

setup(
name="niceback",
author="L. Kärkkäinen",
name="tracerite",
author="Sanic Community",
author_email="[email protected]",
description="Human-readable tracebacks in Jupyter notebooks",
long_description=open("README.md").read(),
description="Human-readable HTML tracebacks for Python exceptions",
long_description=open("README.md", encoding="UTF-8").read(),
long_description_content_type="text/markdown",
url="https://github.com/Tronic/niceback",
url="https://github.com/sanic-org/tracerite",
use_scm_version=True,
setup_requires = ["setuptools_scm"],
packages=find_packages(),
Expand Down
10 changes: 10 additions & 0 deletions tracerite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pkg_resources

from .html import html_traceback
from .notebook import load_ipython_extension, unload_ipython_extension
from .trace import extract_chain

__all__ = ["html_traceback", "extract_chain"]
__version__ = pkg_resources.require(__name__)[0].version

del pkg_resources
14 changes: 7 additions & 7 deletions niceback/html.py → tracerite/html.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import pkg_resources

from html5tagger import E
from niceback.trace import extract_chain
from .trace import extract_chain

style = pkg_resources.resource_string(__name__, "style.css").decode()

detail_show = "{display: inherit}"

symbols = dict(call="➤", warning="⚠️", error="💣")

niceback_show = """\
function niceback_show(id) {
tracerite_show = """\
function tracerite_show(id) {
document.getElementById(id).scrollIntoView(
{behavior: 'smooth', block: 'nearest', inline: 'start'}
)
Expand All @@ -22,8 +22,8 @@

def html_traceback(exc=None, chain=None, **extract_args):
chain = chain or extract_chain(exc=exc, **extract_args)[-3:]
with E.div(class_="niceback") as doc:
doc.script(niceback_show)
with E.div(class_="tracerite") as doc:
doc.script(tracerite_show)
doc.style(style)
for e in chain:
if e is not chain[0]:
Expand All @@ -33,7 +33,7 @@ def html_traceback(exc=None, chain=None, **extract_args):
for e in reversed(chain):
for info in e["frames"]:
if info["relevance"] != "call":
doc(f"niceback_show('{info['id']}')\n")
doc(f"tracerite_show('{info['id']}')\n")
break
return doc

Expand Down Expand Up @@ -62,7 +62,7 @@ def _exception(doc, info):
doc.button(
E.strong(info["location"]).br.small(
info["function"] or "-"),
onclick=f"niceback_show('{info['id']}')"
onclick=f"tracerite_show('{info['id']}')"
)
with doc.div(class_="content"):
for info in limitedframes:
Expand Down
2 changes: 1 addition & 1 deletion niceback/inspector.py → tracerite/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import types
from functools import reduce

from niceback.logging import logger
from .logging import logger

blacklist_names = {"_", "In", "Out"}
blacklist_types = (
Expand Down
2 changes: 1 addition & 1 deletion niceback/logging.py → tracerite/logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging

logger = logging.getLogger("niceback")
logger = logging.getLogger("tracerite")
logger.setLevel(logging.INFO)
10 changes: 5 additions & 5 deletions niceback/notebook.py → tracerite/notebook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from niceback import html_traceback
from niceback.logging import logger
from .html import html_traceback
from .logging import logger


def _can_display_html():
Expand All @@ -16,7 +16,7 @@ def load_ipython_extension(ipython):
def showtraceback(*args, **kwargs):
try:
from IPython.display import display
# Niceback HTML output
# TraceRite HTML output
display(html_traceback(skip_until="<ipython-input-"))
except Exception:
# Fall back to built-in showtraceback
Expand All @@ -27,9 +27,9 @@ def showtraceback(*args, **kwargs):
if _can_display_html():
ipython.showtraceback = showtraceback
else:
logger.warning("Niceback not loaded: No HTML notebook detected")
logger.warning("Tracerite not loaded: No HTML notebook detected")
except Exception:
logger.error("Unable to load Niceback (please report a bug!)")
logger.error("Unable to load Tracerite (please report a bug!)")
raise


Expand Down
52 changes: 26 additions & 26 deletions niceback/style.css → tracerite/style.css
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/* CSS reset */
.niceback,
.niceback * {
.tracerite,
.tracerite * {
margin: 0;
padding: 0;
outline: none;
box-sizing: border-box;
overflow: hidden;
}
.niceback h3 {
.tracerite h3 {
margin: 0;
padding: .2em 0;
font-size: 1.2em;
}
.niceback p {
.tracerite p {
margin: 0;
}
.niceback pre {
.tracerite pre {
width: 100%;
padding: .5em;
padding-left: 5ch;
}
.niceback .codeline {
.tracerite .codeline {
text-indent: 4ch each-line;

}
.niceback .codeline::before {
.tracerite .codeline::before {
content: attr(data-lineno);
color: #888;
opacity: 0.0;
Expand All @@ -37,55 +37,55 @@
padding-right: 1ch;
width: 4ch;
}
.niceback pre:hover .codeline::before {
.tracerite pre:hover .codeline::before {
opacity: 1.0;
}
.niceback mark {
.tracerite mark {
background: transparent;
}
.niceback mark span {
.tracerite mark span {
background: #ff0;
}
.niceback mark::after {
.tracerite mark::after {
display: inline-block;
content: attr(data-symbol);
margin: -1ch;
transform: translate(2em, 0) scale(1.5);
}
.niceback .excmessage {
.tracerite .excmessage {
max-height: 12em;
overflow: auto;
}
.niceback .exctype {color: gray}
.niceback .traceback-labels {
.tracerite .exctype {color: gray}
.tracerite .traceback-labels {
display: flex;
align-items: center;
border-bottom: 3px solid gray;
margin-top: 0.3em;
}
.niceback .traceback-labels button {
.tracerite .traceback-labels button {
flex-shrink: 1;
line-height: 1.0;
padding: .5em;
}
.niceback .traceback-labels * {
.tracerite .traceback-labels * {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.niceback .traceback-tabs .content {
.tracerite .traceback-tabs .content {
scroll-snap-type: x mandatory;
display: flex;
align-items: flex-start;
overflow-x: auto;
scrollbar-width: none;
}
.niceback .traceback-tabs .content::-webkit-scrollbar {
.tracerite .traceback-tabs .content::-webkit-scrollbar {
width: 0;
height: 0;
}

.niceback .traceback-details {
.tracerite .traceback-details {
min-width: 20ch;
max-width: 100%;
max-height: 30em;
Expand All @@ -96,23 +96,23 @@
border-radius: .5em;
padding: .2em;
}
.niceback .traceback-details:last-child {
.tracerite .traceback-details:last-child {
width: 100%;
}
.niceback .inspector tbody tr:nth-child(odd),
.niceback .inspector tbody tr:nth-child(even),
.niceback .inspector th,
.niceback .inspector td {
.tracerite .inspector tbody tr:nth-child(odd),
.tracerite .inspector tbody tr:nth-child(even),
.tracerite .inspector th,
.tracerite .inspector td {
background: transparent;
text-align: left;
max-width: 20em;
text-overflow: ellipsis;
overflow: hidden;
}
.niceback .inspector table {
.tracerite .inspector table {
table-layout: fixed;
}
.niceback .inspector table td {
.tracerite .inspector table td {
border-collapse: collapse;
border: 1px solid white;
background: #eee;
Expand Down
4 changes: 2 additions & 2 deletions niceback/trace.py → tracerite/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from textwrap import dedent
from urllib.parse import quote

from niceback.inspector import extract_variables
from niceback.logging import logger
from .inspector import extract_variables
from .logging import logger

# Function name for IPython interactive input (matches input number)
ipython_input = re.compile(r"<ipython-input-(\d+)-\w+>")
Expand Down

0 comments on commit d25d487

Please sign in to comment.