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
|
rev: 'v1.9.0' # Use the sha / tag you want to point at
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
name: mypy xonsh
|
|
||||||
pass_filenames: false
|
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:
|
additional_dependencies:
|
||||||
- types-ujson
|
- types-ujson
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
|
|
@ -168,7 +168,7 @@ extend-exclude = [
|
||||||
".venv*/",
|
".venv*/",
|
||||||
".local.out*/",
|
".local.out*/",
|
||||||
]
|
]
|
||||||
line-length = 180
|
line-length = 88
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
ignore = [
|
ignore = [
|
||||||
|
@ -196,6 +196,7 @@ ignore = [
|
||||||
"D411", # Missing blank line before section
|
"D411", # Missing blank line before section
|
||||||
"D418", # Function decorated with `@overload` shouldn't contain a docstring
|
"D418", # Function decorated with `@overload` shouldn't contain a docstring
|
||||||
"E402", # Module level import not at top of file
|
"E402", # Module level import not at top of file
|
||||||
|
"E501", # line length
|
||||||
"E731", # Do not assign a lambda expression, use a def
|
"E731", # Do not assign a lambda expression, use a def
|
||||||
]
|
]
|
||||||
select = [
|
select = [
|
||||||
|
|
|
@ -6,6 +6,8 @@ cache_dir = .cache/mypy/
|
||||||
warn_unused_configs = True
|
warn_unused_configs = True
|
||||||
warn_no_return = False
|
warn_no_return = False
|
||||||
|
|
||||||
|
packages=xonsh,xontrib,xompletions
|
||||||
|
|
||||||
; a regex to exclude certain directories
|
; a regex to exclude certain directories
|
||||||
exclude = ((xonsh/ply)|(xontrib/(mpl.*py|distributed.py|jedi.py)))
|
exclude = ((xonsh/ply)|(xontrib/(mpl.*py|distributed.py|jedi.py)))
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,7 @@ def shares_setup(tmpdir_factory):
|
||||||
s,
|
s,
|
||||||
d,
|
d,
|
||||||
l,
|
l,
|
||||||
) in (
|
) in shares: # set up some shares on local machine. dirs already exist test case must invoke wd_setup.
|
||||||
shares
|
|
||||||
): # set up some shares on local machine. dirs already exist test case must invoke wd_setup.
|
|
||||||
rtn = subprocess.call(
|
rtn = subprocess.call(
|
||||||
["NET", "SHARE", s, "/delete"], universal_newlines=True
|
["NET", "SHARE", s, "/delete"], universal_newlines=True
|
||||||
) # clean up from previous run after good, long wait.
|
) # clean up from previous run after good, long wait.
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
"""Tests the xonfig command.
|
"""Tests the xonfig command.
|
||||||
Actually, just a down payment on a full test.
|
Actually, just a down payment on a full test.
|
||||||
Currently exercises only these options:
|
Currently exercises only these options:
|
||||||
- xonfig info
|
- xonfig info
|
||||||
- xonfig jupyter_kernel
|
- xonfig jupyter_kernel
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -69,7 +69,9 @@ class MockRequest:
|
||||||
(
|
(
|
||||||
req.body.encode()
|
req.body.encode()
|
||||||
if isinstance(req.body, str)
|
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()
|
self._request()
|
||||||
|
|
|
@ -442,7 +442,9 @@ class ArgparseCompleter:
|
||||||
nargs = (
|
nargs = (
|
||||||
act.nargs
|
act.nargs
|
||||||
if isinstance(act.nargs, int)
|
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:
|
if len(self.remaining_args) >= nargs:
|
||||||
# consume n-number of args
|
# consume n-number of args
|
||||||
|
|
|
@ -285,7 +285,11 @@ def _make_matcher_handler(tok, typ, pymode, ender, handlers):
|
||||||
matcher = (
|
matcher = (
|
||||||
")"
|
")"
|
||||||
if tok.endswith("(")
|
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):
|
def _inner_handler(state, token):
|
||||||
|
|
|
@ -464,8 +464,7 @@ class CompletionContextParser:
|
||||||
if self.cursor_in_span(inner_span) or (
|
if self.cursor_in_span(inner_span) or (
|
||||||
# the cursor is in a space-separated multi keyword.
|
# 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
|
# even if the cursor's at the edge, the keyword should be considered as a normal arg
|
||||||
tok.value in ("and", "or")
|
tok.value in ("and", "or") and self.cursor_in_span(outer_span)
|
||||||
and self.cursor_in_span(outer_span)
|
|
||||||
):
|
):
|
||||||
tok.type = "ANY"
|
tok.type = "ANY"
|
||||||
|
|
||||||
|
@ -934,7 +933,9 @@ class CompletionContextParser:
|
||||||
sub_expr = cast(ArgContext, arg.expansion_obj)
|
sub_expr = cast(ArgContext, arg.expansion_obj)
|
||||||
|
|
||||||
# this arg is a subcommand or multiple subcommands, e.g. `$(a && b)`
|
# 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:
|
if expanded_obj is None:
|
||||||
return None
|
return None
|
||||||
return self.sub_expression_arg(expanded_obj)
|
return self.sub_expression_arg(expanded_obj)
|
||||||
|
@ -964,7 +965,9 @@ class CompletionContextParser:
|
||||||
# the last command is expandable
|
# the last command is expandable
|
||||||
# if it were an `ExpansionOperation`, `try_expand` would caught it instead
|
# if it were an `ExpansionOperation`, `try_expand` would caught it instead
|
||||||
expandable = cast(ExpandableObject, python_context.expansion_obj)
|
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 (
|
if (
|
||||||
expanded_command is not None
|
expanded_command is not None
|
||||||
|
|
|
@ -29,7 +29,7 @@ def RE_HIDDEN_BYTES():
|
||||||
|
|
||||||
@xl.lazyobject
|
@xl.lazyobject
|
||||||
def RE_VT100_ESCAPE():
|
def RE_VT100_ESCAPE():
|
||||||
return re.compile(b"(\x9B|\x1B\\[)[0-?]*[ -\\/]*[@-~]")
|
return re.compile(b"(\x9b|\x1b\\[)[0-?]*[ -\\/]*[@-~]")
|
||||||
|
|
||||||
|
|
||||||
@xl.lazyobject
|
@xl.lazyobject
|
||||||
|
|
|
@ -357,9 +357,9 @@ class PopenThread(threading.Thread):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
mode = xli.termios.tcgetattr(0) # only makes sense for stdin
|
mode = xli.termios.tcgetattr(0) # only makes sense for stdin
|
||||||
mode[xp.CC][
|
mode[xp.CC][xli.termios.VSUSP] = (
|
||||||
xli.termios.VSUSP
|
self._tc_cc_vsusp
|
||||||
] = self._tc_cc_vsusp # set ^Z (ie SIGSTOP) to original
|
) # set ^Z (ie SIGSTOP) to original
|
||||||
# this usually doesn't work in interactive mode,
|
# this usually doesn't work in interactive mode,
|
||||||
# but we should try it anyway.
|
# but we should try it anyway.
|
||||||
xli.termios.tcsetattr(0, xli.termios.TCSANOW, mode)
|
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)})"
|
), f"Ast nodes field names differ : {xname} (of type {type(xval)}) != {yname} (of type {type(yval)})"
|
||||||
if isinstance(x, ast.Constant) and xname == "kind":
|
if isinstance(x, ast.Constant) and xname == "kind":
|
||||||
continue
|
continue
|
||||||
assert type(xval) == type(
|
assert (
|
||||||
yval
|
type(xval) == type(yval)
|
||||||
), f"Ast nodes fields differ : {xname} (of type {type(xval)}) != {yname} (of type {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)):
|
for xchild, ychild in zip(ast.iter_child_nodes(x), ast.iter_child_nodes(y)):
|
||||||
assert nodes_equal(xchild, ychild), "Ast node children differs"
|
assert nodes_equal(xchild, ychild), "Ast node children differs"
|
||||||
|
|
|
@ -64,7 +64,13 @@ _RL_PREV_CASE_SENSITIVE_COMPLETIONS = "to-be-set"
|
||||||
|
|
||||||
def setup_readline():
|
def setup_readline():
|
||||||
"""Sets up the readline module and completion suppression, if available."""
|
"""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:
|
if RL_COMPLETION_SUPPRESS_APPEND is not None:
|
||||||
return
|
return
|
||||||
for _rlmod_name in ("gnureadline", "readline"):
|
for _rlmod_name in ("gnureadline", "readline"):
|
||||||
|
|
|
@ -1792,7 +1792,9 @@ def to_completion_mode(x):
|
||||||
y = (
|
y = (
|
||||||
"default"
|
"default"
|
||||||
if y in ("", "d", "xonsh", "none", "def")
|
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:
|
if y not in CANONIC_COMPLETION_MODES:
|
||||||
warnings.warn(
|
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 logging
|
||||||
|
import sys
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
|
||||||
|
from xonsh.built_ins import XonshSession
|
||||||
|
from xonsh.environ import Env
|
||||||
|
|
||||||
from . import tags as t
|
from . import tags as t
|
||||||
from . import xonsh_data
|
from . import xonsh_data
|
||||||
|
from .file_writes import insert_into_xonshrc
|
||||||
|
|
||||||
|
|
||||||
class Routes:
|
class Routes:
|
||||||
|
|
|
@ -168,10 +168,13 @@ def render_prompts(env):
|
||||||
yield get_initial(env, prompt_format, fields)
|
yield get_initial(env, prompt_format, fields)
|
||||||
for name, template in get_named_prompts():
|
for name, template in get_named_prompts():
|
||||||
display = html_format(prompt_format(template, fields=fields))
|
display = html_format(prompt_format(template, fields=fields))
|
||||||
yield name, {
|
yield (
|
||||||
"value": template,
|
name,
|
||||||
"display": escape(display),
|
{
|
||||||
}
|
"value": template,
|
||||||
|
"display": escape(display),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def render_colors():
|
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 ast
|
||||||
import collections.abc as cabc
|
import collections.abc as cabc
|
||||||
|
|
|
@ -640,7 +640,7 @@ def xonfig_color_completer(*_, **__):
|
||||||
|
|
||||||
|
|
||||||
def _colors(
|
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
|
"""Preview color style
|
||||||
|
|
||||||
|
|
|
@ -365,7 +365,11 @@ def _get_xontrib_entrypoints() -> "tp.Iterable[EntryPoint]":
|
||||||
name = "xonsh.xontribs"
|
name = "xonsh.xontribs"
|
||||||
entries = metadata.entry_points()
|
entries = metadata.entry_points()
|
||||||
# for some reason, on CI (win py3.8) atleast, returns dict
|
# 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
|
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/
|
Based on cat from GNU coreutils: http://www.gnu.org/software/coreutils/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue