From f0e4d2802d058eaa6c33d48e4e340f2f594e64f1 Mon Sep 17 00:00:00 2001 From: Tiago Cavalcante Trindade Date: Tue, 22 Jun 2021 14:03:42 -0300 Subject: [PATCH 1/4] Add System`$Notebooks test --- test/test_settings.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/test_settings.py b/test/test_settings.py index 87639a7..17ae700 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- from .helper import session +import os.path as osp + +from mathics.core.definitions import autoload_files, Definitions def test_settings(): - # FIXME: this is a start, but we should do more for setting in ( "Settings`$ShowFullFormInput::usage", "Settings`$ShowFullFormInput", @@ -13,5 +15,21 @@ def test_settings(): "Settings`$UseUnicode::usage", "Settings`$UseUnicode", "Settings`MathicsScriptVersion::usage", + "System`$Notebooks", + "System`$Notebooks::usage", ): assert session.evaluate(setting), setting + +def test_is_not_notebook(): + import os.path as osp + from mathics.core.definitions import autoload_files + + root_dir = osp.realpath(osp.join( + osp.dirname(osp.abspath(__file__)), + "..", + "mathicsscript", + )) + + autoload_files(session.definitions, root_dir, "autoload") + + assert session.evaluate("System`$Notebooks").to_python() == False From 6cb239a1d635d1c1c2cf21df649faf4ac68a379e Mon Sep 17 00:00:00 2001 From: Tiago Cavalcante Trindade Date: Tue, 22 Jun 2021 19:56:40 -0300 Subject: [PATCH 2/4] Improve test_settings --- test/test_settings.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/test/test_settings.py b/test/test_settings.py index 17ae700..6f389cc 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -6,30 +6,32 @@ from mathics.core.definitions import autoload_files, Definitions def test_settings(): - for setting in ( - "Settings`$ShowFullFormInput::usage", - "Settings`$ShowFullFormInput", - "Settings`$PygmentsStyle::usage", - "Settings`$PygmentsShowTokens::usage", - "Settings`$PygmentsShowTokens", - "Settings`$UseUnicode::usage", - "Settings`$UseUnicode", - "Settings`MathicsScriptVersion::usage", - "System`$Notebooks", - "System`$Notebooks::usage", - ): - assert session.evaluate(setting), setting - -def test_is_not_notebook(): import os.path as osp from mathics.core.definitions import autoload_files + import mathicsscript - root_dir = osp.realpath(osp.join( - osp.dirname(osp.abspath(__file__)), - "..", - "mathicsscript", - )) + root_dir = osp.realpath( + osp.dirname(mathicsscript.__file__), + ) autoload_files(session.definitions, root_dir, "autoload") + assert session.evaluate("Settings`$ShowFullFormInput::usage").to_python() != "Settings`$ShowFullFormInput::usage" + + assert type(session.evaluate("Settings`$ShowFullFormInput").to_python()) is bool + + assert session.evaluate("Settings`$PygmentsStyle::usage").to_python() != "Settings`$PygmentsStyle::usage" + + assert session.evaluate("Settings`$PygmentsShowTokens::usage").to_python() != "Settings`$PygmentsShowTokens::usage" + + assert type(session.evaluate("Settings`$PygmentsShowTokens").to_python()) is bool + + assert session.evaluate("Settings`$UseUnicode::usage").to_python() != "Settings`$UseUnicode::usage" + + assert type(session.evaluate("Settings`$UseUnicode").to_python()) is bool + + assert session.evaluate("Settings`MathicsScriptVersion::usage").to_python() != "Settings`MathicsScriptVersion::usage" + +def test_is_not_notebook(): + # the settings already were loaded assert session.evaluate("System`$Notebooks").to_python() == False From f9db6f223d784c724a38c8f5b8d9f9c8b679c190 Mon Sep 17 00:00:00 2001 From: Tiago Cavalcante Trindade Date: Wed, 23 Jun 2021 11:08:50 -0300 Subject: [PATCH 3/4] Add load_default_settings_files function --- mathicsscript/__init__.py | 12 ++++++++++++ test/test_settings.py | 39 +++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/mathicsscript/__init__.py b/mathicsscript/__init__.py index 1f73734..f6813b1 100644 --- a/mathicsscript/__init__.py +++ b/mathicsscript/__init__.py @@ -5,3 +5,15 @@ Copyright 2020-2021 The Mathics Team """ from mathicsscript.version import __version__ + + +def load_default_settings_files(definitions): + import os.path as osp + from mathics.core.definitions import autoload_files + + root_dir = osp.realpath(osp.dirname(__file__)) + + autoload_files(definitions, root_dir, "autoload") + + +__all__ = [__version__, load_default_settings_files] diff --git a/test/test_settings.py b/test/test_settings.py index 6f389cc..d32c05f 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -1,37 +1,44 @@ # -*- coding: utf-8 -*- from .helper import session -import os.path as osp +from mathicsscript import load_default_settings_files -from mathics.core.definitions import autoload_files, Definitions def test_settings(): - import os.path as osp - from mathics.core.definitions import autoload_files - import mathicsscript + load_default_settings_files(session.definitions) - root_dir = osp.realpath( - osp.dirname(mathicsscript.__file__), + assert ( + session.evaluate("Settings`$ShowFullFormInput::usage").to_python() + != "Settings`$ShowFullFormInput::usage" ) - autoload_files(session.definitions, root_dir, "autoload") - - assert session.evaluate("Settings`$ShowFullFormInput::usage").to_python() != "Settings`$ShowFullFormInput::usage" - assert type(session.evaluate("Settings`$ShowFullFormInput").to_python()) is bool - assert session.evaluate("Settings`$PygmentsStyle::usage").to_python() != "Settings`$PygmentsStyle::usage" + assert ( + session.evaluate("Settings`$PygmentsStyle::usage").to_python() + != "Settings`$PygmentsStyle::usage" + ) - assert session.evaluate("Settings`$PygmentsShowTokens::usage").to_python() != "Settings`$PygmentsShowTokens::usage" + assert ( + session.evaluate("Settings`$PygmentsShowTokens::usage").to_python() + != "Settings`$PygmentsShowTokens::usage" + ) assert type(session.evaluate("Settings`$PygmentsShowTokens").to_python()) is bool - assert session.evaluate("Settings`$UseUnicode::usage").to_python() != "Settings`$UseUnicode::usage" + assert ( + session.evaluate("Settings`$UseUnicode::usage").to_python() + != "Settings`$UseUnicode::usage" + ) assert type(session.evaluate("Settings`$UseUnicode").to_python()) is bool - assert session.evaluate("Settings`MathicsScriptVersion::usage").to_python() != "Settings`MathicsScriptVersion::usage" + assert ( + session.evaluate("Settings`MathicsScriptVersion::usage").to_python() + != "Settings`MathicsScriptVersion::usage" + ) + def test_is_not_notebook(): - # the settings already were loaded + # the settings already were loaded assert session.evaluate("System`$Notebooks").to_python() == False From 99a0bf7a8fe447cbbba0d3cd8fef8abf807790a9 Mon Sep 17 00:00:00 2001 From: Tiago Cavalcante Trindade Date: Wed, 23 Jun 2021 11:09:49 -0300 Subject: [PATCH 4/4] Autoformat files --- mathicsscript/completion.py | 2 +- rst2html.py | 45 +++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/mathicsscript/completion.py b/mathicsscript/completion.py index f8612aa..d77d1a1 100644 --- a/mathicsscript/completion.py +++ b/mathicsscript/completion.py @@ -103,7 +103,7 @@ def get_completions( words = [] def word_matches(word: str) -> bool: - """ True when the word before the cursor matches. """ + """True when the word before the cursor matches.""" if self.match_middle: return word_before_cursor in word diff --git a/rst2html.py b/rst2html.py index 9d07e82..6b25b3f 100755 --- a/rst2html.py +++ b/rst2html.py @@ -11,6 +11,7 @@ import re + def yield_sphinx_only_markup(lines): """ :param file_inp: a `filename` or ``sys.stdin``? @@ -18,45 +19,39 @@ def yield_sphinx_only_markup(lines): """ substs = [ - ## Selected Sphinx-only Roles. + # Selected Sphinx-only Roles. # - (r':abbr:`([^`]+)`', r'\1'), - (r':ref:`([^`]+)`', r'`\1`_'), - (r':term:`([^`]+)`', r'**\1**'), - (r':dfn:`([^`]+)`', r'**\1**'), - (r':(samp|guilabel|menuselection):`([^`]+)`', r'``\2``'), - - - ## Sphinx-only roles: + (r":abbr:`([^`]+)`", r"\1"), + (r":ref:`([^`]+)`", r"`\1`_"), + (r":term:`([^`]+)`", r"**\1**"), + (r":dfn:`([^`]+)`", r"**\1**"), + (r":(samp|guilabel|menuselection):`([^`]+)`", r"``\2``"), + # Sphinx-only roles: # :foo:`bar` --> foo(``bar``) # :a:foo:`bar` XXX afoo(``bar``) # - #(r'(:(\w+))?:(\w+):`([^`]*)`', r'\2\3(``\4``)'), - (r':(\w+):`([^`]*)`', r'\1(``\2``)'), - - - ## Sphinx-only Directives. + # (r'(:(\w+))?:(\w+):`([^`]*)`', r'\2\3(``\4``)'), + (r":(\w+):`([^`]*)`", r"\1(``\2``)"), + # Sphinx-only Directives. # - (r'\.\. doctest', r'code-block'), - (r'\.\. plot::', r'.. '), - (r'\.\. seealso', r'info'), - (r'\.\. glossary', r'rubric'), - (r'\.\. figure::', r'.. '), - - - ## Other + (r"\.\. doctest", r"code-block"), + (r"\.\. plot::", r".. "), + (r"\.\. seealso", r"info"), + (r"\.\. glossary", r"rubric"), + (r"\.\. figure::", r".. "), + # Other # - (r'\|version\|', r'x.x.x'), + (r"\|version\|", r"x.x.x"), ] - regex_subs = [ (re.compile(regex, re.IGNORECASE), sub) for (regex, sub) in substs ] + regex_subs = [(re.compile(regex, re.IGNORECASE), sub) for (regex, sub) in substs] def clean_line(line): try: for (regex, sub) in regex_subs: line = regex.sub(sub, line) except Exception as ex: - print("ERROR: %s, (line(%s)"%(regex, sub)) + print("ERROR: %s, (line(%s)" % (regex, sub)) raise ex return line