From aa857e8260478f81e8c427cce1e7486f44a4b048 Mon Sep 17 00:00:00 2001 From: Noortheen Raja Date: Mon, 15 Apr 2024 18:31:23 +0530 Subject: [PATCH] refactor: update line length to default setting and ruff-format --- .pre-commit-config.yaml | 14 -------------- pyproject.toml | 3 ++- setup.cfg | 2 ++ tests/test_dirstack_unc.py | 4 +--- tests/test_xonfig.py | 12 +++++++----- xonsh/cli_utils.py | 4 +++- xonsh/lexer.py | 6 +++++- xonsh/parsers/completion_context.py | 11 +++++++---- xonsh/procs/pipelines.py | 2 +- xonsh/procs/posix.py | 6 +++--- xonsh/pytest/tools.py | 4 ++-- xonsh/readline_shell.py | 8 +++++++- xonsh/tools.py | 4 +++- xonsh/webconfig/routes.py | 16 +++++----------- xonsh/webconfig/xonsh_data.py | 11 +++++++---- xonsh/wizard.py | 3 +-- xonsh/xonfig.py | 2 +- xonsh/xontribs.py | 6 +++++- xonsh/xoreutils/uname.py | 1 + 19 files changed, 63 insertions(+), 56 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9ef3186b1..70e7d5436 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 08ee5aca4..aecf35fab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/setup.cfg b/setup.cfg index e7880b307..fb396157b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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))) diff --git a/tests/test_dirstack_unc.py b/tests/test_dirstack_unc.py index e1f181ccb..2e792a4aa 100644 --- a/tests/test_dirstack_unc.py +++ b/tests/test_dirstack_unc.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. diff --git a/tests/test_xonfig.py b/tests/test_xonfig.py index aa2d8ae1a..e47b3599a 100644 --- a/tests/test_xonfig.py +++ b/tests/test_xonfig.py @@ -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() diff --git a/xonsh/cli_utils.py b/xonsh/cli_utils.py index 45ffeb46c..0fc650f12 100644 --- a/xonsh/cli_utils.py +++ b/xonsh/cli_utils.py @@ -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 diff --git a/xonsh/lexer.py b/xonsh/lexer.py index ddebd59af..59278eb51 100644 --- a/xonsh/lexer.py +++ b/xonsh/lexer.py @@ -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): diff --git a/xonsh/parsers/completion_context.py b/xonsh/parsers/completion_context.py index 0984d9671..c31593c80 100644 --- a/xonsh/parsers/completion_context.py +++ b/xonsh/parsers/completion_context.py @@ -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 diff --git a/xonsh/procs/pipelines.py b/xonsh/procs/pipelines.py index bc8c8404d..ba49f7149 100644 --- a/xonsh/procs/pipelines.py +++ b/xonsh/procs/pipelines.py @@ -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 diff --git a/xonsh/procs/posix.py b/xonsh/procs/posix.py index 043555155..aa5011d5c 100644 --- a/xonsh/procs/posix.py +++ b/xonsh/procs/posix.py @@ -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) diff --git a/xonsh/pytest/tools.py b/xonsh/pytest/tools.py index 2413e4ca4..9b8d82d6c 100644 --- a/xonsh/pytest/tools.py +++ b/xonsh/pytest/tools.py @@ -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" diff --git a/xonsh/readline_shell.py b/xonsh/readline_shell.py index a5c4f39c8..e98d4bcfc 100644 --- a/xonsh/readline_shell.py +++ b/xonsh/readline_shell.py @@ -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"): diff --git a/xonsh/tools.py b/xonsh/tools.py index 20387540e..5a0615614 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -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( diff --git a/xonsh/webconfig/routes.py b/xonsh/webconfig/routes.py index 018172125..578798650 100644 --- a/xonsh/webconfig/routes.py +++ b/xonsh/webconfig/routes.py @@ -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: diff --git a/xonsh/webconfig/xonsh_data.py b/xonsh/webconfig/xonsh_data.py index acf3fcfea..51cd5152d 100644 --- a/xonsh/webconfig/xonsh_data.py +++ b/xonsh/webconfig/xonsh_data.py @@ -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(): diff --git a/xonsh/wizard.py b/xonsh/wizard.py index d085b7a98..3e1008139 100644 --- a/xonsh/wizard.py +++ b/xonsh/wizard.py @@ -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 diff --git a/xonsh/xonfig.py b/xonsh/xonfig.py index b28e24b75..eaea4a211 100644 --- a/xonsh/xonfig.py +++ b/xonsh/xonfig.py @@ -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 diff --git a/xonsh/xontribs.py b/xonsh/xontribs.py index 40ea0821d..40de6d3a4 100644 --- a/xonsh/xontribs.py +++ b/xonsh/xontribs.py @@ -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 diff --git a/xonsh/xoreutils/uname.py b/xonsh/xoreutils/uname.py index d4147f3f7..1cdd66343 100644 --- a/xonsh/xoreutils/uname.py +++ b/xonsh/xoreutils/uname.py @@ -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