|
11 | 11 | from inspect import isawaitable |
12 | 12 | from logging import getLogger |
13 | 13 | from pathlib import Path |
| 14 | +from subprocess import CalledProcessError |
14 | 15 | from types import TracebackType |
15 | 16 | from typing import ( |
16 | 17 | TYPE_CHECKING, |
|
33 | 34 |
|
34 | 35 | from sphinx_polyversion.builder import Builder, BuildError |
35 | 36 | from sphinx_polyversion.environment import Environment |
| 37 | +from sphinx_polyversion.git import get_unignored_files |
36 | 38 | from sphinx_polyversion.json import GLOBAL_ENCODER, Encoder, JSONable |
37 | 39 | from sphinx_polyversion.utils import shift_path |
38 | 40 |
|
@@ -333,8 +335,20 @@ async def build_local(self) -> None: |
333 | 335 | with tempfile.TemporaryDirectory() as tmp: |
334 | 336 | path = Path(tmp) |
335 | 337 | # copy source files |
336 | | - logger.info("Copying source files...") |
337 | | - shutil.copytree(self.root, path, symlinks=True, dirs_exist_ok=True) |
| 338 | + logger.info("Copying source files (except for files ignored by git)...") |
| 339 | + try: |
| 340 | + files = await get_unignored_files(self.root) |
| 341 | + for filename in files: |
| 342 | + source = self.root / filename |
| 343 | + target = path / filename |
| 344 | + target.parent.mkdir(parents=True, exist_ok=True) |
| 345 | + if not target.exists(): |
| 346 | + shutil.copy2(source, target, follow_symlinks=False) |
| 347 | + except CalledProcessError: |
| 348 | + logger.warning( |
| 349 | + "Could not list un-ignored files using git. Copying full working directory..." |
| 350 | + ) |
| 351 | + shutil.copytree(self.root, path, symlinks=True, dirs_exist_ok=True) |
338 | 352 | # setup build environment (e.g. poetry/pip venv) |
339 | 353 | async with await self.init_environment(path, rev) as env: |
340 | 354 | # construct metadata to pass to the build process |
|
0 commit comments