Pre commit ci (#4863)

This commit is contained in:
Noorhteen Raja NJ 2022-07-01 21:17:01 +05:30 committed by GitHub
parent 8b9a7e2782
commit cbf23e60fb
Failed to generate hash of commit
30 changed files with 186 additions and 232 deletions

View file

@ -54,9 +54,7 @@ jobs:
timeout-minutes: 15
- name: Run QA Checks
if: ${{ startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python-version, '3.10') }}
run: |
python -m pip install -e ".[lint]"
python -m xonsh run-tests.xsh qa
run: python -m xonsh run-tests.xsh validate-news-items
- name: Run tests
if: ${{ !startsWith(matrix.python-version, '3.10') }}
run: |

View file

@ -1,49 +1,80 @@
default_language_version:
# force all unspecified python hooks to run python3
python: python3.10
ci:
autofix_prs: false
repos:
- repo: local
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
name: black
# this gets run within development environment.
# Otherwise will raise command not found or use system level binary
entry: black xonsh/ xontrib/ tests/
language: system
stages: [ commit ]
types:
- python
- id: isort
name: isort
# this gets run within development environment.
# Otherwise will raise command not found or use system level binary
entry: isort xonsh/ xontrib/ tests/
language: system
stages: [ commit ]
types:
- python
- id: qa
name: qa
entry: xonsh run-tests.xsh qa
language: system
stages: [ push ]
entry: black xonsh xontrib tests xompletions
pass_filenames: false
types:
- python
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
entry: isort xonsh xontrib tests xompletions
pass_filenames: false
name: isort (python)
- repo: https://github.com/pycqa/flake8
rev: '4.0.1' # pick a git hash / tag to point to
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings
- flake8-bugbear
# Check for debugger imports and py37+ breakpoint() calls in python source.
- flake8-debugger
exclude: |
(?x)^(
xonsh/ply/.+|
docs/.+
)$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.961' # 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
rev: v4.2.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
exclude: |
(?x)^(
docs/_static/.+
)$
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
# Check for debugger imports and py37+ breakpoint() calls in python source.
- id: debug-statements
- id: check-added-large-files
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
rev: v2.34.0
hooks:
- id: pyupgrade
args: [--py37-plus]
args: [--py38-plus]
exclude: |
(?x)^(
xonsh/ply/.+|
tests/bin/.+
)$

View file

