Skip to content

ssort ¤

Callable for ssort.

Functions:

  • run

    Run ssort.

run ¤

run(
    *files: str,
    diff: bool | None = None,
    check: bool | None = None
) -> int

Run ssort.

Parameters:

  • *files (str, default: () ) –

    Files to format.

  • diff (bool | None, default: None ) –

    Prints a diff of all changes ssort would make to a file.

  • check (bool | None, default: None ) –

    Check the file for unsorted statements. Returns 0 if nothing needs to be changed. Otherwise returns 1.

Source code in src/duty/callables/ssort.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@lazy(name="ssort")
def run(
    *files: str,
    diff: bool | None = None,
    check: bool | None = None,
) -> int:
    """Run `ssort`.

    Parameters:
        *files: Files to format.
        diff: Prints a diff of all changes ssort would make to a file.
        check: Check the file for unsorted statements. Returns 0 if nothing needs to be changed. Otherwise returns 1.
    """
    from ssort._main import main as ssort

    cli_args = list(files)

    if diff:
        cli_args.append("--diff")

    if check:
        cli_args.append("--check")

    old_sys_argv = sys.argv
    sys.argv = ["ssort*", *cli_args]
    try:
        return ssort()
    finally:
        sys.argv = old_sys_argv