Skip to content

Commit

Permalink
👷 Use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Feb 14, 2024
1 parent dc55cc2 commit df9b743
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 50 deletions.
33 changes: 9 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,25 @@ repos:
- mdformat-toc
- mdformat-deflist
- mdformat-beautysh
- mdformat-black
- mdformat-ruff
- ruff
- mdformat-config
- mdformat-web
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.11.0
rev: v0.12.1
hooks:
- id: markdownlint-cli2
additional_dependencies:
- markdown-it-texmath
- repo: https://github.com/psf/black
rev: 23.11.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
additional_dependencies:
- tomli
- id: ruff
- id: ruff-format
- repo: https://github.com/kumaraditya303/mirrors-pyright
rev: v1.1.338
rev: v1.1.350
hooks:
- id: pyright
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args:
- -cpyproject.toml
additional_dependencies:
- tomli
- repo: https://github.com/nix-community/nixpkgs-fmt
rev: v1.3.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""

from mutt_language_server import __version__ as version # type: ignore
from mutt_language_server._metainfo import ( # type: ignore
author,
Expand Down
37 changes: 24 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,33 @@ file = "templates/metainfo.py.j2"
[tool.mdformat]
number = true

[tool.black]
line-length = 79
[tool.doq]
template_path = "templates"

[tool.isort]
line_length = 79
profile = "black"
[tool.ruff]
line-length = 79

# https://github.com/PyCQA/pydocstyle/issues/418
[tool.pydocstyle]
add_ignore = "D205, D400"
[tool.ruff.lint]
select = [
# pycodestyle
"E",
# pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# isort
"I",
]
ignore = ["D205", "D400"]
preview = true

[tool.doq]
template_path = "templates"
[tool.ruff.format]
docstring-code-format = true
preview = true

[tool.coverage.report]
exclude_lines = [
Expand All @@ -98,9 +112,6 @@ exclude_lines = [
"\\s*import tomli as tomllib",
]

[tool.bandit.assert_used]
skips = ["*_test.py", "*/test_*.py"]

[tool.cibuildwheel]
archs = ["all"]
before-test = "pip install pytest"
Expand Down
1 change: 1 addition & 0 deletions src/mutt_language_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Provide ``__version__`` for
`importlib.metadata.version() <https://docs.python.org/3/library/importlib.metadata.html#distribution-versions>`_.
"""

try:
from ._version import __version__, __version_tuple__ # type: ignore
except ImportError: # for setuptools-generate
Expand Down
1 change: 1 addition & 0 deletions src/mutt_language_server/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""This module can be called by
`python -m <https://docs.python.org/3/library/__main__.html>`_.
"""

import logging
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from contextlib import suppress
Expand Down
22 changes: 10 additions & 12 deletions src/mutt_language_server/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Misc
========
"""

import re
from typing import Any

Expand All @@ -16,7 +17,10 @@ def get_schema() -> dict[str, Any]:
"""
filetype = "neomuttrc"
schema = {
"$id": f"{SOURCE}/blob/main/src/termux_language_server/assets/json/{filetype}.json",
"$id": (
f"{SOURCE}/blob/main/src/"
f"termux_language_server/assets/json/{filetype}.json"
),
"$schema": "http://json-schema.org/draft-07/schema#",
"$comment": (
"Don't edit this file directly! It is generated by "
Expand Down Expand Up @@ -52,16 +56,13 @@ def get_schema() -> dict[str, Any]:
```
"""
}
if len(indices) - 1 == i:
index2 = end_index
else:
index2 = indices[i + 1]
index2 = end_index if len(indices) - 1 == i else indices[i + 1]
for token in tokens[index + 1 : index2]:
if token.content != "" and not token.content.startswith("<!--"):
for keyword in keywords:
schema["properties"][keyword][
"description"
] += token.content.replace("\n", " ")
schema["properties"][keyword]["description"] += (
token.content.replace("\n", " ")
)

schema["properties"]["set"]["properties"] = {}
schema["properties"]["set"]["patternProperties"] = {r"my_\w+": {}}
Expand All @@ -84,10 +85,7 @@ def get_schema() -> dict[str, Any]:
schema["properties"]["set"]["properties"][keyword] = {
"description": ""
}
if len(indices) - 1 == i:
index2 = end_index
else:
index2 = indices[i + 1]
index2 = end_index if len(indices) - 1 == i else indices[i + 1]
for token in tokens[index + 1 : index2]:
if (
token.content != ""
Expand Down
1 change: 1 addition & 0 deletions src/mutt_language_server/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Server
==========
"""

import os
import re
from typing import Any
Expand Down
3 changes: 2 additions & 1 deletion src/mutt_language_server/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Utils
=========
"""

import json
import os
from typing import Any
Expand All @@ -23,6 +24,6 @@ def get_schema(filetype: str = "neomuttrc") -> dict[str, Any]:
),
f"{filetype}.json",
)
with open(file, "r") as f:
with open(file) as f:
SCHEMAS[filetype] = json.load(f)
return SCHEMAS[filetype]
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
r"""Test utils."""

from mutt_language_server.utils import get_schema


Expand Down

0 comments on commit df9b743

Please sign in to comment.