@ -95,18 +95,6 @@ full = [
"setproctitle; platform_system=='Windows'",
"gnureadline; platform_system=='Darwin'",
]
format = [
"black==22.3.0",
"isort>=5.10",
]
lint = [
"xonsh[format]",
"flake8",
"flake8-docstrings",
"flake8-bugbear",
"mypy==0.941",
"types-ujson",
]
bestshell = [
"prompt_toolkit>=3.0.29",
"pygments>=2.2",
@ -128,10 +116,8 @@ test = [
"amalgamate",
]
dev = [
"xonsh[lint,test,doc]",
"xonsh[test,doc]",
"pre-commit",
"sniffer",
"pyinotify; sys_platform == \"linux\"",
"re-ver",
"tomli",
]

View file

@ -20,7 +20,7 @@ $VERSION_BUMP_PATTERNS = [
$CHANGELOG_FILENAME = 'CHANGELOG.rst'
$CHANGELOG_TEMPLATE = 'TEMPLATE.rst'
$PYTEST_COMMAND = "./run-tests.xsh -- test"
$PYTEST_COMMAND = "./run-tests.xsh test"
$TAG_REMOTE = 'git@github.com:xonsh/xonsh.git'
$TAG_TARGET = 'main'

View file

@ -60,28 +60,17 @@ def test(
![pytest @(_replace_args(pytest_args, 0)) --durations=5]
def qa():
"""QA checks"""
$XONSH_NO_AMALGAMATE = True
$XONSH_TRACE_SUBPROC_FUNC = colored_tracer
$XONSH_TRACE_SUBPROC = True
black --check xonsh xontrib tests xompletions
isort --check xonsh xontrib tests xompletions
python -m flake8
mypy xonsh
mypy xontrib --namespace-packages --explicit-package-bases
mypy xompletions --namespace-packages --explicit-package-bases
pytest -m news
def validate_news_items(
pytest_args: xcli.Arg(nargs='*') = (),
):
![pytest -m news @(pytest_args)]
if __name__ == '__main__':
parser = xcli.make_parser("test commands")
parser.add_command(test)
parser.add_command(qa)
parser.add_command(validate_news_items)
try:
xcli.dispatch(parser)

View file

@ -1,47 +0,0 @@
"""Configuration file for sniffer."""
import time
import subprocess
from sniffer.api import select_runnable, file_validator, runnable
try:
from pync import Notifier
except ImportError:
notify = None
else:
notify = Notifier.notify
watch_paths = ['.']
@select_runnable('python')
@file_validator
def py_files(filename):
return "TemplateDemo" not in filename
@runnable
def python(*_):
group = int(time.time()) # unique per run
for count, (command, title) in enumerate((
(('dmypy', 'run', "--", "xonsh"), "type-check"),
(('flake8', '.'), "Lint"),
(('xonsh', 'run-tests.xsh', 'test'), "test"),
), start=1):
print(f"\n$ {' '.join(command)}")
failure = subprocess.call(command)
if failure:
if notify and title:
mark = "" * count
notify(mark + " [FAIL] " + mark, title=title, group=group)
return False
else:
if notify and title:
mark = "" * count
notify(mark + " [PASS] " + mark, title=title, group=group)
return True

View file

@ -119,8 +119,9 @@ pretty = True
ignore_errors = True
# 3rd party libraries that we dont have control over
[mypy-zmq.*,setproctitle,xonsh.ply.*,jupyter_client.*,winreg.*,pygments.*,prompt_toolkit.*,importlib_resources.*,nt.*,prompt_toolkit.*,distro.*,conda_suggest.*,_winreg.*,*.__amalgam__.*]
[mypy-zmq.*,setproctitle,xonsh.ply.*,winreg.*,pygments.*,importlib_resources.*,nt.*,prompt_toolkit.*,distro.*,conda_suggest.*,_winreg.*,*.__amalgam__.*]
ignore_missing_imports = True
ignore_errors = True
[tool:pytest]
cache_dir = .cache/pytest

View file

@ -43,7 +43,7 @@ def _windows_bash_command(env=None):
out = subprocess.check_output(
[bash_on_path, "--version"],
stderr=subprocess.PIPE,
universal_newlines=True,
text=True,
)
except subprocess.CalledProcessError:
bash_works = False
@ -387,7 +387,7 @@ def bash_completions(
try:
out = subprocess.check_output(
[command, "-c", script],
universal_newlines=True,
text=True,
stderr=subprocess.PIPE,
env=env,
)

View file

@ -109,9 +109,7 @@ def _unc_map_temp_drive(unc_path) -> str:
for dord in range(ord("z"), ord("a"), -1):
d = chr(dord) + ":"
if not os.path.isdir(d): # find unused drive letter starting from z:
subprocess.check_output(
["NET", "USE", d, unc_share], universal_newlines=True
)
subprocess.check_output(["NET", "USE", d, unc_share], text=True)
_unc_tempDrives[d] = unc_share
return os.path.join(d, rem_path)
@ -136,9 +134,7 @@ def _unc_unmap_temp_drive(left_drive, cwd):
return
_unc_tempDrives.pop(left_drive)
subprocess.check_output(
["NET", "USE", left_drive, "/delete"], universal_newlines=True
)
subprocess.check_output(["NET", "USE", left_drive, "/delete"], text=True)
events.doc(

View file

@ -99,7 +99,7 @@ def DEFAULT_SETERRPOSTCMD():
return {"bash": "", "zsh": "", "cmd": "if errorlevel 1 exit 1"}
@functools.lru_cache()
@functools.lru_cache
def foreign_shell_data(
shell,
interactive=True,
@ -246,7 +246,7 @@ def foreign_shell_data(
# start new session to avoid hangs
# (doesn't work on Cygwin though)
start_new_session=((not ON_CYGWIN) and (not ON_MSYS)),
universal_newlines=True,
text=True,
)
except (subprocess.CalledProcessError, FileNotFoundError):
if not safe:

View file

@ -381,7 +381,7 @@ def windows_bash_command():
out = subprocess.check_output(
[bash_on_path, "--version"],
stderr=subprocess.PIPE,
universal_newlines=True,
text=True,
)
except subprocess.CalledProcessError:
bash_works = False

View file

@ -222,7 +222,7 @@ def hg_dirty_working_directory():
stderr=subprocess.PIPE,
cwd=cwd,
timeout=vcbt,
universal_newlines=True,
text=True,
env=denv,
)
return s.strip(os.linesep).endswith("+")

View file

@ -57,7 +57,7 @@ def skip_if_not_has(exe: str):
def sp(cmd):
return subprocess.check_output(cmd, universal_newlines=True)
return subprocess.check_output(cmd, text=True)
class DummyStyler:

View file

@ -867,7 +867,7 @@ def debian_command_not_found(cmd):
c = "{0} {1}; exit 0"
s = subprocess.check_output(
c.format(cnf, shlex.quote(cmd)),
universal_newlines=True,
text=True,
stderr=subprocess.STDOUT,
shell=True,
)
@ -902,7 +902,7 @@ def command_not_found(cmd, env):
return rtn
@functools.lru_cache()
@functools.lru_cache
def suggest_commands(cmd, env):
"""Suggests alternative commands given an environment and aliases."""
if not env.get("SUGGEST_COMMANDS"):

View file

@ -10,7 +10,7 @@ from xonsh.built_ins import XSH
from xonsh.xoreutils import _which
@functools.lru_cache()
@functools.lru_cache
def _which_create_parser():
desc = "Parses arguments to which wrapper"
parser = argparse.ArgumentParser("which", description=desc)

View file

@ -6,9 +6,9 @@ from xonsh.built_ins import XonshSession
def handle_sigusr1(sig, frame):
print("\nSIGUSR1 signal received. Starting interactive debugger...", flush=True)
import pdb
import pdb # noqa
pdb.Pdb().set_trace(frame)
pdb.Pdb().set_trace(frame) # noqa
def _load_xontrib_(xsh: XonshSession, **_):