diff --git a/.github/workflows/autoblack.yml b/.github/workflows/autoblack.yml new file mode 100644 index 0000000..40d7050 --- /dev/null +++ b/.github/workflows/autoblack.yml @@ -0,0 +1,32 @@ +# GitHub Action that uses Black to reformat the Python code in an incoming pull request. +# If all Python code in the pull request is compliant with Black then this Action does nothing. +# Othewrwise, Black is run and its changes are committed back to the incoming pull request. +# https://github.com/cclauss/autoblack + +name: autoblack +on: [pull_request] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Install click + run: pip install 'click==8.0.4' + - name: Install Black + run: pip install 'black==22.3.0' + - name: Run black --check . + run: black --check . + - name: If needed, commit black changes to the pull request + if: failure() + run: | + black . + git config --global user.name 'autoblack' + git config --global user.email 'rocky@users.noreply.github.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git checkout $GITHUB_HEAD_REF + git commit -am "fixup: Format Python code with Black" + git push diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml new file mode 100644 index 0000000..702cd52 --- /dev/null +++ b/.github/workflows/osx.yml @@ -0,0 +1,34 @@ +name: pymathics-language (macOS) + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: macos-latest + strategy: + matrix: + os: [macOS] + python-version: [3.8, 3.9] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + brew install llvm@11 + python -m pip install --upgrade pip + pip install pytest + # Can remove after next Mathics-core release + python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full] + - name: Install pymathics.language + run: | + pip install -e . + - name: Test Mathics + run: | + make check diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 0000000..63c6fbc --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,32 @@ +name: pymathics-language (ubuntu) + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8','3.9','3.10'] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + # Can remove after next Mathics-core release + python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full] + - name: Install pymathics.language + run: | + pip install -e . + - name: Test Mathics + run: | + make check diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..eb0dff3 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,34 @@ +name: pymathics-language (Windows) + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: windows-latest + strategy: + matrix: + os: [windows] + python-version: [ 3.8, 3.9] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install wheel + pip install pytest + # Can remove after next Mathics-core release + python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full] + - name: Install pymathics.language + run: | + pip install -e . + - name: Test Mathics + run: | + make check diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bc792d3 --- /dev/null +++ b/Makefile @@ -0,0 +1,81 @@ +# A GNU Makefile to run various tasks - compatibility for us old-timers. + +# Note: This makefile include remake-style target comments. +# These comments before the targets start with #: +# remake --tasks to shows the targets and the comments + +GIT2CL ?= admin-tools/git2cl +PYTHON ?= python +PIP ?= $(PYTHON) -m pip +RM ?= rm + + +.PHONY: all build \ + check clean \ + develop dist doc doc-data \ + pypi-setup \ + pytest \ + rmChangeLog \ + test + +#: Default target - same as "develop" +all: develop + +#: build everything needed to install +build: pypi-setup + $(PYTHON) ./setup.py build + +#: Check Python version, and install PyPI dependencies +pypi-setup: + $(PIP) install -e . + +#: Set up to run from the source tree +develop: pypi-setup + +#: Make distirbution: wheels, eggs, tarball +dist: + ./admin-tools/make-dist.sh + +#: Install pymathics.graph +install: pypi-setup + $(PYTHON) setup.py install + +# Run tests +test check: pytest doctest + +#: Remove derived files +clean: clean-pyc + +#: Remove old PYC files +clean-pyc: + @find . -name "*.pyc" -type f -delete + +#: Run py.test tests. Use environment variable "o" for pytest options +pytest: + MATHICS_CHARACTER_ENCODING="ASCII" $(PYTHON) -m pytest $(PYTEST_WORKERS) test $o + + +# #: Create data that is used to in Django docs and to build TeX PDF +# doc-data mathics/doc/tex/data: mathics/builtin/*.py mathics/doc/documentation/*.mdoc mathics/doc/documentation/images/* +# $(PYTHON) mathics/test.py -ot -k + +#: Run tests that appear in docstring in the code. +doctest: + MATHICS_CHARACTER_ENCODING="ASCII" $(PYTHON) -m mathics.docpipeline -l pymathics.language -c "Pymathics Language" $o + +# #: Make Mathics PDF manual +# doc mathics.pdf: mathics/doc/tex/data +# (cd mathics/doc/tex && $(MAKE) mathics.pdf) + +#: Remove ChangeLog +rmChangeLog: + $(RM) ChangeLog || true + +#: Create a ChangeLog from git via git log and git2cl +ChangeLog: rmChangeLog + git log --pretty --numstat --summary | $(GIT2CL) >$@ + + +#: Run pytest consistency and style checks +check-consistency-and-style: + MATHICS_LINT=t $(PYTHON) -m pytest test/consistency-and-style diff --git a/pymathics/language/__main__.py b/pymathics/language/__main__.py index 810200b..062c92a 100644 --- a/pymathics/language/__main__.py +++ b/pymathics/language/__main__.py @@ -12,8 +12,8 @@ from icu import Locale, LocaleData from typing import List, Optional -from mathics.builtin.base import Builtin from mathics.core.atoms import String +from mathics.core.builtin import Builtin from mathics.core.convert.expression import to_mathics_list availableLocales = Locale.getAvailableLocales() @@ -70,7 +70,7 @@ class Alphabet(Builtin): summary_text = "lowercase letters in an alphabet" - def apply(self, alpha: String, evaluation): + def eval(self, alpha: String, evaluation): """Alphabet[alpha_String]""" alphabet_list = eval_alphabet(alpha) if alphabet_list is None: diff --git a/pymathics/language/version.py b/pymathics/language/version.py index bf28bad..cc1f721 100644 --- a/pymathics/language/version.py +++ b/pymathics/language/version.py @@ -5,4 +5,4 @@ # well as importing into Python. That's why there is no # space around "=" below. # fmt: off -__version__="5.0.0" # noqa +__version__="7.0.0" # noqa diff --git a/setup.py b/setup.py index f6e01b7..e014d24 100644 --- a/setup.py +++ b/setup.py @@ -8,8 +8,8 @@ from setuptools import setup, find_namespace_packages # Ensure user has the correct Python version -if sys.version_info < (3, 6): - print("Mathics support Python 3.6 and above; you have %d.%d" % sys.version_info[:2]) +if sys.version_info < (3, 8): + print("Mathics support Python 3.8 and above; you have %d.%d" % sys.version_info[:2]) sys.exit(-1) @@ -35,7 +35,7 @@ def read(*rnames): version=__version__, packages=find_namespace_packages(include=["pymathics.*"]), install_requires=[ - "Mathics3 >= 5.0.0.dev0,<5.1.0", + "Mathics3 >= 7.0.0.dev", "PyICU>=2.9", ], zip_safe=False, diff --git a/test/test_language.py b/test/test_language.py new file mode 100644 index 0000000..785e0c8 --- /dev/null +++ b/test/test_language.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +from mathics.core.load_builtin import import_and_load_builtins +from mathics.session import MathicsSession + +import_and_load_builtins() + +session = MathicsSession(character_encoding="ASCII") + + +def check_evaluation(str_expr: str, expected: str, message=""): + """Helper function to test that a Mathics expression against + its results""" + result = session.evaluate(str_expr).value + + if message: + assert result == expected, f"{message}: got: {result}" + else: + assert result == expected + + +def test_hello(): + session.evaluate('LoadModule["pymathics.language"]') == "pymathics.language" + check_evaluation('Alphabet["es"]//Length', 33)