refactor: update line length to default setting

and ruff-format
This commit is contained in:
Noortheen Raja 2024-04-15 18:31:23 +05:30 committed by Gil Forsyth
parent b3d58e6ff2
commit aa857e8260
19 changed files with 63 additions and 56 deletions

View file

@ -21,21 +21,7 @@ repos:
rev: 'v1.9.0' # Use the sha / tag you want to point at
hooks:
- id: mypy
name: mypy xonsh
pass_filenames: false
entry: mypy xonsh
additional_dependencies:
- types-ujson
- id: mypy
name: mypy xontrib
pass_filenames: false
entry: mypy xontrib --namespace-packages --explicit-package-bases
additional_dependencies:
- types-ujson
- id: mypy
name: mypy xompletions
pass_filenames: false
entry: mypy xompletions --namespace-packages --explicit-package-bases
additional_dependencies:
- types-ujson
- repo: https://github.com/pre-commit/pre-commit-hooks

View file

@ -168,7 +168,7 @@ extend-exclude = [
".venv*/",
".local.out*/",
]
line-length = 180
line-length = 88
[tool.ruff.lint]
ignore = [
@ -196,6 +196,7 @@ ignore = [
"D411", # Missing blank line before section
"D418", # Function decorated with `@overload` shouldn't contain a docstring
"E402", # Module level import not at top of file
"E501", # line length
"E731", # Do not assign a lambda expression, use a def
]
select = [

View file

@ -6,6 +6,8 @@ cache_dir = .cache/mypy/
warn_unused_configs = True
warn_no_return = False
packages=xonsh,xontrib,xompletions
; a regex to exclude certain directories
exclude = ((xonsh/ply)|(xontrib/(mpl.*py|distributed.py|jedi.py)))

View file

@ -56,9 +56,7 @@ def shares_setup(tmpdir_factory):
s,
d,
l,
) in (
shares
): # set up some shares on local machine. dirs already exist test case must invoke wd_setup.
) in shares: # set up some shares on local machine. dirs already exist test case must invoke wd_setup.
rtn = subprocess.call(
["NET", "SHARE", s, "/delete"], universal_newlines=True
) # clean up from previous run after good, long wait.

View file

@ -1,8 +1,8 @@
"""Tests the xonfig command.
Actually, just a down payment on a full test.
Currently exercises only these options:
- xonfig info
- xonfig jupyter_kernel
Actually, just a down payment on a full test.
Currently exercises only these options:
- xonfig info
- xonfig jupyter_kernel
"""
@ -69,7 +69,9 @@ class MockRequest:
(
req.body.encode()
if isinstance(req.body, str)
else b"" if req.body is None else req.body
else b""
if req.body is None
else req.body
),
]
self._request()

View file

@ -442,7 +442,9 @@ class ArgparseCompleter:
nargs = (
act.nargs
if isinstance(act.nargs, int)
else args_len + 1 if act.nargs in {ap.ONE_OR_MORE, ap.ZERO_OR_MORE} else 1
else args_len + 1
if act.nargs in {ap.ONE_OR_MORE, ap.ZERO_OR_MORE}
else 1
)
if len(self.remaining_args) >= nargs:
# consume n-number of args

View file

@ -285,7 +285,11 @@ def _make_matcher_handler(tok, typ, pymode, ender, handlers):
matcher = (
")"
if tok.endswith("(")
else "}" if tok.endswith("{") else "]" if tok.endswith("[") else None
else "}"
if tok.endswith("{")
else "]"
if tok.endswith("[")
else None
)
def _inner_handler(state, token):

View file

