From 4384bc058968a83e095ae0ce14fafbff90fa4c1a Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 7 Jan 2020 10:28:59 -0800 Subject: Add support for automatically skipping over fifo files --- isort/main.py | 7 +++++++ tests/test_main.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/test_main.py diff --git a/isort/main.py b/isort/main.py index 5d48f84c..b9b86687 100644 --- a/isort/main.py +++ b/isort/main.py @@ -4,6 +4,7 @@ import functools import glob import os import re +import stat import sys from pathlib import Path from typing import Any, Dict, Iterable, Iterator, List, MutableMapping, Optional, Sequence @@ -44,6 +45,12 @@ def is_python_file(path: str) -> bool: if path.endswith("~"): return False + try: + if stat.S_ISFIFO(os.stat(path).st_mode): + return False + except OSError: + pass + try: with open(path, "rb") as fp: line = fp.readline(100) diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 00000000..b3e50b54 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,17 @@ +import os +from isort import main + + +def test_is_python_file(tmpdir): + assert main.is_python_file("file.py") + assert main.is_python_file("file.pyi") + assert main.is_python_file("file.pyx") + assert not main.is_python_file("file.pyc") + assert not main.is_python_file("file.txt") + + fifo_file = os.path.join(tmpdir, "fifo_file") + os.mkfifo(fifo_file) + assert not main.is_python_file(fifo_file) + + + -- cgit v1.2.1