diff options
author | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2020-01-07 11:26:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-07 11:26:49 -0800 |
commit | 3c2d7976501bbe471fe4c8aea2d3d67807a65303 (patch) | |
tree | c62c485074d77522dd3efc9969ef40a8a4693f44 | |
parent | 4dc2a71af88d59b664a8bfdcfcc7acd6412bed76 (diff) | |
parent | 70c904d8c951df3faaa8ee3573c8bb9eb7203814 (diff) | |
download | isort-3c2d7976501bbe471fe4c8aea2d3d67807a65303.tar.gz |
Merge pull request #1084 from timothycrosley/feature/fix-issue-1083
Add support for automatically skipping over fifo files
-rw-r--r-- | isort/main.py | 7 | ||||
-rw-r--r-- | tests/test_main.py | 21 |
2 files changed, 28 insertions, 0 deletions
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 @@ -45,6 +46,12 @@ def is_python_file(path: str) -> bool: 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) except OSError: diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 00000000..300108a0 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,21 @@ +import os +import sys + +import pytest + +from isort import main + + +def test_is_python_file(): + 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") + + +@pytest.mark.skipif(sys.platform == "win32", reason="cannot create fifo file on Windows platform") +def test_is_python_file_fifo(tmpdir): + fifo_file = os.path.join(tmpdir, "fifo_file") + os.mkfifo(fifo_file) + assert not main.is_python_file(fifo_file) |