##// END OF EJS Templates
Remove the "autoedit_syntax" feature....
Remove the "autoedit_syntax" feature. IPython used to (a long time ago, in a galaxy far far away) have the ability to automatically open an editor in case a wild syntax error appears. The configuration option to enable that was not working for a few years, and apparently we by mistake re enabled it, to discover that the feature is actually broken. So this plainly remove the code to support this feature, at the exception of the `fix_error_editor` hook. Indeed it is public API, so for now as it seem to be used only for this feature, we'll just raise a UserWarning (there is roughly 0 chance of this being tested as it's used mostly interactively, so DeprecationWarnings would be unseen). We'll remove later if no complaints Closes #9603

File last commit:

r21530:6ea81c96
r22576:b7d03ed6
Show More
gen_latex_symbols.py
89 lines | 2.7 KiB | text/x-python | PythonLexer
/ tools / gen_latex_symbols.py
# coding: utf-8
# This script autogenerates `IPython.core.latex_symbols.py`, which contains a
# single dict , named `latex_symbols`. The keys in this dict are latex symbols,
# such as `\\alpha` and the values in the dict are the unicode equivalents for
# those. Most importantly, only unicode symbols that are valid identifers in
# Python 3 are included.
#
# The original mapping of latex symbols to unicode comes from the `latex_symbols.jl` files from Julia.
from __future__ import print_function
import os, sys
if not sys.version_info[0] == 3:
print("This script must be run with Python 3, exiting...")
sys.exit(1)
# Import the Julia LaTeX symbols
print('Importing latex_symbols.js from Julia...')
import requests
url = 'https://raw.githubusercontent.com/JuliaLang/julia/master/base/latex_symbols.jl'
r = requests.get(url)
# Build a list of key, value pairs
print('Building a list of (latex, unicode) key-value pairs...')
lines = r.text.splitlines()[60:]
lines = [line for line in lines if '=>' in line]
lines = [line.replace('=>',':') for line in lines]
def line_to_tuple(line):
"""Convert a single line of the .jl file to a 2-tuple of strings like ("\\alpha", "α")"""
kv = line.split(',')[0].split(':')
# kv = tuple(line.strip(', ').split(':'))
k, v = kv[0].strip(' "'), kv[1].strip(' "')
# if not test_ident(v):
# print(line)
return k, v
assert line_to_tuple(' "\\sqrt" : "\u221A",') == ('\\sqrt', '\u221A')
lines = [line_to_tuple(line) for line in lines]
# Filter out non-valid identifiers
print('Filtering out characters that are not valid Python 3 identifiers')
def test_ident(i):
"""Is the unicode string valid in a Python 3 identifer."""
# Some characters are not valid at the start of a name, but we still want to
# include them. So prefix with 'a', which is valid at the start.
return ('a' + i).isidentifier()
assert test_ident("α")
assert not test_ident('‴')
valid_idents = [line for line in lines if test_ident(line[1])]
# Write the `latex_symbols.py` module in the cwd
s = """# encoding: utf-8
# DO NOT EDIT THIS FILE BY HAND.
# To update this file, run the script /tools/gen_latex_symbols.py using Python 3
# This file is autogenerated from the file:
# https://raw.githubusercontent.com/JuliaLang/julia/master/base/latex_symbols.jl
# This original list is filtered to remove any unicode characters that are not valid
# Python identifiers.
latex_symbols = {\n
"""
for line in valid_idents:
s += ' "%s" : "%s",\n' % (line[0], line[1])
s += "}\n"
s += """
reverse_latex_symbol = { v:k for k,v in latex_symbols.items()}
"""
fn = os.path.join('..','IPython','core','latex_symbols.py')
print("Writing the file: %s" % fn)
with open(fn, 'w', encoding='utf-8') as f:
f.write(s)