$88 GRAYBYTE WORDPRESS FILE MANAGER $11

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/isort/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/isort//hooks.py
"""Defines a git hook to allow pre-commit warnings and errors about import order.

usage:
    exit_code = git_hook(strict=True|False, modify=True|False)
"""
import os
import subprocess  # nosec - Needed for hook
from pathlib import Path
from typing import List, Optional

from isort import Config, api, exceptions


def get_output(command: List[str]) -> str:
    """Run a command and return raw output

    :param str command: the command to run
    :returns: the stdout output of the command
    """
    result = subprocess.run(command, stdout=subprocess.PIPE, check=True)  # nosec - trusted input
    return result.stdout.decode()


def get_lines(command: List[str]) -> List[str]:
    """Run a command and return lines of output

    :param str command: the command to run
    :returns: list of whitespace-stripped lines output by command
    """
    stdout = get_output(command)
    return [line.strip() for line in stdout.splitlines()]


def git_hook(
    strict: bool = False,
    modify: bool = False,
    lazy: bool = False,
    settings_file: str = "",
    directories: Optional[List[str]] = None,
) -> int:
    """Git pre-commit hook to check staged files for isort errors

    :param bool strict - if True, return number of errors on exit,
        causing the hook to fail. If False, return zero so it will
        just act as a warning.
    :param bool modify - if True, fix the sources if they are not
        sorted properly. If False, only report result without
        modifying anything.
    :param bool lazy - if True, also check/fix unstaged files.
        This is useful if you frequently use ``git commit -a`` for example.
        If False, only check/fix the staged files for isort errors.
    :param str settings_file - A path to a file to be used as
                               the configuration file for this run.
        When settings_file is the empty string, the configuration file
        will be searched starting at the directory containing the first
        staged file, if any, and going upward in the directory structure.
    :param list[str] directories - A list of directories to restrict the hook to.

    :return number of errors if in strict mode, 0 otherwise.
    """
    # Get list of files modified and staged
    diff_cmd = ["git", "diff-index", "--cached", "--name-only", "--diff-filter=ACMRTUXB", "HEAD"]
    if lazy:
        diff_cmd.remove("--cached")
    if directories:
        diff_cmd.extend(directories)

    files_modified = get_lines(diff_cmd)
    if not files_modified:
        return 0

    errors = 0
    config = Config(
        settings_file=settings_file,
        settings_path=os.path.dirname(os.path.abspath(files_modified[0])),
    )
    for filename in files_modified:
        if filename.endswith(".py"):
            # Get the staged contents of the file
            staged_cmd = ["git", "show", f":{filename}"]
            staged_contents = get_output(staged_cmd)

            try:
                if not api.check_code_string(
                    staged_contents, file_path=Path(filename), config=config
                ):
                    errors += 1
                    if modify:
                        api.sort_file(filename, config=config)
            except exceptions.FileSkipped:  # pragma: no cover
                pass

    return errors if strict else 0

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
_vendored
--
17 Apr 2025 8.10 PM
root / root
0755
deprecated
--
14 Aug 2025 9.24 PM
root / root
0755
stdlibs
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
0.851 KB
17 Apr 2025 8.10 PM
root / root
0644
__main__.py
0.035 KB
17 Apr 2025 8.10 PM
root / root
0644
_version.py
0.07 KB
17 Apr 2025 8.10 PM
root / root
0644
api.py
25.508 KB
17 Apr 2025 8.10 PM
root / root
0644
comments.py
0.911 KB
17 Apr 2025 8.10 PM
root / root
0644
core.py
21.997 KB
17 Apr 2025 8.10 PM
root / root
0644
exceptions.py
6.895 KB
17 Apr 2025 8.10 PM
root / root
0644
files.py
1.552 KB
17 Apr 2025 8.10 PM
root / root
0644
format.py
5.354 KB
17 Apr 2025 8.10 PM
root / root
0644
hooks.py
3.26 KB
17 Apr 2025 8.10 PM
root / root
0644
identify.py
8.177 KB
17 Apr 2025 8.10 PM
root / root
0644
io.py
2.164 KB
17 Apr 2025 8.10 PM
root / root
0644
literal.py
3.626 KB
17 Apr 2025 8.10 PM
root / root
0644
logo.py
0.379 KB
17 Apr 2025 8.10 PM
root / root
0644
main.py
45.726 KB
17 Apr 2025 8.10 PM
root / root
0644
output.py
27.152 KB
17 Apr 2025 8.10 PM
root / root
0644
parse.py
24.738 KB
17 Apr 2025 8.10 PM
root / root
0644
place.py
5.05 KB
17 Apr 2025 8.10 PM
root / root
0644
profiles.py
2.094 KB
17 Apr 2025 8.10 PM
root / root
0644
py.typed
0 KB
17 Apr 2025 8.10 PM
root / root
0644
pylama_isort.py
1.277 KB
17 Apr 2025 8.10 PM
root / root
0644
sections.py
0.29 KB
17 Apr 2025 8.10 PM
root / root
0644
settings.py
34.75 KB
17 Apr 2025 8.10 PM
root / root
0644
setuptools_commands.py
2.243 KB
17 Apr 2025 8.10 PM
root / root
0644
sorting.py
4.409 KB
17 Apr 2025 8.10 PM
root / root
0644
utils.py
2.356 KB
17 Apr 2025 8.10 PM
root / root
0644
wrap.py
6.173 KB
17 Apr 2025 8.10 PM
root / root
0644
wrap_modes.py
13.251 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF