Skip to content

Commit 4558e0f

Browse files
committed
Initialize git for copied local directory (setuptools-scm)
1 parent d8a96a1 commit 4558e0f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

sphinx_polyversion/driver.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from inspect import isawaitable
1212
from logging import getLogger
1313
from pathlib import Path
14-
from subprocess import CalledProcessError
14+
from subprocess import PIPE, CalledProcessError
1515
from types import TracebackType
1616
from typing import (
1717
TYPE_CHECKING,
@@ -344,6 +344,19 @@ async def build_local(self) -> None:
344344
target.parent.mkdir(parents=True, exist_ok=True)
345345
if not target.exists():
346346
shutil.copy2(source, target, follow_symlinks=False)
347+
348+
# as .git is not copied, we have to initialize a dummy git repository
349+
# in the copied directory (for setuptools-scm)
350+
git_init_cmd = ("git", "init", "--initial-branch=dummy")
351+
with tempfile.SpooledTemporaryFile(max_size=1024) as f:
352+
process = await asyncio.create_subprocess_exec(
353+
*git_init_cmd, cwd=tmp, stdout=f, stderr=PIPE
354+
)
355+
out, err = await process.communicate()
356+
if process.returncode:
357+
raise CalledProcessError(
358+
process.returncode, " ".join(git_init_cmd), stderr=err
359+
)
347360
except CalledProcessError:
348361
logger.warning(
349362
"Could not list un-ignored files using git. Copying full working directory..."

sphinx_polyversion/git.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ async def _copy_tree(
220220
)
221221
out, err = await process.communicate()
222222
if process.returncode:
223-
raise CalledProcessError(process.returncode, " ".join(cmd), stderr=err)
223+
raise CalledProcessError(
224+
process.returncode, " ".join(git_init_cmd), stderr=err
225+
)
224226

225227

226228
async def file_exists(repo: Path, ref: GitRef, file: PurePath) -> bool:

0 commit comments

Comments
 (0)