Skip to content

Commit

Permalink
Merge pull request #150 from oscarbenjamin/pr_ruff_format
Browse files Browse the repository at this point in the history
Use ruff instead of black for formatting
  • Loading branch information
oscarbenjamin authored Nov 6, 2024
2 parents 0886e71 + b317403 commit 7b1a44f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 40 deletions.
21 changes: 7 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
repos:
- repo: local
hooks:
- id: ruff
name: Run ruff on Python files
entry: ruff --fix
- id: ruff-lint
name: Run ruff lint on Python files
entry: ruff check --select=I --fix
language: python
types: [python]
- id: black
name: black
entry: black
language: system
- id: ruff-format
name: Run ruff format on Python files
entry: ruff format
language: python
types: [python]
require_serial: true
- id: check-toml
name: Check Toml
entry: check-toml
Expand All @@ -22,12 +21,6 @@ repos:
entry: check-yaml
language: system
types: [yaml]
- id: trailing-whitespace
name: Trim Trailing Whitespace
entry: trailing-whitespace-fixer
language: system
types: [text]
stages: [commit, push, manual]
- id: check-added-large-files
name: Check for added large files
entry: check-added-large-files
Expand Down
1 change: 1 addition & 0 deletions benchmarks/test_differentiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest
import symengine
import sympy

from protosym import simplecas

ExprType = TypeVar("ExprType")
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ pyright-check = "pyright {args:src tests}"
[tool.hatch.envs.pre-commit]
dependencies = [
"ruff",
"black",
"pre-commit",
"pre-commit-hooks",
]
Expand Down Expand Up @@ -141,7 +140,7 @@ extend-ignore = [
"RUF005", # list concatenation
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D100", "D104", "PLR2004", "PLR0124"]

[tool.ruff.lint.pydocstyle]
Expand Down
2 changes: 1 addition & 1 deletion src/protosym/simplecas/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
# ------------------------------------------------------------------------- #

latex_add = PyOpN(lambda args: f'({" + ".join(args)})')
latex_mul = PyOpN(lambda args: "(%s)" % r" \times ".join(args))
latex_mul = PyOpN(lambda args: "(" + r" \times ".join(args) + ")")
latex_pow = PyOp2(lambda b, e: f"{b}^{{{e}}}")
latex_sin = PyOp1(lambda a: rf"\sin({a})")
latex_cos = PyOp1(lambda a: rf"\cos({a})")
Expand Down
3 changes: 2 additions & 1 deletion tests/core/test_evaluate.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import math
from typing import Callable

from pytest import raises

from protosym.core.atom import AtomType
from protosym.core.evaluate import Evaluator, Transformer
from protosym.core.exceptions import NoEvaluationRuleError
from protosym.core.tree import Tr, Tree, funcs_symbols
from pytest import raises


def test_Evaluator() -> None:
Expand Down
31 changes: 17 additions & 14 deletions tests/core/test_sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import math
from typing import Any

from pytest import approx, raises

from protosym.core.exceptions import BadRuleError
from protosym.core.sym import (
AtomFunc,
Expand All @@ -20,7 +22,6 @@
star,
)
from protosym.core.tree import Tree
from pytest import approx, raises


class Expr(Sym):
Expand All @@ -41,17 +42,19 @@ def __call__(self, *args: Expr) -> Expr:
return Expr(self.rep(*args_rep))


def _make_atoms() -> tuple[
SymAtomType[Expr, int],
SymAtomType[Expr, str],
Expr,
Expr,
Expr,
Expr,
Expr,
Expr,
Expr,
]:
def _make_atoms() -> (
tuple[
SymAtomType[Expr, int],
SymAtomType[Expr, str],
Expr,
Expr,
Expr,
Expr,
Expr,
Expr,
Expr,
]
):
"""Set up a Sym subclass and create some atoms etc."""
Integer = Expr.new_atom("Integer", int)
Function = Expr.new_atom("Function", str)
Expand Down Expand Up @@ -105,15 +108,15 @@ def test_Sym_types() -> None:
assert type(cos) is Expr
assert type(Add) is Expr
assert type(cos.rep) is Tree
assert type(a) == type(b) == Expr
assert type(a) is type(b) is Expr


def test_Sym_evaluator() -> None:
"""Test creating a str-evaluator for Sym."""
Integer, Function, cos, sin, Add, one, a, b, x = _make_atoms()

to_str = Expr.new_evaluator("to_str", str)
assert type(to_str) == SymEvaluator
assert type(to_str) is SymEvaluator
assert repr(to_str) == repr(to_str) == "to_str"

to_str[Integer[a]] = PyFunc1[int, str](str)(a)
Expand Down
3 changes: 2 additions & 1 deletion tests/core/test_tree.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pytest import raises

from protosym.core.atom import Atom, AtomType
from protosym.core.tree import (
ForwardGraph,
Expand All @@ -9,7 +11,6 @@
topological_sort,
topological_split,
)
from pytest import raises


def test_Tree_basic() -> None:
Expand Down
13 changes: 7 additions & 6 deletions tests/test_simplecas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pytest import raises, skip

from protosym.core.sym import SymAtomType
from protosym.simplecas import (
Add,
Expand Down Expand Up @@ -25,7 +27,6 @@
zero,
)
from protosym.simplecas.exceptions import ExpressifyError, LLVMNotImplementedError
from pytest import raises, skip

from .utils import requires_llvmlite, requires_numpy

Expand All @@ -34,11 +35,11 @@

def test_simplecas_types() -> None:
"""Basic tests for type of Expr."""
assert type(x) == Expr
assert type(Mul) == Expr
assert type(Integer) == SymAtomType
assert type(Integer(1)) == Expr
assert type(Mul(x, Integer(1))) == Expr
assert type(x) is Expr
assert type(Mul) is Expr
assert type(Integer) is SymAtomType
assert type(Integer(1)) is Expr
assert type(Mul(x, Integer(1))) is Expr
raises(TypeError, lambda: Expr([])) # type: ignore


Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def wrapper(*args: Any, **kwargs: Any) -> None:
try:
__import__(module_name)
except ImportError:
pytest.skip("requires %s" % module_name)
pytest.skip(f"Requires {module_name}")
return func(*args, **kwargs)

return wrapper
Expand Down

0 comments on commit 7b1a44f

Please sign in to comment.