Skip to content

Commit 17efd6f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ad4b2b1 commit 17efd6f

File tree

2 files changed

+50
-44
lines changed

2 files changed

+50
-44
lines changed
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import os.path
35
from pathlib import Path
4-
from typing import Iterable, Iterator, Optional, Sequence, Set
6+
from typing import Iterable
7+
from typing import Iterator
8+
from typing import Optional
9+
from typing import Sequence
10+
from typing import Set
511

612
from pre_commit_hooks.util import added_files
713

814

9-
def lower_set(iterable: Iterable[str]) -> Set[str]:
15+
def lower_set(iterable: Iterable[str]) -> set[str]:
1016
return {x.lower() for x in iterable}
1117

1218

@@ -17,18 +23,18 @@ def parents(file: str) -> Iterator[str]:
1723
file = os.path.dirname(file)
1824

1925

20-
def directories_for(files: Set[str]) -> Set[str]:
26+
def directories_for(files: set[str]) -> set[str]:
2127
return {parent for file in files for parent in parents(file)}
2228

2329

2430
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
2531
ILLEGAL_NAMES = {
26-
"CON",
27-
"PRN",
28-
"AUX",
29-
"NUL",
30-
*(f"COM{i}" for i in range(1, 10)),
31-
*(f"LPT{i}" for i in range(1, 10)),
32+
'CON',
33+
'PRN',
34+
'AUX',
35+
'NUL',
36+
*(f'COM{i}' for i in range(1, 10)),
37+
*(f'LPT{i}' for i in range(1, 10)),
3238
}
3339

3440

@@ -40,25 +46,25 @@ def find_illegal_windows_names(filenames: Sequence[str]) -> int:
4046
for filename in relevant_files:
4147
root = Path(filename)
4248
while root.suffix:
43-
root = root.with_suffix("")
49+
root = root.with_suffix('')
4450
if root.name.lower() in lower_set(ILLEGAL_NAMES):
45-
print(f"Illegal name {filename}")
51+
print(f'Illegal name {filename}')
4652
retv = 1
4753

4854
return retv
4955

5056

51-
def main(argv: Optional[Sequence[str]] = None) -> int:
57+
def main(argv: Sequence[str] | None = None) -> int:
5258
parser = argparse.ArgumentParser()
5359
parser.add_argument(
54-
"filenames",
55-
nargs="*",
56-
help="Filenames pre-commit believes are changed.",
60+
'filenames',
61+
nargs='*',
62+
help='Filenames pre-commit believes are changed.',
5763
)
5864

5965
args = parser.parse_args(argv)
6066
return find_illegal_windows_names(args.filenames)
6167

6268

63-
if __name__ == "__main__":
69+
if __name__ == '__main__':
6470
exit(main())
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1+
from __future__ import annotations
2+
13
import sys
24

35
import pytest
46

5-
from pre_commit_hooks.check_illegal_windows_names import (
6-
find_illegal_windows_names,
7-
main,
8-
parents,
9-
)
7+
from pre_commit_hooks.check_illegal_windows_names import find_illegal_windows_names
8+
from pre_commit_hooks.check_illegal_windows_names import main
9+
from pre_commit_hooks.check_illegal_windows_names import parents
1010
from pre_commit_hooks.util import cmd_output
1111

1212
skip_win32 = pytest.mark.skipif(
13-
sys.platform == "win32",
14-
reason="case conflicts between directories and files",
13+
sys.platform == 'win32',
14+
reason='case conflicts between directories and files',
1515
)
1616

1717

1818
def test_parents():
19-
assert set(parents("a")) == set()
20-
assert set(parents("a/b")) == {"a"}
21-
assert set(parents("a/b/c")) == {"a/b", "a"}
22-
assert set(parents("a/b/c/d")) == {"a/b/c", "a/b", "a"}
19+
assert set(parents('a')) == set()
20+
assert set(parents('a/b')) == {'a'}
21+
assert set(parents('a/b/c')) == {'a/b', 'a'}
22+
assert set(parents('a/b/c/d')) == {'a/b/c', 'a/b', 'a'}
2323

2424

2525
def test_nothing_added(temp_git_dir):
2626
with temp_git_dir.as_cwd():
27-
assert find_illegal_windows_names(["f.py"]) == 0
27+
assert find_illegal_windows_names(['f.py']) == 0
2828

2929

3030
def test_adding_something(temp_git_dir):
3131
with temp_git_dir.as_cwd():
32-
temp_git_dir.join("f.py").write("print('hello world')")
33-
cmd_output("git", "add", "f.py")
32+
temp_git_dir.join('f.py').write("print('hello world')")
33+
cmd_output('git', 'add', 'f.py')
3434

35-
assert find_illegal_windows_names(["f.py"]) == 0
35+
assert find_illegal_windows_names(['f.py']) == 0
3636

3737

3838
@skip_win32 # pragma: win32 no cover
3939
def test_adding_something_with_illegal_filename(temp_git_dir):
4040
with temp_git_dir.as_cwd():
41-
temp_git_dir.join("CoM3.py").write("print('hello world')")
42-
cmd_output("git", "add", "CoM3.py")
41+
temp_git_dir.join('CoM3.py').write("print('hello world')")
42+
cmd_output('git', 'add', 'CoM3.py')
4343

44-
assert find_illegal_windows_names(["CoM3.py"]) == 1
44+
assert find_illegal_windows_names(['CoM3.py']) == 1
4545

4646

4747
@skip_win32 # pragma: win32 no cover
4848
def test_adding_files_with_illegal_directory(temp_git_dir):
4949
with temp_git_dir.as_cwd():
50-
temp_git_dir.mkdir("lpt2").join("x").write("foo")
51-
cmd_output("git", "add", "-A")
50+
temp_git_dir.mkdir('lpt2').join('x').write('foo')
51+
cmd_output('git', 'add', '-A')
5252

5353
assert find_illegal_windows_names([]) == 1
5454

5555

5656
@skip_win32 # pragma: win32 no cover
5757
def test_adding_files_with_illegal_deep_directories(temp_git_dir):
5858
with temp_git_dir.as_cwd():
59-
temp_git_dir.mkdir("x").mkdir("y").join("pRn").write("foo")
60-
cmd_output("git", "add", "-A")
59+
temp_git_dir.mkdir('x').mkdir('y').join('pRn').write('foo')
60+
cmd_output('git', 'add', '-A')
6161

6262
assert find_illegal_windows_names([]) == 1
6363

@@ -67,12 +67,12 @@ def test_integration(temp_git_dir):
6767
with temp_git_dir.as_cwd():
6868
assert main(argv=[]) == 0
6969

70-
temp_git_dir.join("f.py").write("print('hello world')")
71-
cmd_output("git", "add", "f.py")
70+
temp_git_dir.join('f.py').write("print('hello world')")
71+
cmd_output('git', 'add', 'f.py')
7272

73-
assert main(argv=["f.py"]) == 0
73+
assert main(argv=['f.py']) == 0
7474

75-
temp_git_dir.join("CON.py").write("print('hello world')")
76-
cmd_output("git", "add", "CON.py")
75+
temp_git_dir.join('CON.py').write("print('hello world')")
76+
cmd_output('git', 'add', 'CON.py')
7777

78-
assert main(argv=["CON.py"]) == 1
78+
assert main(argv=['CON.py']) == 1

0 commit comments

Comments
 (0)