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 41f5fe5 commit a2e52fa
Show file tree
Hide file tree
Showing 22 changed files with 116 additions and 85 deletions.
37 changes: 11 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repos:
hooks:
- id: actionlint
- repo: https://github.com/adrienverge/yamllint
rev: v1.33.0
rev: v1.34.0
hooks:
- id: yamllint
- repo: https://github.com/executablebooks/mdformat
Expand All @@ -68,44 +68,29 @@ 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.10.0
rev: v0.12.1
hooks:
- id: markdownlint-cli2
additional_dependencies:
- markdown-it-texmath
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.7.0-4
rev: v3.8.0-1
hooks:
- id: shfmt
- 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.335
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

ci:
skip:
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 termux_language_server import __version__ as version # type: ignore
from termux_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 @@ -96,19 +96,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 @@ -117,9 +131,6 @@ exclude_lines = [
"\\s*import tomli as tomllib",
]

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

[tool.cibuildwheel]
archs = ["all"]
skip = "*37-* *38-* *39-*"
Expand Down
1 change: 1 addition & 0 deletions src/termux_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>`_.
"""

from typing import Literal

try:
Expand Down
4 changes: 2 additions & 2 deletions src/termux_language_server/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
r"""This module can be called by
`python -m <https://docs.python.org/3/library/__main__.html>`_.
"""

from argparse import ArgumentParser, RawDescriptionHelpFormatter
from contextlib import suppress
from datetime import datetime

from . import FILETYPE
from . import FILETYPE, __version__
from . import __name__ as NAME
from . import __version__

NAME = NAME.replace("_", "-")
VERSION = rf"""{NAME} {__version__}
Expand Down
1 change: 1 addition & 0 deletions src/termux_language_server/finders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Finders
===========
"""

from copy import deepcopy
from dataclasses import dataclass

Expand Down
1 change: 1 addition & 0 deletions src/termux_language_server/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Misc
========
"""

from typing import Any

