Skip to content

Commit

Permalink
Merge branch 'master' into typing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidar committed Oct 26, 2024
2 parents 9176eeb + 2f709d7 commit e2826a6
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 6 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/pyodide.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copied from SymPy https://github.com/sympy/sympy/pull/27183

name: Mathics3 (Pyodide)

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
pyodide-test:
runs-on: ubuntu-latest
env:
PYODIDE_VERSION: 0.27.0a2
# PYTHON_VERSION and EMSCRIPTEN_VERSION are determined by PYODIDE_VERSION.
# The appropriate versions can be found in the Pyodide repodata.json
# "info" field, or in Makefile.envs:
# https://github.com/pyodide/pyodide/blob/main/Makefile.envs#L2
PYTHON_VERSION: 3.12.1
EMSCRIPTEN_VERSION: 3.1.58
NODE_VERSION: 20
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Set up Emscripten toolchain
uses: mymindstorm/setup-emsdk@v14
with:
version: ${{ env.EMSCRIPTEN_VERSION }}
actions-cache-folder: emsdk-cache

- name: Install pyodide-build
run: pip install pyodide-build

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Set up Pyodide virtual environment and run tests
run: |
# Set up Pyodide virtual environment
pyodide xbuildenv install ${{ env.PYODIDE_VERSION }}
pyodide venv .venv-pyodide
# Activate the virtual environment
source .venv-pyodide/bin/activate
pip install "setuptools>=70.0.0" PyYAML click packaging pytest
git clone https://github.com/Mathics3/mathics-scanner.git
cd mathics-scanner/
pip install --no-build-isolation -e .
cd ..
make mathics/data/op-tables.json mathics/data/operator-tables.json
pip install --no-build-isolation -e .
make -j3 check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/.cache
/.gdbinit
/.python-version
/.pyodide-xbuildenv-*
/Mathics.egg-info
/Mathics3.egg-info
ChangeLog
Expand Down
3 changes: 0 additions & 3 deletions mathics/builtin/file_operations/file_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ class SetFileDate(Builtin):
>> SetFileDate[tmpfilename, {2002, 1, 1, 0, 0, 0.}, "Access"];
>> FileDate[tmpfilename, "Access"]
= {2002, 1, 1, 0, 0, 0.}
#> DeleteFile[tmpfilename]
"""

Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/files_io/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ class OpenRead(_OpenAction):
The stream must be closed after using it to release the resource:
>> Close[%];
S> Close[OpenRead["https://raw.githubusercontent.com/Mathics3/mathics-core/master/README.rst"]];
"""

summary_text = "open a file for reading"
Expand Down
20 changes: 20 additions & 0 deletions test/builtin/files_io/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def test_close():
), f"temporary filename {temp_filename} should not appear"


@pytest.mark.skipif(
sys.platform in ("emscripten",),
reason="Pyodide has restricted filesystem access",
)
@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
[
Expand Down Expand Up @@ -147,6 +151,12 @@ def test_close():
"OpenRead[]",
"",
),
(
'Close[OpenRead["https://raw.githubusercontent.com/Mathics3/mathics-core/master/README.rst"]];',
None,
"Null",
"",
),
(
'fd=OpenRead["ExampleData/EinsteinSzilLetter.txt", BinaryFormat -> True, CharacterEncoding->"UTF8"]//Head',
None,
Expand Down Expand Up @@ -314,6 +324,16 @@ def test_close():
),
("FilePrint[pathname]", None, "Null", ""),
("DeleteFile[pathname];Clear[pathname];", None, "Null", ""),
('tmpfilename = $TemporaryDirectory <> "/tmp0";', None, "Null", ""),
("Close[OpenWrite[tmpfilename]];", None, "Null", ""),
(
'SetFileDate[tmpfilename, {2002, 1, 1, 0, 0, 0.}, "Access"];',
None,
"Null",
"",
),
('FileDate[tmpfilename, "Access"]', None, "{2002, 1, 1, 0, 0, 0.}", ""),
("DeleteFile[tmpfilename]", None, "Null", ""),
],
)
def test_private_doctests_files(str_expr, msgs, str_expected, fail_msg):
Expand Down
2 changes: 1 addition & 1 deletion test/builtin/test_datentime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@pytest.mark.skipif(
sys.platform in ("win32",) or hasattr(sys, "pyston_version_info"),
sys.platform in ("win32", "emscripten") or hasattr(sys, "pyston_version_info"),
reason="TimeConstrained needs to be rewritten",
)
def test_timeremaining():
Expand Down
7 changes: 7 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
import os.path as osp
import re
import subprocess
import sys

import pytest


def get_testdir():
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
return osp.realpath(filename)


@pytest.mark.skipif(
sys.platform in ("emscripten",),
reason="Pyodide does not support processes",
)
def test_cli():
script_file = osp.join(get_testdir(), "data", "script.m")

Expand Down
7 changes: 7 additions & 0 deletions test/test_returncode.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# -*- coding: utf-8 -*-
import os.path as osp
import subprocess
import sys

import pytest


def get_testdir():
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
return osp.realpath(filename)


@pytest.mark.skipif(
sys.platform in ("emscripten",),
reason="Pyodide does not support processes",
)
def test_returncode():
assert subprocess.run(["mathics", "-e", "Quit[5]"]).returncode == 5
assert subprocess.run(["mathics", "-e", "1 + 2'"]).returncode == 0
Expand Down

0 comments on commit e2826a6

Please sign in to comment.