Skip to content

Commit 8440626

Browse files
Refactor: generate instead of list files to copy.
1 parent a3de3d1 commit 8440626

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

sphinx_polyversion/driver.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,9 @@ async def build_local(self) -> None:
337337
# copy source files
338338
logger.info("Copying source files (except for files ignored by git)...")
339339
try:
340-
files = await get_unignored_files(self.root)
341-
for filename in files:
342-
source = self.root / filename
343-
target = path / filename
340+
async for file in get_unignored_files(self.root):
341+
source = self.root / file
342+
target = path / file
344343
target.parent.mkdir(parents=True, exist_ok=True)
345344
if source.exists() and not target.exists():
346345
shutil.copy2(source, target, follow_symlinks=False)

sphinx_polyversion/git.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ async def file_exists(repo: Path, ref: GitRef, file: PurePath) -> bool:
260260
return rc == 0
261261

262262

263-
async def get_unignored_files(directory: Path) -> list[Path]:
263+
async def get_unignored_files(directory: Path) -> AsyncGenerator[Path, None]:
264264
"""
265265
List all unignored files in the directory.
266266
@@ -271,7 +271,7 @@ async def get_unignored_files(directory: Path) -> list[Path]:
271271
272272
Returns
273273
-------
274-
Path
274+
AsyncGenerator[Path,]
275275
The paths to all un-ignored files in the directory (recursive)
276276
277277
"""
@@ -284,8 +284,8 @@ async def get_unignored_files(directory: Path) -> list[Path]:
284284
)
285285
process = await asyncio.create_subprocess_exec(*cmd, cwd=directory, stdout=PIPE)
286286
out, err = await process.communicate()
287-
files = out.decode().split("\n")
288-
return [Path(path.strip()) for path in files]
287+
for line in out.decode().splitlines():
288+
yield Path(line.strip())
289289

290290

291291
# -- VersionProvider API -----------------------------------------------------

0 commit comments

Comments
 (0)