From 11c72428263feba0c5b98e4ac012bf73d70d366f Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Mon, 28 Jun 2021 07:11:39 +0100 Subject: [PATCH] Use https://github.com/saltstack/invoke-pre-commit for invoke pre-commit steps --- .pre-commit-config.yaml | 54 ++++++++++++++++++++--------------------- noxfile.py | 50 ++------------------------------------ 2 files changed, 29 insertions(+), 75 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d45d8d5fc40..6780f0173d3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1185,6 +1185,33 @@ repos: # <---- Security --------------------------------------------------------------------------------------------------- # ----- Pre-Commit ------------------------------------------------------------------------------------------------> + - repo: https://github.com/saltstack/invoke-pre-commit + rev: v1.5.0 + hooks: + - id: invoke + alias: check-docs + name: Check Docs + files: ^(salt/.*\.py|doc/ref/.*\.rst)$ + args: + - docs.check + additional_dependencies: + - blessings + - pyyaml + + - repo: https://github.com/saltstack/invoke-pre-commit + rev: v1.5.0 + hooks: + - id: invoke + alias: check-filemap + name: Check Filename Map Change Matching + files: ^tests/(filename_map\.yml|.*\.py)$ + pass_filenames: false + args: + - filemap.check + additional_dependencies: + - blessings + - pyyaml + - repo: https://github.com/saltstack/mirrors-nox rev: v2020.8.22 hooks: @@ -1213,31 +1240,4 @@ repos: - -e - lint-tests-pre-commit - -- - - - repo: https://github.com/saltstack/mirrors-nox - rev: v2020.8.22 - hooks: - - id: nox - alias: check-docs - name: Check Docs - files: ^(salt/.*\.py|doc/ref/.*\.rst)$ - args: - - -e - - invoke-pre-commit - - -- - - docs.check - - - repo: https://github.com/saltstack/mirrors-nox - rev: v2020.8.22 - hooks: - - id: nox - alias: check-filemap - name: Check Filename Map Change Matching - files: ^tests/(filename_map\.yml|.*\.py)$ - pass_filenames: false - args: - - -e - - invoke-pre-commit - - -- - - filemap.check # <---- Pre-Commit ------------------------------------------------------------------------------------------------- diff --git a/noxfile.py b/noxfile.py index 6922af69864..603f3a50099 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1042,7 +1042,8 @@ def docs_man(session, compress, update, clean): os.chdir("..") -def _invoke(session): +@nox.session(name="invoke", python="3") +def invoke(session): """ Run invoke tasks """ @@ -1069,53 +1070,6 @@ def _invoke(session): session.run(*cmd) -@nox.session(name="invoke", python="3") -def invoke(session): - """ - Run an invoke target - """ - _invoke(session) - - -@nox.session(name="invoke-pre-commit", python=False) -def invoke_pre_commit(session): - """ - DO NOT CALL THIS NOX SESSION DIRECTLY - - This session is called from a pre-commit hook - """ - if "VIRTUAL_ENV" not in os.environ: - session.error( - "This should be running from within a virtualenv and " - "'VIRTUAL_ENV' was not found as an environment variable." - ) - if "pre-commit" not in os.environ["VIRTUAL_ENV"]: - session.error( - "This should be running from within a pre-commit virtualenv and " - "'VIRTUAL_ENV'({}) does not appear to be a pre-commit virtualenv.".format( - os.environ["VIRTUAL_ENV"] - ) - ) - from nox.virtualenv import VirtualEnv - - # Let's patch nox to make it run inside the pre-commit virtualenv - try: - session._runner.venv = VirtualEnv( # pylint: disable=unexpected-keyword-arg - os.environ["VIRTUAL_ENV"], - interpreter=session._runner.func.python, - reuse_existing=True, - venv=True, - ) - except TypeError: - # This is still nox-py2 - session._runner.venv = VirtualEnv( - os.environ["VIRTUAL_ENV"], - interpreter=session._runner.func.python, - reuse_existing=True, - ) - _invoke(session) - - @nox.session(name="changelog", python="3") @nox.parametrize("draft", [False, True]) def changelog(session, draft):