Skip to content

Commit 72ffa18

Browse files
c0llab0rat0rntninja
authored andcommitted
Inline shim enum.auto; document shims for os.fwalk and os.O_DIRECTORY
1 parent 23a2d51 commit 72ffa18

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

ipfshttpclient/filescanner.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
re_pattern_t = re_pattern_type = type(re.compile(""))
2222

2323

24-
enum_auto = enum.auto
25-
26-
27-
O_DIRECTORY = getattr(os, "O_DIRECTORY", 0) # type: int
24+
# Windows does not have os.O_DIRECTORY
25+
O_DIRECTORY: int = getattr(os, "O_DIRECTORY", 0)
2826

2927

3028
# Neither Windows nor MacOS have os.fwalk even through Python 3.9
@@ -423,8 +421,8 @@ def matcher_from_spec(spec: match_spec_t[ty.AnyStr], *, # type: ignore[misc] #
423421
from .filescanner_ty import FSNodeType, FSNodeEntry
424422
else:
425423
class FSNodeType(enum.Enum):
426-
FILE = enum_auto()
427-
DIRECTORY = enum_auto()
424+
FILE = enum.auto()
425+
DIRECTORY = enum.auto()
428426

429427
FSNodeEntry = ty.NamedTuple("FSNodeEntry", [
430428
("type", FSNodeType),

test/functional/test_files.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import conftest
1313

1414

15-
O_DIRECTORY = getattr(os, "O_DIRECTORY", 0) # type: int
15+
# Windows does not have os.O_DIRECTORY
16+
O_DIRECTORY: int = getattr(os, "O_DIRECTORY", 0)
1617

1718

1819
### test_add_multiple_from_list
@@ -263,15 +264,15 @@ def test_add_filepattern_from_dirname(client, cleanup_pins):
263264
reason="No point in disabling os.fwalk if it isn't actually supported")
264265
def test_add_filepattern_from_dirname_nofwalk(client, cleanup_pins, monkeypatch):
265266
monkeypatch.setattr(ipfshttpclient.filescanner, "HAVE_FWALK", False)
266-
267+
267268
res = client.add(FAKE_DIR_PATH, pattern=FAKE_DIR_FNPATTERN1)
268269
assert conftest.sort_by_key(res) == conftest.sort_by_key(FAKE_DIR_FNPATTERN1_HASH)
269270

270271

271272
@pytest.mark.skipif(not ipfshttpclient.filescanner.HAVE_FWALK,
272273
reason="Passing directory as file descriptor requires os.fwalk")
273274
def test_add_filepattern_from_dirfd(client, cleanup_pins):
274-
fd = os.open(str(FAKE_DIR_PATH), os.O_RDONLY | O_DIRECTORY) # type: int
275+
fd: int = os.open(str(FAKE_DIR_PATH), os.O_RDONLY | O_DIRECTORY)
275276
try:
276277
res = client.add(fd, pattern=FAKE_DIR_FNPATTERN1)
277278
finally:
@@ -288,7 +289,7 @@ def test_add_filepattern_from_dirname_recursive(client, cleanup_pins):
288289
reason="No point in disabling os.fwalk if it isn't actually supported")
289290
def test_add_filepattern_from_dirname_recursive_nofwalk(client, cleanup_pins, monkeypatch):
290291
monkeypatch.setattr(ipfshttpclient.filescanner, "HAVE_FWALK", False)
291-
292+
292293
res = client.add(FAKE_DIR_PATH, pattern=FAKE_DIR_FNPATTERN1, recursive=True)
293294
assert conftest.sort_by_key(res) == conftest.sort_by_key(FAKE_DIR_FNPATTERN1_RECURSIVE_HASH)
294295

@@ -297,9 +298,9 @@ def test_add_filepattern_from_dirname_recursive_nofwalk(client, cleanup_pins, mo
297298
reason="Opening directory FDs does not work on Windows")
298299
def test_add_filepattern_from_dirfd_recursive_nofwalk(client, cleanup_pins, monkeypatch):
299300
monkeypatch.setattr(ipfshttpclient.filescanner, "HAVE_FWALK", False)
300-
301+
301302
with pytest.raises(NotImplementedError):
302-
fd = os.open(str(FAKE_DIR_PATH), os.O_RDONLY | O_DIRECTORY) # type: int
303+
fd: int = os.open(str(FAKE_DIR_PATH), os.O_RDONLY | O_DIRECTORY)
303304
try:
304305
client.add(fd, pattern=FAKE_DIR_FNPATTERN1, recursive=True)
305306
finally:
@@ -309,7 +310,7 @@ def test_add_filepattern_from_dirfd_recursive_nofwalk(client, cleanup_pins, monk
309310
@pytest.mark.skipif(not ipfshttpclient.filescanner.HAVE_FWALK,
310311
reason="Passing directory as file descriptor requires os.fwalk")
311312
def test_add_filepattern_from_dirfd_recursive(client, cleanup_pins):
312-
fd = os.open(str(FAKE_DIR_PATH), os.O_RDONLY | O_DIRECTORY) # type: int
313+
fd: int = os.open(str(FAKE_DIR_PATH), os.O_RDONLY | O_DIRECTORY)
313314
try:
314315
res = client.add(fd, pattern=FAKE_DIR_FNPATTERN1, recursive=True)
315316
finally:
@@ -327,7 +328,7 @@ def test_add_filepattern_from_dirname_recursive_binary(client, cleanup_pins):
327328
reason="No point in disabling os.fwalk if it isn't actually supported")
328329
def test_add_filepattern_from_dirname_recursive_nofwalk_binary(client, cleanup_pins, monkeypatch):
329330
monkeypatch.setattr(ipfshttpclient.filescanner, "HAVE_FWALK", False)
330-
331+
331332
res = client.add(os.fsencode(str(FAKE_DIR_PATH)),
332333
pattern=os.fsencode(FAKE_DIR_FNPATTERN1), recursive=True)
333334
assert conftest.sort_by_key(res) == conftest.sort_by_key(FAKE_DIR_FNPATTERN1_RECURSIVE_HASH)

0 commit comments

Comments
 (0)