diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 691a7cc..cb8ca43 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [macOS] - python-version: ['3.9', '3.10', '3.11'] + python-version: ['3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -24,12 +24,10 @@ jobs: brew install asymptote python3 -m pip install --upgrade pip # Can comment out when next Mathics core and Mathics-scanner are released - # python3 -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full] - # python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full] - # git clone https://github.com/Mathics3/mathics-core - # (cd mathics-core && pip3 install -e .[full]) - # (cd mathics-core && bash ./admin-tools/make-op-tables.sh) - python -m pip install Mathics3[full] + git clone https://github.com/Mathics3/mathics-scanner + (cd mathics-scanner && pip install -e . && bash ./admin-tools/make-JSON-tables.sh) + git clone https://github.com/Mathics3/mathics-core + (cd mathics-core && bash ./admin-tools/make-JSON-tables.sh && pip install -e .[full]) - name: Install mathicsscript run: | make diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index fd19f71..618f620 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + python-version: ['3.13', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -22,14 +22,11 @@ jobs: run: | sudo apt-get update -qq && sudo apt-get install -qq liblapack-dev llvm-dev asymptote python3 -m pip install --upgrade pip - # Can comment out when next Mathics core and Mathics-scanner are released - # python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full] - # python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full] - # git clone https://github.com/Mathics3/mathics-core - # (cd mathics-core && pip3 install -e .[full]) - # (cd mathics-core && bash ./admin-tools/make-op-tables.sh) - # python -m pip install Mathics3[full] - pip install -e . + # We can comment out when next Mathics core and Mathics-scanner are released + git clone https://github.com/Mathics3/mathics-scanner + (cd mathics-scanner && pip install -e . && bash ./admin-tools/make-JSON-tables.sh) + git clone https://github.com/Mathics3/mathics-core + (cd mathics-core && bash ./admin-tools/make-JSON-tables.sh && pip install -e .[full]) - name: Install mathicsscript run: | make diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 9d7f5ab..8dd73fe 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [windows] - python-version: ['3.10', '3.12'] + python-version: ['3.11', '3.12'] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -24,12 +24,12 @@ jobs: python3 -m pip install --upgrade pip python3 -m pip install wheel set LLVM_DIR="C:\Program Files\LLVM" - # Can comment out when next Mathics core and Mathics-scanner are released - # python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full] - # git clone https://github.com/Mathics3/mathics-core - # bash -c '(cd mathics-core && pip3 install -e .[full])' - # bash -c '(cd mathics-core && bash ./admin-tools/make-op-tables.sh)' - python -m pip install Mathics3[full] + # We can comment out when next Mathics core and Mathics-scanner are released + git clone https://github.com/Mathics3/mathics-scanner + bash -c '(cd mathics-scanner && python -m pip install -e . && bash ./admin-tools/make-JSON-tables.sh)' + git clone https://github.com/Mathics3/mathics-core + bash -c '(cd mathics-core && ./admin-tools/make-JSON-tables.sh && python -m pip install -e .)' + python -m pip install -e . - name: Install mathicsscript run: | make diff --git a/mathicsscript/bindkeys.py b/mathicsscript/bindkeys.py index 5c82aeb..2c8b524 100644 --- a/mathicsscript/bindkeys.py +++ b/mathicsscript/bindkeys.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2021-2022, 2024 Rocky Bernstein +# Copyright (C) 2021-2022, 2024-2025 Rocky Bernstein # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -22,6 +22,8 @@ from prompt_toolkit.enums import EditingMode from prompt_toolkit.key_binding import KeyBindings from prompt_toolkit.filters import Condition +from sys import version_info +import contextlib import pathlib import re @@ -144,7 +146,10 @@ def read_inputrc(read_init_file_fn: Callable, use_unicode: bool) -> None: # GNU Readline inputrc $include's paths are relative to itself, # so chdir to its directory before reading the file. parent_dir = pathlib.Path(__file__).parent.absolute() - with parent_dir: + path_context_fn = ( + parent_dir if version_info < (3, 11) else contextlib.chdir(parent_dir) + ) + with path_context_fn: inputrc = "inputrc-unicode" if use_unicode else "inputrc-no-unicode" try: read_init_file_fn(str(parent_dir / "data" / inputrc)) diff --git a/mathicsscript/termshell.py b/mathicsscript/termshell.py index 7c2a338..538a010 100644 --- a/mathicsscript/termshell.py +++ b/mathicsscript/termshell.py @@ -1,36 +1,35 @@ # -*- coding: utf-8 -*- # Copyright (C) 2020-2022, 2024, 2025 Rocky Bernstein -from columnize import columnize - import locale import os import os.path as osp import pathlib import sys - from typing import Optional -from mathics_pygments.lexer import MathematicaLexer, MToken +import mathics_scanner.location +from colorama import init as colorama_init +from columnize import columnize from mathics.core.atoms import String, Symbol from mathics.core.attributes import attribute_string_to_number -from mathics.core.expression import ( - Expression, - # strip_context, - from_python, -) +from mathics.core.expression import Expression, from_python # strip_context, from mathics.core.rules import Rule from mathics.core.symbols import SymbolNull from mathics.core.systemsymbols import SymbolMessageName +from mathics_scanner.location import ContainerKind from mathics.session import get_settings_value, set_settings_value - +from mathics_pygments.lexer import MathematicaLexer, MToken from pygments import format, highlight, lex -from pygments.formatters.terminal import TERMINAL_COLORS from pygments.formatters import Terminal256Formatter +from pygments.formatters.terminal import TERMINAL_COLORS from pygments.styles import get_all_styles from pygments.util import ClassNotFound +# FIXME: __main__ shouldn't be needed. Fix term_background +from term_background.__main__ import is_dark_background + mma_lexer = MathematicaLexer() ALL_PYGMENTS_STYLES = list(get_all_styles()) @@ -41,11 +40,6 @@ color_scheme[MToken.OPERATOR] = ("magenta", "ansibrightmagenta") color_scheme[MToken.NUMBER] = ("ansiblue", "ansibrightblue") -from colorama import init as colorama_init - -# FIXME: __main__ shouldn't be needed. Fix term_background -from term_background.__main__ import is_dark_background - # Set up mathicsscript configuration directory CONFIGHOME = os.environ.get("XDG_CONFIG_HOME", osp.expanduser("~/.config")) CONFIGDIR = osp.join(CONFIGHOME, "mathicsscript") @@ -86,11 +80,11 @@ def __init__( self, definitions, style: Optional[str], - want_completion: bool, + _: bool, use_unicode: bool, prompt: bool, ): - super().__init__("") + super().__init__([], ContainerKind.STREAM) self.input_encoding = locale.getpreferredencoding() self.lineno = 0 self.terminal_formatter = None @@ -284,6 +278,8 @@ def reset_lineno(self): def feed(self): prompt_str = self.get_in_prompt() if self.prompt else "" result = self.read_line(prompt_str) + "\n" + if mathics_scanner.location.TRACK_LOCATIONS: + self.container.append(self.source_text) if result == "\n": return "" # end of input self.lineno += 1 diff --git a/pyproject.toml b/pyproject.toml index 0118d42..b71f529 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,8 +11,8 @@ build-backend = "setuptools.build_meta" name = "mathicsscript" description = "Command-line interface to Mathics3" dependencies = [ - "Mathics_Scanner>=1.4.1", - "Mathics3 >= 8.0.0", + "Mathics_Scanner>1.4.1", + "Mathics3 >= 8.0.1", "click", "colorama", "columnize", @@ -22,7 +22,7 @@ dependencies = [ "mathics_pygments>=1.0.2", "term-background >= 1.0.1", ] -requires-python = ">=3.8" +requires-python = ">=3.9" readme = "README.rst" license = {text = "GPL-3.0-only"} keywords = ["Mathematica", "Wolfram", "Interpreter", "Shell", "Math", "CAS"] @@ -34,11 +34,11 @@ classifiers = [ "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Programming Language :: Python", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Scientific/Engineering",