Skip to content

Commit b418135

Browse files
committed
file searching improvements
1 parent 71f3143 commit b418135

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

dan/core/find.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
from dan.core.pathlib import Path
44
import re
5+
import typing as t
56

67
include_paths_lookup = [
78
'~/.local/include',
@@ -32,15 +33,14 @@ def find_file(expr, paths) -> Path:
3233
if r.match(file):
3334
return Path(root) / file
3435

35-
def find_files(expr, paths) -> list[Path]:
36+
37+
def find_files(expr, paths) -> t.Generator[Path, None, None]:
3638
r = re.compile(expr)
37-
files = list()
3839
for path in paths:
3940
for root, _, _files in os.walk(os.path.expandvars(os.path.expanduser(path))):
4041
for file in _files:
4142
if r.match(file):
42-
files.append(Path(root) / file)
43-
return files
43+
yield (Path(root) / file)
4444

4545

4646
def find_include_path(name, paths: list[str|Path] = None) -> Path:
@@ -66,12 +66,12 @@ def find_executable(name, paths: list[str|Path] = None, default_paths=True) -> P
6666
paths.extend(programs_paths_lookup)
6767
return find_file(expr, paths)
6868

69-
def find_executables(name, paths: list[str|Path] = None, default_paths=True) -> list[Path]:
69+
def find_executables(name, paths: list[str|Path] = None, default_paths=True) -> t.Generator[Path, None, None]:
7070
paths = paths or list()
7171
if os.name == 'posix':
7272
expr = name + '$'
7373
elif os.name == 'nt':
7474
expr = f'{name}.exe$'
7575
if default_paths:
7676
paths.extend(programs_paths_lookup)
77-
return find_files(expr, paths)
77+
yield from find_files(expr, paths)

dan/pkgconfig/package.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313
from dan.core.version import Version, VersionSpec
1414
from dan.cxx.targets import CXXTarget, Library
1515

16+
import typing as t
17+
1618

1719
class MissingPackage(RuntimeError):
1820
def __init__(self, name) -> None:
1921
super().__init__(f'package {name} not found')
2022

2123

2224
def find_pkg_config(name, paths=list()) -> Path:
23-
return find_file(fr'.*{name}\.pc$', ['$PKG_CONFIG_PATH', *paths, *library_paths_lookup])
25+
return find_file(fr'.*{name}\.pc$', [*paths, '$PKG_CONFIG_PATH', *library_paths_lookup])
26+
2427

25-
def find_pkg_configs(name, paths=list()) -> Path:
26-
return find_files(fr'.*{name}\.pc$', ['$PKG_CONFIG_PATH', *paths, *library_paths_lookup])
28+
def find_pkg_configs(name, paths=list()) -> t.Generator[Path, None, None]:
29+
yield from find_files(fr'.*{name}\.pc$', [*paths, '$PKG_CONFIG_PATH', *library_paths_lookup])
2730

2831

2932
def has_package(name, paths=list()):

0 commit comments

Comments
 (0)