@ -464,8 +464,7 @@ class CompletionContextParser:
if self.cursor_in_span(inner_span) or (
# the cursor is in a space-separated multi keyword.
# even if the cursor's at the edge, the keyword should be considered as a normal arg
tok.value in ("and", "or")
and self.cursor_in_span(outer_span)
tok.value in ("and", "or") and self.cursor_in_span(outer_span)
):
tok.type = "ANY"
@ -934,7 +933,9 @@ class CompletionContextParser:
sub_expr = cast(ArgContext, arg.expansion_obj)
# this arg is a subcommand or multiple subcommands, e.g. `$(a && b)`
expanded_obj: Optional[ArgContext] = self.try_expand_span(sub_expr, new_span) # type: ignore
expanded_obj: Optional[ArgContext] = self.try_expand_span( # type: ignore
sub_expr, new_span
)
if expanded_obj is None:
return None
return self.sub_expression_arg(expanded_obj)
@ -964,7 +965,9 @@ class CompletionContextParser:
# the last command is expandable
# if it were an `ExpansionOperation`, `try_expand` would caught it instead
expandable = cast(ExpandableObject, python_context.expansion_obj)
expanded_command: Optional[ExpandableObject] = self.try_expand_right(expandable, new_span.stop) # type: ignore
expanded_command: Optional[ExpandableObject] = self.try_expand_right(
expandable, new_span.stop
) # type: ignore
if (
expanded_command is not None

View file

@ -29,7 +29,7 @@ def RE_HIDDEN_BYTES():
@xl.lazyobject
def RE_VT100_ESCAPE():
return re.compile(b"(\x9B|\x1B\\[)[0-?]*[ -\\/]*[@-~]")
return re.compile(b"(\x9b|\x1b\\[)[0-?]*[ -\\/]*[@-~]")
@xl.lazyobject

View file

@ -357,9 +357,9 @@ class PopenThread(threading.Thread):
return
try:
mode = xli.termios.tcgetattr(0) # only makes sense for stdin
mode[xp.CC][
xli.termios.VSUSP
] = self._tc_cc_vsusp # set ^Z (ie SIGSTOP) to original
mode[xp.CC][xli.termios.VSUSP] = (
self._tc_cc_vsusp
) # set ^Z (ie SIGSTOP) to original
# this usually doesn't work in interactive mode,
# but we should try it anyway.
xli.termios.tcsetattr(0, xli.termios.TCSANOW, mode)

View file

@ -124,8 +124,8 @@ def nodes_equal(x, y):
), f"Ast nodes field names differ : {xname} (of type {type(xval)}) != {yname} (of type {type(yval)})"
if isinstance(x, ast.Constant) and xname == "kind":
continue
assert type(xval) == type(
yval
assert (
type(xval) == type(yval)
), f"Ast nodes fields differ : {xname} (of type {type(xval)}) != {yname} (of type {type(yval)})"
for xchild, ychild in zip(ast.iter_child_nodes(x), ast.iter_child_nodes(y)):
assert nodes_equal(xchild, ychild), "Ast node children differs"

View file

@ -64,7 +64,13 @@ _RL_PREV_CASE_SENSITIVE_COMPLETIONS = "to-be-set"
def setup_readline():
"""Sets up the readline module and completion suppression, if available."""
global RL_COMPLETION_SUPPRESS_APPEND, RL_LIB, RL_CAN_RESIZE, RL_STATE, readline, RL_COMPLETION_QUERY_ITEMS
global \
RL_COMPLETION_SUPPRESS_APPEND, \
RL_LIB, \
RL_CAN_RESIZE, \
RL_STATE, \
readline, \
RL_COMPLETION_QUERY_ITEMS
if RL_COMPLETION_SUPPRESS_APPEND is not None:
return
for _rlmod_name in ("gnureadline", "readline"):

View file

@ -1792,7 +1792,9 @@ def to_completion_mode(x):
y = (
"default"
if y in ("", "d", "xonsh", "none", "def")
else "menu-complete" if y in ("m", "menu", "menu-completion") else y
else "menu-complete"
if y in ("m", "menu", "menu-completion")
else y
)
if y not in CANONIC_COMPLETION_MODES:
warnings.warn(

View file

@ -1,19 +1,13 @@
import sys
from typing import TYPE_CHECKING
from xonsh.environ import Env
from ..built_ins import XonshSession
from .file_writes import insert_into_xonshrc
if TYPE_CHECKING:
pass
import logging
import sys
from urllib import parse
from xonsh.built_ins import XonshSession
from xonsh.environ import Env
from . import tags as t
from . import xonsh_data
from .file_writes import insert_into_xonshrc
class Routes:

View file

@ -168,10 +168,13 @@ def render_prompts(env):
yield get_initial(env, prompt_format, fields)
for name, template in get_named_prompts():
display = html_format(prompt_format(template, fields=fields))
yield name, {
"value": template,
"display": escape(display),
}
yield (
name,
{
"value": template,
"display": escape(display),
},
)
def render_colors():

View file

@ -1,5 +1,4 @@
"""Tools for creating command-line and web-based wizards from a tree of nodes.
"""
"""Tools for creating command-line and web-based wizards from a tree of nodes."""
import ast
import collections.abc as cabc

View file

@ -640,7 +640,7 @@ def xonfig_color_completer(*_, **__):
def _colors(
style: Annotated[str, Arg(nargs="?", completer=xonfig_color_completer)] = None
style: Annotated[str, Arg(nargs="?", completer=xonfig_color_completer)] = None,
):
"""Preview color style

View file

@ -365,7 +365,11 @@ def _get_xontrib_entrypoints() -> "tp.Iterable[EntryPoint]":
name = "xonsh.xontribs"
entries = metadata.entry_points()
# for some reason, on CI (win py3.8) atleast, returns dict
group = entries.select(group=name) if hasattr(entries, "select") else entries.get(name, []) # type: ignore
group = (
entries.select(group=name)
if hasattr(entries, "select")
else entries.get(name, []) # type: ignore
)
yield from group

View file

@ -7,6 +7,7 @@ This version of uname was written in Python for the xonsh project: http://xon.sh
Based on cat from GNU coreutils: http://www.gnu.org/software/coreutils/
"""
import platform
import sys