Skip to content
Merged
45 changes: 45 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Mathics (Windows)

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

jobs:
build:
runs-on: windows-latest
strategy:
matrix:
os: [windows]
python-version: [3.7, 3.8]
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
python -m pip install wheel
choco install llvm
set LLVM_DIR="C:\Program Files\LLVM"
pip install llvmlite
pip install numpy
pip install sympy
pip install pillow
pip install scikit-image
pip install requests
pip install wordcloud
pip install PyYAML
pip install palettable
pip install mpmath
pip install mathics_scanner
- name: Install Mathics
run: |
python setup.py install
- name: Test Mathics
run: |
pip install pytest
py.test test
26 changes: 20 additions & 6 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
CHANGES
=======

New builtins
2.1.0
-----

New builtins
++++++++++++++

* ``ByteArray``
* ``FileNames``
* ``CreateFile``
* ``CreateTemporary``


Enhancements
++++++++++++
ByteArray
FileNames
CreateFile
CreateTemporary

* ``FileNameJoin`` - implement ``OperatingSystem`` option

Miscellanea
+++++++++++

A pass was made to improve Microsof Windows compatability and testin
Windows under MSYS.

2.0.0
-----
Expand Down Expand Up @@ -88,7 +102,7 @@ Numerous bugs were fixed while working on Combinatorica V0.9 and CellsToTeX.
Document updates
++++++++++++++++

- Start a readthedocs `Developer Guide <https://mathics-development-guide.readthedocs.io/en/latest/>`_
- Start a readthedocs `Developer Guide <https://mathics-development-guide.reandthedocs.io/en/latest/>`_

Enhancements and bug fixes:
+++++++++++++++++++++++++++
Expand Down
114 changes: 58 additions & 56 deletions mathics/builtin/datentime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
Date and Time
"""

import time
from datetime import datetime, timedelta
import dateutil.parser
import re
import sys
import time

from mathics.version import __version__ # noqa used in loading to check consistency.

Expand Down Expand Up @@ -126,62 +127,63 @@ def apply(self, evaluation):
return SymbolInfinity


class TimeConstrained(Builtin):
"""
<dl>
<dt>'TimeConstrained[$expr$, $t$]'
<dd>'evaluates $expr$, stopping after $t$ seconds.'
<dt>'TimeConstrained[$expr$, $t$, $failexpr$]'
<dd>'returns $failexpr$ if the time constraint is not met.'
</dl>
>> TimeConstrained[Integrate[Sin[x]^1000000,x],1]
= $Aborted

>> TimeConstrained[Integrate[Sin[x]^1000000,x], 1, Integrate[Cos[x],x]]
= Sin[x]

>> s=TimeConstrained[Integrate[Sin[x] ^ 3, x], a]
: Number of seconds a is not a positive machine-sized number or Infinity.
= TimeConstrained[Integrate[Sin[x] ^ 3, x], a]

>> a=1; s
= -Cos[x] + Cos[x] ^ 3 / 3

Possible issues: for certain time-consuming functions (like simplify)
which are based on sympy or other libraries, it is possible that
the evaluation continues after the timeout. However, at the end of the evaluation, the function will return $\\$Aborted$ and the results will not affect
the state of the mathics kernel.

"""

attributes = ('HoldAll',)
messages = {
'timc': 'Number of seconds `1` is not a positive machine-sized number or Infinity.',
}

def apply_2(self, expr, t, evaluation):
'TimeConstrained[expr_, t_]'
return self.apply_3(expr, t, SymbolAborted, evaluation)

def apply_3(self, expr, t, failexpr, evaluation):
'TimeConstrained[expr_, t_, failexpr_]'
t = t.evaluate(evaluation)
if not t.is_numeric():
evaluation.message('TimeConstrained', 'timc', t)
return
try:
t = float(t.to_python())
evaluation.timeout_queue.append((t, datetime.now().timestamp()))
request = lambda : expr.evaluate(evaluation)
res = run_with_timeout_and_stack(request, t, evaluation)
except TimeoutInterrupt:
evaluation.timeout_queue.pop()
return failexpr.evaluate(evaluation)
except:
if sys.platform != "win32":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is TimeConstrained what is failing? or is the expression we have chosen to test it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the implementation is Unix/POSIX specific. I haven't investigated though.

class TimeConstrained(Builtin):
"""
<dl>
<dt>'TimeConstrained[$expr$, $t$]'
<dd>'evaluates $expr$, stopping after $t$ seconds.'
<dt>'TimeConstrained[$expr$, $t$, $failexpr$]'
<dd>'returns $failexpr$ if the time constraint is not met.'
</dl>
>> TimeConstrained[Integrate[Sin[x]^1000000,x],1]
= $Aborted

>> TimeConstrained[Integrate[Sin[x]^1000000,x], 1, Integrate[Cos[x],x]]
= Sin[x]

>> s=TimeConstrained[Integrate[Sin[x] ^ 3, x], a]
: Number of seconds a is not a positive machine-sized number or Infinity.
= TimeConstrained[Integrate[Sin[x] ^ 3, x], a]

>> a=1; s
= -Cos[x] + Cos[x] ^ 3 / 3

Possible issues: for certain time-consuming functions (like simplify)
which are based on sympy or other libraries, it is possible that
the evaluation continues after the timeout. However, at the end of the evaluation, the function will return $\\$Aborted$ and the results will not affect
the state of the mathics kernel.

"""

attributes = ('HoldAll',)
messages = {
'timc': 'Number of seconds `1` is not a positive machine-sized number or Infinity.',
}

def apply_2(self, expr, t, evaluation):
'TimeConstrained[expr_, t_]'
return self.apply_3(expr, t, SymbolAborted, evaluation)

def apply_3(self, expr, t, failexpr, evaluation):
'TimeConstrained[expr_, t_, failexpr_]'
t = t.evaluate(evaluation)
if not t.is_numeric():
evaluation.message('TimeConstrained', 'timc', t)
return
try:
t = float(t.to_python())
evaluation.timeout_queue.append((t, datetime.now().timestamp()))
request = lambda : expr.evaluate(evaluation)
res = run_with_timeout_and_stack(request, t, evaluation)
except TimeoutInterrupt:
evaluation.timeout_queue.pop()
return failexpr.evaluate(evaluation)
except:
evaluation.timeout_queue.pop()
raise
evaluation.timeout_queue.pop()
raise
evaluation.timeout_queue.pop()
return res
return res


class Timing(Builtin):
Expand Down
Loading