Skip to content

Commit

Permalink
👷 Use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Jan 31, 2024
1 parent 019af0a commit f676993
Show file tree
Hide file tree
Showing 65 changed files with 164 additions and 126 deletions.
31 changes: 7 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ repos:
- mdformat-black
- mdformat-config
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.10.0
rev: v0.12.1
hooks:
- id: markdownlint-cli2
additional_dependencies:
Expand All @@ -84,39 +84,22 @@ repos:
- id: update-package.json
- id: update-addon-info.json
- repo: https://github.com/perltidy/perltidy
rev: "20230912.05"
rev: "20230912.13"
hooks:
- id: perltidy
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.7.0-4
hooks:
- id: shfmt
- repo: https://github.com/psf/black
rev: 23.11.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
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.348
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/vimjas/vint
rev: v0.4a3
hooks:
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""

from translate_shell import __version__ as version # type: ignore
from translate_shell._metainfo import author, copyright, project
from translate_shell.utils.notify import ICON_FILE as html_favicon
Expand Down
1 change: 1 addition & 0 deletions examples/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configure."""

from translate_shell.config import Configuration


Expand Down
46 changes: 26 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,40 @@ file = "requirements/yaml.txt"
[tool.mdformat]
number = true

[tool.black]
line-length = 79

[tool.isort]
line_length = 79
profile = "black"

[tool.pydocstyle]
add_ignore = "D205, D400"
[tool.codespell]
ignore-words-list = "fo, nd, te"

[tool.bandit]
skips = ["B310", "B404", "B603"]
[tool.doq]
template_path = "templates"

[tool.bandit.assert_used]
skips = ["*_test.py", "test_*.py"]
[tool.ruff]
line-length = 79

[tool.codespell]
ignore-words-list = "fo, nd, te"
[tool.ruff.lint]
select = [
# pycodestyle
"E",
# pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# isort
"I",
]
ignore = ["D205", "D400"]
preview = true

[tool.pyright]
exclude = ["templates/__init__.py"]
[tool.ruff.format]
docstring-code-format = true
preview = true

[tool.coverage.report]
exclude_lines = [
"if TYPE_CHECKING:",
"if __name__ == .__main__.:",
"\\s*import tomli as tomllib",
]

[tool.doq]
template_path = "templates"
1 change: 1 addition & 0 deletions scripts/generate-repl-screenshot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Generate screenshot for REPL."""

from time import sleep

import pexpect
Expand Down
1 change: 1 addition & 0 deletions scripts/generate-translator.md.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Generate translator.md."""

import logging

from translate_shell.translators import TRANSLATORS
Expand Down
9 changes: 4 additions & 5 deletions scripts/test-bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
time: 1.8392638560035266
results: 4
"""

import time
from timeit import timeit

from translate_shell.__main__ import get_parser
from translate_shell.translate import translate
from translate_shell.translate import translate # noqa: F401
from translate_shell.ui import init

NUMBER = 1
Expand All @@ -28,14 +29,12 @@
parser = get_parser()
args = parser.parse_args()
init(args)
print(
f"""
print(f"""
input text:\t{args.text}
target lang\t{args.target_lang}
source lang:\t{args.source_lang}
translators:\t{args.translators}
"""
)
""")
args.translators = args.translators.split(",")

translationss = {}
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
r"""Setup
=========
"""

from setuptools import setup

with open("action.yml") as fin, open(
"src/translate_shell/tools/po/action.yml", "w"
) as fout:
with (
open("action.yml") as fin,
open("src/translate_shell/tools/po/action.yml", "w") as fout,
):
fout.write(fin.read())

setup()
8 changes: 4 additions & 4 deletions src/translate_shell/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
`python -m <https://docs.python.org/3/library/__main__.html>`_.
See `man <../resources/man.html>`_.
"""

import json
import sys
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from pathlib import Path
from typing import Literal, NoReturn

from translate_shell import __version__ # type: ignore
from translate_shell._metainfo import ( # type: ignore
DESCRIPTION,
EPILOG,
Expand Down Expand Up @@ -153,8 +153,8 @@ def get_parser() -> ArgumentParser:
"--options",
default=[],
help="advanced usage, see "
"https://translate-shell.readthedocs.io/en/latest/resources/config.html "
". default: %(default)s",
"https://translate-shell.readthedocs.io/en/latest/resources/config.html"
" . default: %(default)s",
action="append",
).complete = LANG_COMPLETE # type: ignore
parser.add_argument(
Expand Down Expand Up @@ -188,7 +188,7 @@ def main() -> None | NoReturn:
from translate_shell.ui.server import run
else:
try:
import vim # type: ignore
import vim # type: ignore # noqa: F401
except ImportError:
if not sys.stdin.isatty():
args.text = [sys.stdin.read()] + args.text
Expand Down
1 change: 1 addition & 0 deletions src/translate_shell/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Define a class for user customization.
"""

