Skip to content

Commit

Permalink
chore: add format
Browse files Browse the repository at this point in the history
  • Loading branch information
grieve54706 committed Dec 3, 2024
1 parent be6393a commit 213f89b
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 7 deletions.
8 changes: 8 additions & 0 deletions wren-core-py/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ develop:
test: develop
cargo test --no-default-features
poetry run pytest

alias fmt := format

format:
cargo fmt
poetry run ruff format .
poetry run ruff check --fix .
taplo fmt
92 changes: 92 additions & 0 deletions wren-core-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ maturin = "1.7.5"

[tool.poetry.group.dev.dependencies]
pytest = "8.3.3"
ruff = "0.8.0"

[tool.maturin]
module-name = "wren_core"
Expand All @@ -25,3 +26,94 @@ features = ["pyo3/extension-module"]
[build-system]
requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"

[tool.ruff]
line-length = 88
target-version = "py311"
exclude = ["tools/"]

[tool.ruff.lint]
select = [
"C4", # comprehensions
"D", # pydocstyle
"E", # pycodestyle
"EXE", # flake8-executable
"F", # pyflakes
"FA", # flake8-future-annotations
"G", # flake8-logging-format
"FLY", # flynt (format string conversion)
"I", # isort
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420 (implicit namespace packages)
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"RET", # flake8-return
"RUF", # ruff-specific rules
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"YTT", # flake8-2020
]
ignore = [
"B008", # do not perform function calls in argument defaults
"B028", # required stacklevel argument to warn
"B904", # raise from e or raise from None in exception handlers
"B905", # zip-without-explicit-strict
"C408", # dict(...) as literal
"C901", # too complex
"D100", # public module
"D101", # public class
"D102", # public method
"D103", # public function
"D104", # public package
"D105", # magic methods
"D106", # nested class
"D107", # init
"D202", # blank lines after function docstring
"D203", # blank line before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D401", # Imperative mood
"D402", # First line should not be the function's signature
"D413", # Blank line required after last section
"E501", # line-too-long, this is automatically enforced by ruff format
"E731", # lambda-assignment
"ISC001", # single line implicit string concat, handled by ruff format
"PGH003", # blanket-type-ignore
"PLC0105", # covariant type parameters should have a _co suffix
"PLR0124", # name compared with self, e.g., a == a
"PLR0911", # too many return statements
"PLR0912", # too many branches
"PLR0913", # too many arguments
"PLR0915", # too many statements
"PLR2004", # forces everything to be a constant
"PLW2901", # overwriting loop variable
"RET504", # unnecessary-assign, these are useful for debugging
"RET505", # superfluous-else-return, stylistic choice
"RET506", # superfluous-else-raise, stylistic choice
"RET507", # superfluous-else-continue, stylistic choice
"RET508", # superfluous-else-break, stylistic choice
"RUF005", # splat instead of concat
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"S101", # ignore "Use of `assert` detected"
"SIM102", # nested ifs
"SIM108", # convert everything to ternary operator
"SIM114", # combine `if` branches using logical `or` operator
"SIM116", # dictionary instead of `if` statements
"SIM117", # nested with statements
"SIM118", # remove .keys() calls from dictionaries
"SIM300", # yoda conditions
"UP007", # Optional[str] -> str | None
"UP038", # non-pep604-isinstance, results in slower code
"W191", # indentation contains tabs
]
# none of these codes will be automatically fixed by ruff
unfixable = [
"T201", # print statements
"F401", # unused imports
"RUF100", # unused noqa comments
"F841", # unused variables
]
Empty file added wren-core-py/tests/__init__.py
Empty file.
10 changes: 3 additions & 7 deletions wren-core-py/tests/test_modeling_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import pytest
from wren_core import (
SessionContext,
Extractor,
SessionContext,
to_json_base64,
)

Expand Down Expand Up @@ -123,19 +123,15 @@ def test_read_function_list():
def test_get_available_functions():
session_context = SessionContext(manifest_str, "tests/functions.csv")
functions = session_context.get_available_functions()
add_two = next(
filter(lambda x: x["name"] == "add_two", map(lambda x: x.to_dict(), functions))
)
add_two = next(x.to_dict() for x in functions if x["name"] == "add_two")
assert add_two["name"] == "add_two"
assert add_two["function_type"] == "scalar"
assert add_two["description"] == "Adds two numbers together."
assert add_two["return_type"] == "int"
assert add_two["param_names"] == "f1,f2"
assert add_two["param_types"] == "int,int"

max_if = next(
filter(lambda x: x["name"] == "max_if", map(lambda x: x.to_dict(), functions))
)
max_if = next(x.to_dict() for x in functions if x["name"] == "max_if")
assert max_if["name"] == "max_if"
assert max_if["function_type"] == "window"
assert max_if["param_names"] is None
Expand Down

0 comments on commit 213f89b

Please sign in to comment.