Skip to content

Commit fb9c040

Browse files
fix pypa#957 - add subprocess timeout
1 parent 58b4021 commit fb9c040

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
### Changed
3+
4+
- fix #957 - add subprocess timeout control env var

docs/overrides.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ where the dist name normalization follows adapted PEP 503 semantics.
1414

1515
setuptools_scm parses the environment variable `SETUPTOOLS_SCM_OVERRIDES_FOR_${NORMALIZED_DIST_NAME}`
1616
as a toml inline map to override the configuration data from `pyproject.toml`.
17+
18+
## subprocess timeouts
19+
20+
The environment variable `SETUPTOOLS_SCM_SUBPROCESS_TIMEOUT` allows to override the subprocess timeout.
21+
The default is 40 seconds and should work for most needs. However, users with git lfs + windows reported
22+
situations where this was not enough.
23+

src/setuptools_scm/_run_cmd.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
# unfortunately github CI for windows sometimes needs
2626
# up to 30 seconds to start a command
2727

28-
BROKEN_TIMEOUT: Final[int] = 40
28+
def _get_timeout(env: Mapping[str, str]) -> int:
29+
return int(env.get("SETUPTOOLS_SCM_SUBPROCESS_TIMEOUT") or 40)
30+
31+
BROKEN_TIMEOUT: Final[int] = _get_timeout(os.environ)
2932

3033
log = _log.log.getChild("run_cmd")
3134

@@ -132,7 +135,7 @@ def run(
132135
*,
133136
strip: bool = True,
134137
trace: bool = True,
135-
timeout: int = BROKEN_TIMEOUT,
138+
timeout: int | None = None,
136139
check: bool = False,
137140
) -> CompletedProcess:
138141
if isinstance(cmd, str):
@@ -141,6 +144,8 @@ def run(
141144
cmd = [os.fspath(x) for x in cmd]
142145
cmd_4_trace = " ".join(map(_unsafe_quote_for_display, cmd))
143146
log.debug("at %s\n $ %s ", cwd, cmd_4_trace)
147+
if timeout is None:
148+
timeout = BROKEN_TIMEOUT
144149
res = subprocess.run(
145150
cmd,
146151
capture_output=True,

0 commit comments

Comments
 (0)