Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: refresh ci #10

Merged
merged 4 commits into from
Nov 29, 2023
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Build

on:
schedule:
# Every Monday at 1PM UTC (9AM EST)
- cron: "0 13 * * 1"
push:
branches:
- master
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ assert input_exp.evaluate(ctx) == output_exp.evaluate(ctx)
<!-- ### Visualize a Tree -- needs mathy plugin in docs.sh -->
<!-- ### Generate Problems -- needs example snippet -->

## 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.
Expand Down
4 changes: 0 additions & 4 deletions mathy_core/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def clear_classes(self) -> None:
def visit_fn(
node: MathExpression, depth: int, data: Any
) -> Optional[VisitStop]:

node.classes = []
return None

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion mathy_core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class TidierExtreme:

left: Optional[BinaryTreeNode]
right: Optional[BinaryTreeNode]
thread: Optional[BinaryTreeNode]
Expand Down
10 changes: 5 additions & 5 deletions mathy_core/problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
numpy
colr
pydantic>=1.0.0
wasabi
typing_extensions; python_version < "3.7"
1 change: 0 additions & 1 deletion tests/test_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


def test_number_generation() -> None:

random.seed(1337)

# When using pretty number generation, all values
Expand Down
2 changes: 0 additions & 2 deletions tests/test_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


def test_tokenizer_tokenize() -> None:

text = "4x + 2x^3 * 7!"
tokenizer = Tokenizer()
tokens: List[Token] = tokenizer.tokenize(text)
Expand All @@ -18,7 +17,6 @@ def test_tokenizer_tokenize() -> None:


def test_tokenizer_errors() -> None:

text = "4x + 2x^3 * 7\\"
tokenizer = Tokenizer()

Expand Down
1 change: 0 additions & 1 deletion tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/test_tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tools/codecov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -e
. .env/bin/activate
pip install codecov
python -m codecov
python3 -m codecov
2 changes: 1 addition & 1 deletion tools/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tools/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down