Skip to content

Commit ebe9473

Browse files
authored
nox bump: build sdist in an isolated directory (#143)
hatch does not honor global gitignores or subdirectory .gitignores (it uses its own custom parsing) so some unwanted files can get into the release (see the latest antsibull-core for an example 😬). This adds another safeguard to ensure that unwanted files stay out of the sdist.
1 parent 577c75e commit ebe9473

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

noxfile.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
from __future__ import annotations
77

8+
import contextlib
89
import os
10+
import tempfile
911
from pathlib import Path
1012

1113
import nox
@@ -194,6 +196,27 @@ def check_no_modifications(session: nox.Session) -> None:
194196
)
195197

196198

199+
@contextlib.contextmanager
200+
def isolated_src(session: nox.Session):
201+
"""
202+
Create an isolated directory that only contains the latest git HEAD
203+
"""
204+
with tempfile.TemporaryDirectory() as _tmpdir:
205+
tmp = Path(_tmpdir)
206+
session.run(
207+
"git",
208+
"archive",
209+
"HEAD",
210+
f"--output={tmp / 'HEAD.tar'}",
211+
"--prefix=build/",
212+
external=True,
213+
)
214+
with session.chdir(tmp):
215+
session.run("tar", "-xf", "HEAD.tar", external=True)
216+
with session.chdir(tmp / "build"):
217+
yield
218+
219+
197220
@nox.session
198221
def bump(session: nox.Session):
199222
check_no_modifications(session)
@@ -247,7 +270,9 @@ def bump(session: nox.Session):
247270
version,
248271
external=True,
249272
)
250-
session.run("hatch", "build", "--clean")
273+
dist = Path.cwd() / "dist"
274+
with isolated_src(session):
275+
session.run("hatch", "build", "--clean", str(dist))
251276

252277

253278
@nox.session

0 commit comments

Comments
 (0)