Skip to content
New issue

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

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

Already on GitHub? # to your account

compatibility with Mathics 7 #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions .github/workflows/autoblack.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -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
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions pymathics/language/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pymathics/language/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions test/test_language.py
Original file line number Diff line number Diff line change
@@ -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)
Loading