from .. import FILETYPE
Expand Down
8 changes: 6 additions & 2 deletions src/termux_language_server/misc/color_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Portage's color.map
=======================
"""

from typing import Any

from tree_sitter_lsp.misc import get_soup
Expand All @@ -15,7 +16,10 @@ def init_schema() -> dict[str, dict[str, Any]]:
"""
filetype = "color.map"
schema = {
"$id": f"{SOURCE}/blob/main/src/termux_language_server/assets/json/{filetype}.json",
"$id": (
f"{SOURCE}/blob/main/"
"src/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 All @@ -25,7 +29,7 @@ def init_schema() -> dict[str, dict[str, Any]]:
"properties": {},
}
dl = get_soup("color.map").find_all("dl")[1]
for dt, dd in zip(dl.find_all("dt"), dl.find_all("dd")):
for dt, dd in zip(dl.find_all("dt"), dl.find_all("dd"), strict=False):
name = dt.text.split()[0]
description = dd.text.replace("\n", " ").strip()
example = dt.text.replace("\n", " ")
Expand Down
8 changes: 6 additions & 2 deletions src/termux_language_server/misc/ebuild.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Portage's ebuild
====================
"""

from typing import Any

from tree_sitter_lsp.misc import get_soup
Expand All @@ -16,7 +17,10 @@ def init_schema() -> dict[str, dict[str, Any]]:
"""
filetype = "ebuild"
schema = {
"$id": f"{SOURCE}/blob/main/src/termux_language_server/assets/json/{filetype}.json",
"$id": (
f"{SOURCE}/blob/main/"
"src/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 All @@ -26,7 +30,7 @@ def init_schema() -> dict[str, dict[str, Any]]:
"properties": {},
}
for dl in get_soup("ebuild").find_all("dl")[20:-2]:
for dt, dd in zip(dl.find_all("dt"), dl.find_all("dd")):
for dt, dd in zip(dl.find_all("dt"), dl.find_all("dd"), strict=False):
if dt.strong is None or dt.strong.text.endswith(":"):
continue
name = dt.strong.text.split()[0]
Expand Down
1 change: 1 addition & 0 deletions src/termux_language_server/misc/licenses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Licenses
============
"""

from license_expression import get_license_index

LICENSES = [
Expand Down
8 changes: 6 additions & 2 deletions src/termux_language_server/misc/make_conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""Portage's make.conf
=======================
"""

from typing import Any

from tree_sitter_lsp.misc import get_soup
Expand All @@ -15,7 +16,10 @@ def init_schema() -> dict[str, dict[str, Any]]:
"""
filetype = "make.conf"
schema = {
"$id": f"{SOURCE}/blob/main/src/termux_language_server/assets/json/{filetype}.json",
"$id": (
f"{SOURCE}/blob/main/"
"src/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 All @@ -25,7 +29,7 @@ def init_schema() -> dict[str, dict[str, Any]]:
"properties": {},
}
for dl in get_soup("make.conf").find_all("dl")[:-2]:
for dt, dd in zip(dl.find_all("dt"), dl.find_all("dd")):
for dt, dd in zip(dl.find_all("dt"), dl.find_all("dd"), strict=False):
if dt.strong is None:
continue
name = dt.strong.text.split()[0]
Expand Down
6 changes: 5 additions & 1 deletion src/termux_language_server/misc/makepkg_conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""makepkg.conf
================
"""

from typing import Any

from tree_sitter_lsp.misc import get_soup
Expand All @@ -15,7 +16,10 @@ def init_schema() -> dict[str, dict[str, Any]]:
"""
filetype = "makepkg.conf"
schema = {
"$id": f"{SOURCE}/blob/main/src/termux_language_server/assets/json/{filetype}.json",
"$id": (
f"{SOURCE}/blob/main/"
"src/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
37 changes: 20 additions & 17 deletions src/termux_language_server/misc/pkgbuild.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
r"""PKGBUILD
============
"""

import os
from typing import Any

Expand All @@ -18,9 +19,9 @@ def get_content(tokens: list[Token]) -> str:
:type tokens: list[Token]
:rtype: str
"""
return "\n".join(
[token.content.replace("\n", " ") for token in tokens if token.content]
)
return "\n".join([
token.content.replace("\n", " ") for token in tokens if token.content
])


def init_schema() -> dict[str, Any]:
Expand All @@ -31,7 +32,10 @@ def init_schema() -> dict[str, Any]:
schemas = {}
for filetype in {"PKGBUILD", "install"}:
schemas[filetype] = {
"$id": f"{SOURCE}/blob/main/src/termux_language_server/assets/json/{filetype}.json",
"$id": (
f"{SOURCE}/blob/main/"
"src/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 @@ -63,16 +67,14 @@ def init_schema() -> dict[str, Any]:
if token.type == "blockquote_close"
]
close_indices = [
min(
[
blockquote_close_index
for blockquote_close_index in blockquote_close_indices
if blockquote_close_index > index
]
)
min([
blockquote_close_index
for blockquote_close_index in blockquote_close_indices
if blockquote_close_index > index
])
for index in indices
]
for index, close_index in zip(indices, close_indices):
for index, close_index in zip(indices, close_indices, strict=False):
children = tokens[index].children
if children is None:
continue
Expand Down Expand Up @@ -108,9 +110,9 @@ def init_schema() -> dict[str, Any]:
schemas[filetype][properties_name][name] = {
"description": description
}
# makepkg supports building multiple packages from a single PKGBUILD.
# This is achieved by assigning an array of package names to the
# pkgname directive.
# makepkg supports building multiple packages from a single
# PKGBUILD. This is achieved by assigning an array of package names
# to the pkgname directive.
if name == "pkgname":
schemas[filetype][properties_name][name]["oneOf"] = [
{
Expand All @@ -129,8 +131,9 @@ def init_schema() -> dict[str, Any]:
"uniqueItems": True,
}
elif kind == "Function":
# Each split package uses a corresponding packaging function with
# name package_foo(), where foo is the name of the split package.
# Each split package uses a corresponding packaging function
# with name package_foo(), where foo is the name of the split
# package.
schemas[filetype][properties_name][name]["const"] = 0
# https://archlinux32.org/architecture/
# https://archlinux.org/packages/
Expand Down
Loading

0 comments on commit a2e52fa

Please sign in to comment.