Skip to content
Open
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: 0 additions & 1 deletion binder/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ pandas
matplotlib
ipywidgets
ipykernel
ansicolors
22 changes: 21 additions & 1 deletion papermill/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from colors import strip_color
import re


class AwsError(Exception):
Expand Down Expand Up @@ -59,6 +59,26 @@ class PapermillParameterOverwriteWarning(PapermillWarning):
"""Callee overwrites caller argument to pass down the stream."""


# The regular expression is copied from:
# https://github.com/jonathaneunice/colors/blob/
# c965f5b9103c5bd32a1572adb8024ebe83278fb0/colors/colors.py#L122-L131
#
# The original docstring notes that this does not strip all possible ANSI
# escape sequences related to color and style, but it attempts to cover the
# most common ones and a few known oddities produced by actual colorization
# libraries, including \x1b[K (EL, erase to end of line) and \x1b[m (more
# commonly expressed as \x1b[0m).
_COLORS = re.compile("\x1b\\[(K|.*?m)")


def strip_color(text):
"""Remove most ANSI color and style sequences from a string

Based on https://pypi.org/project/ansicolors/."""

return _COLORS.sub("", text)


def missing_dependency_generator(package, dep):
def missing_dep():
raise PapermillOptionalDependencyException(
Expand Down
3 changes: 1 addition & 2 deletions papermill/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from unittest.mock import ANY, patch

import nbformat
from colors import strip_color
from nbformat import validate

from .. import engines, translators
from ..exceptions import PapermillExecutionError
from ..exceptions import PapermillExecutionError, strip_color
from ..execute import execute_notebook
from ..iorw import load_notebook_node
from ..log import logger
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ requests
entrypoints
tenacity >= 5.0.2
aiohttp >=3.9.0; python_version=="3.12"
ansicolors
Loading