MCPcopy
hub / github.com/huggingface/transformers / stylify

Function stylify

utils/check_copies.py:576–591  ·  view source on GitHub ↗

Applies the ruff part of our `make style` command to some code. This formats the code using `ruff format`. As `ruff` does not provide a python api this cannot be done on the fly. Args: code (`str`): The code to format. Returns: `str`: The formatted code.

(code: str)

Source from the content-addressed store, hash-verified

574
575
576def stylify(code: str) -> str:
577 """
578 Applies the ruff part of our `make style` command to some code. This formats the code using `ruff format`.
579 As `ruff` does not provide a python api this cannot be done on the fly.
580
581 Args:
582 code (`str`): The code to format.
583
584 Returns:
585 `str`: The formatted code.
586 """
587 has_indent = len(get_indent(code)) > 0
588 if has_indent:
589 code = f"class Bla:\n{code}"
590 formatted_code = run_ruff(code)
591 return formatted_code[len("class Bla:\n") :] if has_indent else formatted_code
592
593
594def check_codes_match(observed_code: str, theoretical_code: str) -> int | None:

Callers 1

is_copy_consistentFunction · 0.85

Calls 2

get_indentFunction · 0.70
run_ruffFunction · 0.70

Tested by

no test coverage detected