MCPcopy
hub / github.com/PyCQA/isort / check_file

Function check_file

isort/api.py:303–344  ·  view source on GitHub ↗

Checks any imports within the provided file, returning `False` if any unsorted or incorrectly imports are found or `True` if no problems are identified. - **filename**: The name or Path of the file to check. - **show_diff**: If `True` the changes that need to be done will be printed to

(
    filename: str | Path,
    show_diff: bool | TextIO = False,
    config: Config = DEFAULT_CONFIG,
    file_path: Path | None = None,
    disregard_skip: bool = True,
    extension: str | None = None,
    **config_kwargs: Any,
)

Source from the content-addressed store, hash-verified

301
302
303def check_file(
304 filename: str | Path,
305 show_diff: bool | TextIO = False,
306 config: Config = DEFAULT_CONFIG,
307 file_path: Path | None = None,
308 disregard_skip: bool = True,
309 extension: str | None = None,
310 **config_kwargs: Any,
311) -> bool:
312 """Checks any imports within the provided file, returning `False` if any unsorted or
313 incorrectly imports are found or `True` if no problems are identified.
314
315 - **filename**: The name or Path of the file to check.
316 - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
317 TextIO stream is provided results will be written to it, otherwise no diff will be computed.
318 - **config**: The config object to use when sorting imports.
319 - **file_path**: The disk location where the code string was pulled from.
320 - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
321 - **extension**: The file extension that contains imports. Defaults to filename extension or py.
322 - ****config_kwargs**: Any config modifications.
323 """
324 file_config: Config = config
325
326 if "config_trie" in config_kwargs:
327 config_trie = config_kwargs.pop("config_trie", None)
328 if config_trie:
329 config_info = config_trie.search(filename)
330 if config.verbose:
331 print(f"{config_info[0]} used for file {filename}")
332
333 file_config = Config(**config_info[1])
334
335 with io.File.read(filename) as source_file:
336 return check_stream(
337 source_file.stream,
338 show_diff=show_diff,
339 extension=extension,
340 config=file_config,
341 file_path=file_path or source_file.path,
342 disregard_skip=disregard_skip,
343 **config_kwargs,
344 )
345
346
347@contextlib.contextmanager

Callers

nothing calls this directly

Calls 4

ConfigClass · 0.85
check_streamFunction · 0.85
searchMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…