-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ANSI on Windows (#31)
* Add support for ANSI on Windows This is a belated replacement for the reverted #24. Improvements this time around: Moved the relevant code into upstream colorama, so it plays nicely with other packages using terminal features on Windows, like tqdm. This also gives us basic ANSI support on any old Windows installs out there that still don't have the native ANSI support. I think they're all EOL already so not a big deal, but it's a free bonus, so why not. Last time, we had to revert due to a bug in handling "fake" consoles like Jupyter notebooks. This time, we're using code that's already been out in the wild for ~1 month with no issues reported, so hopefully there won't be any need for emergency reverts. * Install colorama type stubs to make mypy happy * work around typeshed bug * Test running in jupyter * Fix jupyter test * Windows subprocess requires Path's to be stringified * jupyter install fails on py36, so restrict to py37+ * Better check for jupyter install Avoids making mypy complain about missing jupyter stubs * Make colorama import check more robust * Restore temporary type: ignore so I can test the rest... * Another approach to notebook testing * Remove unnecessary # type: ignore * Maybe this * windows py36 doesn't support ansi * Improve comment
- Loading branch information
Showing
6 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include LICENSE | ||
recursive-include wasabi/tests/test-data *.ipynb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
pytest | ||
typing_extensions | ||
mypy | ||
mypy | ||
types-colorama | ||
nbconvert | ||
ipykernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "eb5586f8", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"import wasabi\n", | ||
"\n", | ||
"wasabi.msg.warn(\"This is a test. This is only a test.\")\n", | ||
"if sys.version_info >= (3, 7):\n", | ||
" assert wasabi.util.supports_ansi()\n", | ||
"\n", | ||
"print(sys.stdout)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from pathlib import Path | ||
import subprocess | ||
import os | ||
import sys | ||
|
||
import wasabi | ||
|
||
TEST_DATA = Path(__file__).absolute().parent / "test-data" | ||
WASABI_DIR = Path(wasabi.__file__).absolute().parent.parent | ||
|
||
|
||
def test_jupyter(): | ||
# This runs some code in a jupyter notebook environment, but without actually | ||
# starting up the notebook UI. Historically we once had a bug that caused crashes | ||
# when importing wasabi in a jupyter notebook, because they replace | ||
# sys.stdout/stderr with custom objects that aren't "real" files/ttys. So this makes | ||
# sure that we can import and use wasabi inside a notebook without crashing. | ||
env = dict(os.environ) | ||
if "PYTHONPATH" in env: | ||
env["PYTHONPATH"] = f"{WASABI_DIR}{os.pathsep}{env['PYTHONPATH']}" | ||
else: | ||
env["PYTHONPATH"] = str(WASABI_DIR) | ||
subprocess.run( | ||
[ | ||
sys.executable, | ||
"-m", | ||
"nbconvert", | ||
str(TEST_DATA / "wasabi-test-notebook.ipynb"), | ||
"--execute", | ||
"--stdout", | ||
"--to", | ||
"notebook", | ||
], | ||
env=env, | ||
check=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters