Skip to content

Commit

Permalink
uses ruff for linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MArpogaus committed Jan 29, 2024
1 parent d8587a6 commit 08d3f43
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
24 changes: 7 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/timothycrosley/isort
rev: 5.13.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: isort
args: [--profile, black]
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down
42 changes: 26 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,39 @@ urls = {documentation = 'https://zuko.readthedocs.io', source = 'https://github.

[project.optional-dependencies]
develop = [
'autoflake',
'black',
'isort',
'pre-commit',
'pytest',
'python-lsp-black',
'python-lsp-ruff',
'python-lsp-server[all]',
'ipykernel',
'tox'
'ruff'
]

[tool.autoflake]
expand-star-imports = true
ignore-init-module-imports = true
remove-all-unused-imports = true
remove-unused-variables = true
[tool.ruff]
indent-width = 4
# Same as Black.
line-length = 88
# Assume Python 3.8
target-version = "py38"

[tool.black]
# line-length = 88
target-version = ['py38']
[tool.ruff.format]
# Like Black, indent with spaces, rather than tabs.
indent-style = "space"
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
# Like Black, use double quotes for strings.
quote-style = "double"
# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

[tool.isort]
profile = 'black'
[tool.ruff.lint]
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
ignore = ["E501"]
# Enable Pyflakes (`F`) and the pycodestyle (`E`) codes
select = ["E", "F"]
unfixable = []

[tool.setuptools.dynamic]
dependencies = {file = 'requirements.txt'}
Expand Down
2 changes: 1 addition & 1 deletion zuko/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class LayerNorm(nn.Module):
def __init__(self, dim: Union[int, Iterable[int]] = -1, eps: float = 1e-5):
super().__init__()

self.dim = dim if type(dim) is int else tuple(dim)
self.dim = dim if isinstance(dim, int) else tuple(dim)
self.eps = eps

def forward(self, x: Tensor) -> Tensor:
Expand Down
2 changes: 1 addition & 1 deletion zuko/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def broadcast(*tensors: Tensor, ignore: Union[int, Sequence[int]] = 0) -> List[T
torch.Size([3, 4, 5])
"""

if type(ignore) is int:
if isinstance(ignore, int):
ignore = [ignore] * len(tensors)

dims = [t.dim() - i for t, i in zip(tensors, ignore)]
Expand Down

0 comments on commit 08d3f43

Please sign in to comment.