Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mathics scanner import #13

Merged
merged 2 commits into from
Jan 23, 2021
Merged
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
7 changes: 4 additions & 3 deletions mathicsscript/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from mathicsscript.format import format_output

from mathics import replace_wl_with_unicode
from mathics.core.parser import FileLineFeeder
from mathics.core.definitions import Definitions
from mathics.core.expression import Symbol, SymbolTrue, SymbolFalse
Expand All @@ -21,6 +20,8 @@
from mathics import version_string, license_string
from mathics import settings

from mathics_scanner.characters import replace_wl_with_plain_text

from pygments import highlight
from pygments.lexers import MathematicaLexer

Expand Down Expand Up @@ -327,7 +328,7 @@ def main(
current_pos = GNU_readline.get_current_history_length()
for pos in range(last_pos, current_pos - 1):
GNU_readline.remove_history_item(pos)
wl_input = replace_wl_with_unicode(source_code.rstrip())
wl_input = replace_wl_with_plain_text(source_code.rstrip(), use_unicode=unicode)
GNU_readline.add_history(wl_input)

if query is None:
Expand All @@ -344,7 +345,7 @@ def main(
query, timeout=settings.TIMEOUT, format="unformatted"
)
if result is not None:
shell.print_result(result, output_style)
shell.print_result(result, output_style, use_unicode=unicode)

except ShellEscapeException as e:
source_code = e.line
Expand Down
2 changes: 1 addition & 1 deletion mathicsscript/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def format_output(obj, expr, format=None):
format = obj.format

if isinstance(format, dict):
return dict((k, obj.format_output(expr, f)) for k, f in format.items())
return {k: obj.format_output(expr, f) for k, f in format.items()}

from mathics.core.expression import Expression, BoxError

Expand Down
13 changes: 9 additions & 4 deletions mathicsscript/termshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import sys
import re
from columnize import columnize
from mathics import replace_unicode_with_wl
from mathics.core.expression import Expression, String, Symbol
from mathics.core.expression import strip_context, from_python
from mathics.core.rules import Rule
from mathics.core.characters import named_characters
from mathics_scanner.characters import (
named_characters,
replace_unicode_with_wl,
replace_wl_with_plain_text,
)

from pygments import highlight, lex
from mathicsscript.mmalexer import MathematicaLexer
Expand Down Expand Up @@ -253,7 +256,7 @@ def read_line(self, prompt):
raise ShellEscapeException(line)
return replace_unicode_with_wl(line)

def print_result(self, result, output_style=""):
def print_result(self, result, output_style="", use_unicode=True):
if result is None:
# FIXME decide what to do here
return
Expand All @@ -267,7 +270,9 @@ def print_result(self, result, output_style=""):
print(sys.exc_info()[1])
return

out_str = str(result.result)
out_str = replace_wl_with_plain_text(str(result.result),
use_unicode=use_unicode)

if eval_type == "System`Graph":
out_str = "-Graph-"
elif self.terminal_formatter: # pygmentize
Expand Down
25 changes: 16 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
import os.path as osp
from setuptools import find_packages

INSTALL_REQUIRES = [
"Mathics-Scanner>=1.0.0dev",
"Mathics3 >= 2.0.0dev",
"click",
"colorama",
"columnize",
"networkx",
"pygments",
"term-background >= 1.0.1",
]

DEPENDENCY_LINKS = [
'http://github.com/Mathics3/mathics-scanner/tarball/master#egg=Mathics-Scanner-1.0.0dev'
]

def get_srcdir():
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
Expand Down Expand Up @@ -66,15 +80,8 @@ def read(*rnames):
package_data={
"": ["inputrc", "inputrc-no-unicode", "inputrc-unicode", "settings/settings.m"]
},
install_requires=[
"Mathics3 >= 2.0.0dev",
"click",
"colorama",
"columnize",
"networkx",
"pygments",
"term-background >= 1.0.1",
],
install_requires=INSTALL_REQUIRES,
dependency_links=DEPENDENCY_LINKS,
entry_points={"console_scripts": ["mathicsscript = mathicsscript.__main__:main"]},
long_description=long_description,
long_description_content_type="text/x-rst",
Expand Down