Skip to content

Commit a05ba42

Browse files
committed
Initialize git in copied revisions to resolve setuptools-scm issues.
Fixes #26. The following error message arises when using `setuptools-scm`: ``` LookupError: setuptools-scm was unable to detect version for ... Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work. For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj Alternatively, set the version with the environment variable SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${NORMALIZED_DIST_NAME} as described in https://setuptools-scm.readthedocs.io/en/latest/config. [end of output] ``` This can be resolved by creating an empty git respository.
1 parent 86cfef8 commit a05ba42

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sphinx_polyversion/git.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ async def _copy_tree(
202202
"""
203203
# retrieve commit contents as tar archive
204204
cmd = ("git", "archive", "--format", "tar", ref)
205+
git_init_cmd = ("git", "init", "--initial-branch=dummy")
205206
with tempfile.SpooledTemporaryFile(max_size=buffer_size) as f:
206207
process = await asyncio.create_subprocess_exec(
207208
*cmd, cwd=repo, stdout=f, stderr=PIPE
@@ -213,6 +214,13 @@ async def _copy_tree(
213214
f.seek(0)
214215
with tarfile.open(fileobj=f) as tf:
215216
tf.extractall(str(dest))
217+
# initialize dummy git repository in copied directory (required for setuptools-scm)
218+
process = await asyncio.create_subprocess_exec(
219+
*git_init_cmd, cwd=str(dest), stdout=f, stderr=PIPE
220+
)
221+
out, err = await process.communicate()
222+
if process.returncode:
223+
raise CalledProcessError(process.returncode, " ".join(cmd), stderr=err)
216224

217225

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

0 commit comments

Comments
 (0)