MCPcopy
hub / github.com/psf/black / main

Function main

src/black/__init__.py:538–760  ·  view source on GitHub ↗

The uncompromising code formatter.

(
    ctx: click.Context,
    code: str | None,
    line_length: int,
    target_version: list[TargetVersion],
    check: bool,
    diff: bool,
    line_ranges: Sequence[str],
    color: bool,
    fast: bool,
    pyi: bool,
    ipynb: bool,
    python_cell_magics: Sequence[str],
    skip_source_first_line: bool,
    skip_string_normalization: bool,
    skip_magic_trailing_comma: bool,
    preview: bool,
    unstable: bool,
    enable_unstable_feature: list[Preview],
    quiet: bool,
    verbose: bool,
    required_version: str | None,
    include: Pattern[str],
    exclude: Pattern[str] | None,
    extend_exclude: Pattern[str] | None,
    force_exclude: Pattern[str] | None,
    stdin_filename: str | None,
    workers: int | None,
    src: tuple[str, ...],
    config: str | None,
    no_cache: bool,
)

Source from the content-addressed store, hash-verified

536)
537@click.pass_context
538def main(
539 ctx: click.Context,
540 code: str | None,
541 line_length: int,
542 target_version: list[TargetVersion],
543 check: bool,
544 diff: bool,
545 line_ranges: Sequence[str],
546 color: bool,
547 fast: bool,
548 pyi: bool,
549 ipynb: bool,
550 python_cell_magics: Sequence[str],
551 skip_source_first_line: bool,
552 skip_string_normalization: bool,
553 skip_magic_trailing_comma: bool,
554 preview: bool,
555 unstable: bool,
556 enable_unstable_feature: list[Preview],
557 quiet: bool,
558 verbose: bool,
559 required_version: str | None,
560 include: Pattern[str],
561 exclude: Pattern[str] | None,
562 extend_exclude: Pattern[str] | None,
563 force_exclude: Pattern[str] | None,
564 stdin_filename: str | None,
565 workers: int | None,
566 src: tuple[str, ...],
567 config: str | None,
568 no_cache: bool,
569) -> None:
570 """The uncompromising code formatter."""
571 ctx.ensure_object(dict)
572
573 assert sys.version_info >= (3, 10), "Black requires Python 3.10+"
574 if sys.version_info[:3] == (3, 12, 5):
575 out(
576 "Python 3.12.5 has a memory safety issue that can cause Black's "
577 "AST safety checks to fail. "
578 "Please upgrade to Python 3.12.6 or downgrade to Python 3.12.4"
579 )
580 ctx.exit(1)
581
582 if src and code is not None:
583 out(
584 main.get_usage(ctx)
585 + "\n\n'SRC' and 'code' cannot be passed simultaneously."
586 )
587 ctx.exit(1)
588 if not src and code is None:
589 out(main.get_usage(ctx) + "\n\nOne of 'SRC' or 'code' is required.")
590 ctx.exit(1)
591
592 # It doesn't do anything if --unstable is also passed, so just allow it.
593 if enable_unstable_feature and not (preview or unstable):
594 out(
595 main.get_usage(ctx)

Callers 1

patched_mainFunction · 0.70

Calls 15

outFunction · 0.90
find_project_rootFunction · 0.90
find_user_pyproject_tomlFunction · 0.90
errFunction · 0.90
ModeClass · 0.90
parse_line_rangesFunction · 0.90
ReportClass · 0.90
reformat_manyFunction · 0.90
reformat_codeFunction · 0.85
get_sourcesFunction · 0.85

Tested by

no test coverage detected