from argparse import Namespace
from typing import Any, Literal

Expand Down
4 changes: 3 additions & 1 deletion src/translate_shell/external/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
"""This module can be called by
`python -m <https://docs.python.org/3/library/__main__.html>`_
to check if any fake module imports any variable don't owned by any true module.
to check if any fake module imports any variable doesn't owned by any real
module.
"""

import os
import sys
from importlib import import_module
Expand Down
5 changes: 3 additions & 2 deletions src/translate_shell/external/colorama/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake colorama
================
"""

try:
from colorama import * # type: ignore
from colorama import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
5 changes: 3 additions & 2 deletions src/translate_shell/external/keyring/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake keyring
===============
"""

try:
from keyring import * # type: ignore
from keyring import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
1 change: 1 addition & 0 deletions src/translate_shell/external/keyring/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
`python -m <https://docs.python.org/3/library/__main__.html>`_
to check if it imports any variable don't owned by any true module.
"""

import logging as _logging

_logger = _logging.getLogger(__name__)
Expand Down
5 changes: 3 additions & 2 deletions src/translate_shell/external/keyring/errors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake errors
==============
"""

try:
from errors import * # type: ignore
from errors import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
1 change: 1 addition & 0 deletions src/translate_shell/external/keyring/errors/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
`python -m <https://docs.python.org/3/library/__main__.html>`_
to check if it imports any variable don't owned by any true module.
"""

NoKeyringError = Exception


Expand Down
5 changes: 3 additions & 2 deletions src/translate_shell/external/langdetect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake langdetect
==================
"""

try:
from langdetect import * # type: ignore
from langdetect import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
3 changes: 2 additions & 1 deletion src/translate_shell/external/langdetect/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
`python -m <https://docs.python.org/3/library/__main__.html>`_
to check if it imports any variable don't owned by any true module.
"""

import re as _re

_RE_CHINESE = _re.compile("[\u4e00-\u9fff]", _re.UNICODE)
_RE_JAPANESE = _re.compile("[\u3041-\u30FE]", _re.UNICODE)
_RE_JAPANESE = _re.compile("[\u3041-\u30fe]", _re.UNICODE)
LangDetectException = Exception


Expand Down
5 changes: 3 additions & 2 deletions src/translate_shell/external/platformdirs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake platformdirs
====================
"""

try:
from platformdirs import * # type: ignore
from platformdirs import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
5 changes: 3 additions & 2 deletions src/translate_shell/external/pystardict/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake pystardict
==================
"""

try:
from pystardict import * # type: ignore
from pystardict import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
1 change: 1 addition & 0 deletions src/translate_shell/external/pystardict/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
`python -m <https://docs.python.org/3/library/__main__.html>`_
to check if it imports any variable don't owned by any true module.
"""

import logging as _logging

_logger = _logging.getLogger(__name__)
Expand Down
5 changes: 3 additions & 2 deletions src/translate_shell/external/readline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake readline
================
"""

try:
from readline import * # type: ignore
from readline import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
5 changes: 3 additions & 2 deletions src/translate_shell/external/shtab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake shtab
=============
"""

try:
from shtab import * # type: ignore
from shtab import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
1 change: 1 addition & 0 deletions src/translate_shell/external/shtab/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://github.com/iterative/shtab/blob/95b0e3092cd4dcf1ac2871d44cebda01a89992df/shtab/__init__.py#L786-L789
"""

from argparse import Action, ArgumentParser
from typing import Any, NoReturn

Expand Down
5 changes: 3 additions & 2 deletions src/translate_shell/external/yaml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Fake yaml
============
"""

try:
from yaml import * # type: ignore
from yaml import * # type: ignore # noqa: F403
except ImportError:
from .__main__ import *
from .__main__ import * # noqa: F403
1 change: 1 addition & 0 deletions src/translate_shell/external/yaml/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
`python -m <https://docs.python.org/3/library/__main__.html>`_
to check if it imports any variable don't owned by any true module.
"""

import logging as _logging
import sys
from typing import Any, NoReturn
Expand Down
Loading

0 comments on commit f676993

Please sign in to comment.