diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7e18bf..38090bf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,9 @@ name: Build on: + schedule: + # Every Monday at 1PM UTC (9AM EST) + - cron: "0 13 * * 1" push: branches: - master diff --git a/README.md b/README.md index de0cecd..da24b31 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,22 @@ assert input_exp.evaluate(ctx) == output_exp.evaluate(ctx) +## Development + +Install the prerequisites in a virtual environment (python3 required) + +```bash +sh tools/setup.sh +``` + +Run the test suite and view code-coverage statistics + +```bash +sh tools/test.sh +``` + +The tests cover ~90% of the code so they're a good reference for how to use the various APIs. + ## Semantic Versioning Before Mathy Core reaches v1.0 the project is not guaranteed to have a consistent API, which means that types and classes may move around or be removed. That said, we try to be predictable when it comes to breaking changes, so the project uses semantic versioning to help users avoid breakage. diff --git a/mathy_core/expressions.py b/mathy_core/expressions.py index 881a64f..624b222 100644 --- a/mathy_core/expressions.py +++ b/mathy_core/expressions.py @@ -140,7 +140,6 @@ def clear_classes(self) -> None: def visit_fn( node: MathExpression, depth: int, data: Any ) -> Optional[VisitStop]: - node.classes = [] return None @@ -153,7 +152,6 @@ def to_list(self, visit: str = "preorder") -> List["MathExpression"]: def visit_fn( node: MathExpression, depth: int, data: Any ) -> Optional[VisitStop]: - results.append(node) return None @@ -179,7 +177,6 @@ def find_type(self, instanceType: Type[NodeType]) -> List[NodeType]: def visit_fn( node: MathExpression, depth: int, data: Any ) -> Optional[VisitStop]: - if isinstance(node, instanceType): results.append(node) # type:ignore return None @@ -197,7 +194,6 @@ def find_id(self, id: str) -> Optional["MathExpression"]: def visit_fn( node: MathExpression, depth: int, data: Any ) -> Optional[VisitStop]: - nonlocal result if node.id == id: result = node diff --git a/mathy_core/layout.py b/mathy_core/layout.py index fb88924..af82d1b 100644 --- a/mathy_core/layout.py +++ b/mathy_core/layout.py @@ -4,7 +4,6 @@ class TidierExtreme: - left: Optional[BinaryTreeNode] right: Optional[BinaryTreeNode] thread: Optional[BinaryTreeNode] diff --git a/mathy_core/problems.py b/mathy_core/problems.py index f9b1681..e217764 100644 --- a/mathy_core/problems.py +++ b/mathy_core/problems.py @@ -4,10 +4,9 @@ Utility functions for helping generate input problems. """ import random +from dataclasses import dataclass from typing import Any, List, Optional, Set, Tuple, TypeVar, Union, cast -from pydantic import BaseModel, Field - from .types import NumberType DefaultType = TypeVar("DefaultType", bound=Any) @@ -23,9 +22,10 @@ _pretty_numbers: bool = True -class MathyTermTemplate(BaseModel): - variable: Optional[str] = Field(None, description="the term variable") - exponent: Optional[int] = Field(None, description="the term exponent") +@dataclass +class MathyTermTemplate: + variable: Optional[str] = None # the term variable + exponent: Optional[int | float] = None # the term exponent def make(self) -> str: return mathy_term_string( diff --git a/requirements.txt b/requirements.txt index db974b7..0a6b5fe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ numpy colr -pydantic>=1.0.0 wasabi typing_extensions; python_version < "3.7" \ No newline at end of file diff --git a/tests/test_problems.py b/tests/test_problems.py index 36156aa..02840e2 100644 --- a/tests/test_problems.py +++ b/tests/test_problems.py @@ -12,7 +12,6 @@ def test_number_generation() -> None: - random.seed(1337) # When using pretty number generation, all values diff --git a/tests/test_tokenizer.py b/tests/test_tokenizer.py index d7739cc..faf1f3f 100644 --- a/tests/test_tokenizer.py +++ b/tests/test_tokenizer.py @@ -6,7 +6,6 @@ def test_tokenizer_tokenize() -> None: - text = "4x + 2x^3 * 7!" tokenizer = Tokenizer() tokens: List[Token] = tokenizer.tokenize(text) @@ -18,7 +17,6 @@ def test_tokenizer_tokenize() -> None: def test_tokenizer_errors() -> None: - text = "4x + 2x^3 * 7\\" tokenizer = Tokenizer() diff --git a/tests/test_tree.py b/tests/test_tree.py index c80b0c8..5cb982a 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -55,7 +55,6 @@ def node_visit(node, depth, data): def test_tree_node_is_leaf(): - """check that the known extremes of a tree are reported as leaf nodes and that all other known non - extremes are not.""" tree = BinarySearchTree(0) diff --git a/tests/test_tree_node.py b/tests/test_tree_node.py index 3eea1e3..090f0bc 100644 --- a/tests/test_tree_node.py +++ b/tests/test_tree_node.py @@ -50,7 +50,6 @@ def node_visit(node, depth, data): def test_tree_node_is_leaf(): - """check that the known extremes of a tree are reported as leaf nodes and that all other known non - extremes are not.""" tree = BinarySearchTree(0) diff --git a/tools/build.sh b/tools/build.sh index 9cc3b05..205b45b 100644 --- a/tools/build.sh +++ b/tools/build.sh @@ -3,4 +3,4 @@ set -e . .env/bin/activate echo "Build python package..." -python setup.py sdist bdist_wheel +python3 setup.py sdist bdist_wheel diff --git a/tools/codecov.sh b/tools/codecov.sh index 475134a..bb898f7 100644 --- a/tools/codecov.sh +++ b/tools/codecov.sh @@ -2,4 +2,4 @@ set -e . .env/bin/activate pip install codecov -python -m codecov +python3 -m codecov diff --git a/tools/deploy.sh b/tools/deploy.sh index 9c9c4c1..28b33b3 100644 --- a/tools/deploy.sh +++ b/tools/deploy.sh @@ -10,7 +10,7 @@ echo "--- Install requirements" pip install twine wheel pip install -r requirements.txt echo "--- Buid dists" -python setup.py sdist bdist_wheel +python3 setup.py sdist bdist_wheel echo "--- Upload to PyPi" # NOTE: ignore errors on upload because our CI is dumb and tries to upload # even if the version has already been uploaded. This isn't great, but diff --git a/tools/docs.sh b/tools/docs.sh index 1b4b1d6..a4d1fee 100644 --- a/tools/docs.sh +++ b/tools/docs.sh @@ -2,5 +2,5 @@ set -e . .env/bin/activate mathy_pydoc mathy_core.tokenizer.Tokenizer++ mathy_core.parser++ mathy_core.tree++ mathy_core.expressions++ mathy_core.rules.associative_swap++ mathy_core.rules.balanced_move++ mathy_core.rules.commutative_swap++ mathy_core.rules.constants_simplify++ mathy_core.rules.distributive_factor_out++ mathy_core.rules.distributive_multiply_across++ mathy_core.rules.variable_multiply++ mathy_core.layout++ mathy_core.problems++ > /tmp/pathy_api.md -python tools/docs.py /tmp/pathy_api.md README.md +python3 tools/docs.py /tmp/pathy_api.md README.md npx prettier README.md --write \ No newline at end of file diff --git a/tools/setup.sh b/tools/setup.sh index e4ebc34..e993e8e 100644 --- a/tools/setup.sh +++ b/tools/setup.sh @@ -5,7 +5,7 @@ set -e DIR=.env if [ ! -d "${DIR}" ]; then pip install virtualenv --upgrade - python -m virtualenv .env -p python3 + python3 -m virtualenv .env -p python3 fi . .env/bin/activate