mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Switch to the remove-import-headers pre-commit hook
This commit is contained in:
parent
e3acc17ffc
commit
7e7cbf3ffa
3 changed files with 4 additions and 67 deletions
|
@ -1080,18 +1080,10 @@ repos:
|
||||||
salt/client/ssh/ssh_py_shim.py
|
salt/client/ssh/ssh_py_shim.py
|
||||||
)$
|
)$
|
||||||
|
|
||||||
- repo: https://github.com/saltstack/mirrors-nox
|
- repo: https://github.com/saltstack/pre-commit-remove-import-headers
|
||||||
rev: v2020.8.22
|
rev: 1.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: nox
|
- id: remove-import-headers
|
||||||
alias: remove-import-comments
|
|
||||||
name: Remove import comments
|
|
||||||
files: .*\.py$
|
|
||||||
args:
|
|
||||||
- -e
|
|
||||||
- invoke-pre-commit
|
|
||||||
- --
|
|
||||||
- imports.remove-comments
|
|
||||||
|
|
||||||
- repo: https://github.com/timothycrosley/isort
|
- repo: https://github.com/timothycrosley/isort
|
||||||
rev: "1e78a9acf3110e1f9721feb591f89a451fc9876a"
|
rev: "1e78a9acf3110e1f9721feb591f89a451fc9876a"
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
from invoke import Collection # pylint: disable=3rd-party-module-not-gated
|
from invoke import Collection # pylint: disable=3rd-party-module-not-gated
|
||||||
|
|
||||||
from . import docs, filemap, imports, loader
|
from . import docs, filemap, loader
|
||||||
|
|
||||||
ns = Collection()
|
ns = Collection()
|
||||||
ns.add_collection(Collection.from_module(docs, name="docs"), name="docs")
|
ns.add_collection(Collection.from_module(docs, name="docs"), name="docs")
|
||||||
ns.add_collection(Collection.from_module(loader, name="loader"), name="loader")
|
ns.add_collection(Collection.from_module(loader, name="loader"), name="loader")
|
||||||
ns.add_collection(Collection.from_module(filemap, name="filemap"), name="filemap")
|
ns.add_collection(Collection.from_module(filemap, name="filemap"), name="filemap")
|
||||||
ns.add_collection(Collection.from_module(imports, name="imports"), name="imports")
|
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
"""
|
|
||||||
tasks.imports
|
|
||||||
~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Imports related tasks
|
|
||||||
"""
|
|
||||||
|
|
||||||
import pathlib
|
|
||||||
import re
|
|
||||||
|
|
||||||
from invoke import task # pylint: disable=3rd-party-module-not-gated
|
|
||||||
from tasks import utils
|
|
||||||
|
|
||||||
CODE_DIR = pathlib.Path(__file__).resolve().parent.parent
|
|
||||||
SALT_CODE_DIR = CODE_DIR / "salt"
|
|
||||||
|
|
||||||
|
|
||||||
@task(iterable=["files"], positional=["files"])
|
|
||||||
def remove_comments(ctx, files):
|
|
||||||
"""
|
|
||||||
Remove import comments, 'Import Python libs', 'Import salt libs', etc
|
|
||||||
"""
|
|
||||||
# CD into Salt's repo root directory
|
|
||||||
ctx.cd(CODE_DIR)
|
|
||||||
|
|
||||||
# Unfortunately invoke does not support nargs.
|
|
||||||
# We migth have been passed --files="foo.py bar.py"
|
|
||||||
# Turn that into a list of paths
|
|
||||||
_files = []
|
|
||||||
for path in files:
|
|
||||||
if not path:
|
|
||||||
continue
|
|
||||||
_files.extend(path.split())
|
|
||||||
if not _files:
|
|
||||||
utils.exit_invoke(0)
|
|
||||||
|
|
||||||
_files = [
|
|
||||||
pathlib.Path(fname).resolve() for fname in _files if fname.endswith(".py")
|
|
||||||
]
|
|
||||||
|
|
||||||
fixes = 0
|
|
||||||
exitcode = 0
|
|
||||||
comments_regex = re.compile(r"^# ([I|i])mports? .*(([L|l])ibs?)?\n", re.MULTILINE)
|
|
||||||
for path in _files:
|
|
||||||
contents = path.read_text()
|
|
||||||
fixed = comments_regex.sub("", contents)
|
|
||||||
if fixed == contents:
|
|
||||||
continue
|
|
||||||
fixes += 1
|
|
||||||
exitcode = 1
|
|
||||||
path.write_text(fixed)
|
|
||||||
if exitcode:
|
|
||||||
utils.error("Fixed {} files", fixes)
|
|
||||||
utils.exit_invoke(exitcode)
|
|
Loading…
Add table
Reference in a new issue