Skip to content

Commit 6ad99e4

Browse files
Drop the dependency on ansicolors
The package is not actively maintained (last released in 2017), and the function we use is just based on a single simple regular expression. Copy the regular expression into papermill and drop the external dependency.
1 parent 5384731 commit 6ad99e4

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

binder/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ pandas
33
matplotlib
44
ipywidgets
55
ipykernel
6-
ansicolors

papermill/exceptions.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from colors import strip_color
1+
import re
22

33

44
class AwsError(Exception):
@@ -59,6 +59,23 @@ class PapermillParameterOverwriteWarning(PapermillWarning):
5959
"""Callee overwrites caller argument to pass down the stream."""
6060

6161

62+
def strip_color(text):
63+
"""Remove most ANSI color and style sequences from a string
64+
65+
Based on https://pypi.org/project/ansicolors/."""
66+
67+
# The regular expression is copied from:
68+
# https://github.com/jonathaneunice/colors/blob/
69+
# c965f5b9103c5bd32a1572adb8024ebe83278fb0/colors/colors.py#L122-L131
70+
#
71+
# The original docstring notes that this does not strip all possible ANSI
72+
# escape sequences related to color and style, but it attempts to cover the
73+
# most common ones and a few known oddities produced by actual
74+
# colorization libraries, including \x1b[K (EL, erase to end of line) and
75+
# \x1b[m (more commonly expressed as \x1b[0m).
76+
return re.sub("\x1b\\[(K|.*?m)", "", text)
77+
78+
6279
def missing_dependency_generator(package, dep):
6380
def missing_dep():
6481
raise PapermillOptionalDependencyException(

papermill/tests/test_execute.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from unittest.mock import ANY, patch
99

1010
import nbformat
11-
from colors import strip_color
1211
from nbformat import validate
1312

1413
from .. import engines, translators
15-
from ..exceptions import PapermillExecutionError
14+
from ..exceptions import PapermillExecutionError, strip_color
1615
from ..execute import execute_notebook
1716
from ..iorw import load_notebook_node
1817
from ..log import logger

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ requests
77
entrypoints
88
tenacity >= 5.0.2
99
aiohttp >=3.9.0; python_version=="3.12"
10-
ansicolors

0 commit comments

Comments
 (0)