Skip to content

Commit

Permalink
Increase version information...
Browse files Browse the repository at this point in the history
Add matplotlib and asymptote versions
  • Loading branch information
rocky committed Jul 17, 2022
1 parent dee2341 commit b4b6e30
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
48 changes: 36 additions & 12 deletions mathicsscript/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import click
import os
import os.path as osp
import subprocess
import sys

from pathlib import Path
from pygments import highlight

import click
from mathics.core.attributes import attribute_string_to_number
from pygments import highlight

from mathics import license_string, settings, version_info
from mathics.core.definitions import autoload_files
from mathics.core.evaluation import Evaluation, Output
from mathics.core.expression import from_python
from mathics.core.parser import MathicsFileLineFeeder
from mathics.core.symbols import Symbol, SymbolFalse, SymbolTrue

from mathics_scanner import replace_wl_with_plain_text

from mathicsscript.asymptote import asymptote_version
from mathicsscript.termshell import ShellEscapeException, mma_lexer
from mathicsscript.termshell_gnu import TerminalShellGNUReadline
from mathicsscript.termshell_prompt import TerminalShellPromptToolKit
Expand All @@ -24,17 +34,31 @@
readline_choices = ["GNU", "Prompt", "None"]
have_readline = True

from mathicsscript.format import format_output

from mathics.core.symbols import Symbol, SymbolTrue, SymbolFalse
from mathics.core.definitions import autoload_files
from mathics.core.evaluation import Evaluation, Output
from mathics.core.expression import from_python
from mathics.core.parser import MathicsFileLineFeeder
from mathics import version_string, license_string
from mathics import settings
from mathicsscript.format import format_output, matplotlib_version

from mathics_scanner import replace_wl_with_plain_text
version_string = """Mathics {mathics}
on {python}
Using:
SymPy {sympy}, mpmath {mpmath}, numpy {numpy}
""".format(
**version_info
)


if "cython" in version_info:
version_string += f"cython {version_info['cython']}, "

if matplotlib_version is None:
version_string += "\nNo matplotlib installed,"
else:
version_string += f"matplotlib {matplotlib_version},"

if asymptote_version is None:
version_string += "\nNo asymptote installed,"
else:
version_string += f"\n{asymptote_version}"


def get_srcdir():
Expand Down
11 changes: 10 additions & 1 deletion mathicsscript/asymptote.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import os.path as osp

from subprocess import Popen, PIPE
from subprocess import Popen, PIPE, run

asy_program = os.environ.get("ASY_PROG", "asy")

Expand All @@ -17,6 +17,15 @@
with_asymptote_dir = f"""{mathics_asymptote_dir}{os.pathsep}{asymptote_dir}"""
os.environ["ASYMPTOTE_DIR"] = with_asymptote_dir

result = run([asy_program, "--version"], timeout=0.5, capture_output=True)
if result.returncode == 0:
# Use the first line of output only, not all of the enabled options
asymptote_version = result.stderr.decode("utf-8").split("\n")[0]
# Just the name and version, not the copyright and authors
asymptote_version = asymptote_version.split("[")[0].strip()
else:
asymptote_version = None


def get_srcdir():
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
Expand Down
17 changes: 11 additions & 6 deletions mathicsscript/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
)
from mathics.session import get_settings_value

try:
from matplotlib import __version__ as matplotlib_version
except ImportError:
matplotlib_version = None

try:
import matplotlib.pyplot as plt
except ImportError:
Expand Down Expand Up @@ -70,14 +75,14 @@ def eval_boxes(result, fn, obj, **options):
expr_type = expr.get_head_name()
if expr_type == "System`MathMLForm":
format = "xml"
leaves = expr.get_leaves()
if len(leaves) == 1:
expr = leaves[0]
elements = expr.elements
if len(elements) == 1:
expr = elements[0]
elif expr_type == "System`TeXForm":
format = "tex"
leaves = expr.get_leaves()
if len(leaves) == 1:
expr = leaves[0]
elements = expr.elements
if len(elemtns) == 1:
expr = elements[0]
elif expr_type == "System`Image":
if get_settings_value(obj.definitions, "Settings`$UseMatplotlib") and plt:
temp_png = NamedTemporaryFile(
Expand Down
2 changes: 1 addition & 1 deletion mathicsscript/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# well as importing into Python. That's why there is no
# space around "=" below.
# fmt: off
__version__="4.1.0.dev0" # noqa
__version__="5.0.0.dev0" # noqa

0 comments on commit b4b6e30

Please sign in to comment.