diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..e795376f7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yaml] +indent_size = 2 diff --git a/.gitignore b/.gitignore index eefa0cb13..4b1f5e921 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,3 @@ benchmarks/results build docs/build logs -logs/ -__pycache__/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9039b605..3c05ecb80 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,33 +1,20 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: check-merge-conflict - id: debug-statements - id: end-of-file-fixer - id: trailing-whitespace -- repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - args: [--profile, black] -- repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 - hooks: - - id: pyupgrade - args: [--py37-plus] -- repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 -- repo: https://github.com/psf/black - rev: 23.3.0 - hooks: - - id: black - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.2.0 + rev: v1.14.1 hooks: - id: mypy args: [--allow-redefinition] exclude: ^examples/ additional_dependencies: [types-tqdm, types-Pillow] +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.9.1 + hooks: + - id: ruff + args: ["--config=pyproject.toml"] diff --git a/.pydocstyle b/.pydocstyle new file mode 100644 index 000000000..6663458d8 --- /dev/null +++ b/.pydocstyle @@ -0,0 +1,2 @@ +[pydocstyle] +convention = numpy diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..a3a183836 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} diff --git a/outlines/fsm/types.py b/outlines/fsm/types.py index 5695dee07..cdb1d2115 100644 --- a/outlines/fsm/types.py +++ b/outlines/fsm/types.py @@ -39,19 +39,19 @@ def enum_format_fn(sequence: str) -> str: return enum_regex_str, enum_format_fn - if python_type == float: + if python_type is float: def float_format_fn(sequence: str) -> float: return float(sequence) return FLOAT, float_format_fn - elif python_type == int: + elif python_type is int: def int_format_fn(sequence: str) -> int: return int(sequence) return INTEGER, int_format_fn - elif python_type == bool: + elif python_type is bool: def bool_format_fn(sequence: str) -> bool: return bool(sequence) diff --git a/outlines/processors/base_logits_processor.py b/outlines/processors/base_logits_processor.py index 800e69f79..d6fe346e0 100644 --- a/outlines/processors/base_logits_processor.py +++ b/outlines/processors/base_logits_processor.py @@ -136,10 +136,10 @@ def _from_torch(tensor: torch.Tensor, target_type: Type) -> Array: elif target_type == np.ndarray: return tensor.detach().numpy() - elif target_type == list: + elif target_type is list: return tensor.detach().tolist() - elif target_type == tuple: + elif target_type is tuple: return tuple(tensor.detach().tolist()) elif is_mlx_array_type(target_type): diff --git a/pyproject.toml b/pyproject.toml index 0f1683d41..5c45b0e9e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -174,3 +174,10 @@ show_missing = true [tool.diff_cover] compare_branch = "origin/main" diff_range_notation = ".." + +[tool.docformatter] +style = "numpy" +in-place = true + +[tool.ruff.lint] +ignore = [ "E731", "F401" ]