mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
refactor: update line length to default setting
and ruff-format
This commit is contained in:
parent
b3d58e6ff2
commit
aa857e8260
19 changed files with 63 additions and 56 deletions
|
@ -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
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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)))
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"):
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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, {
|
||||
yield (
|
||||
name,
|
||||
{
|
||||
"value": template,
|
||||
"display": escape(display),
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def render_colors():
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue