Skip to content

Commit

Permalink
fix #957 - add subprocess timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Jan 5, 2024
1 parent 58b4021 commit fb9c040
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20240105_133254_subprocess_timeout_var.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Changed

- fix #957 - add subprocess timeout control env var
7 changes: 7 additions & 0 deletions docs/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ where the dist name normalization follows adapted PEP 503 semantics.

setuptools_scm parses the environment variable `SETUPTOOLS_SCM_OVERRIDES_FOR_${NORMALIZED_DIST_NAME}`
as a toml inline map to override the configuration data from `pyproject.toml`.

## subprocess timeouts

The environment variable `SETUPTOOLS_SCM_SUBPROCESS_TIMEOUT` allows to override the subprocess timeout.
The default is 40 seconds and should work for most needs. However, users with git lfs + windows reported
situations where this was not enough.

9 changes: 7 additions & 2 deletions src/setuptools_scm/_run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
# unfortunately github CI for windows sometimes needs
# up to 30 seconds to start a command

BROKEN_TIMEOUT: Final[int] = 40
def _get_timeout(env: Mapping[str, str]) -> int:
return int(env.get("SETUPTOOLS_SCM_SUBPROCESS_TIMEOUT") or 40)

BROKEN_TIMEOUT: Final[int] = _get_timeout(os.environ)

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

Expand Down Expand Up @@ -132,7 +135,7 @@ def run(
*,
strip: bool = True,
trace: bool = True,
timeout: int = BROKEN_TIMEOUT,
timeout: int | None = None,
check: bool = False,
) -> CompletedProcess:
if isinstance(cmd, str):
Expand All @@ -141,6 +144,8 @@ def run(
cmd = [os.fspath(x) for x in cmd]
cmd_4_trace = " ".join(map(_unsafe_quote_for_display, cmd))
log.debug("at %s\n $ %s ", cwd, cmd_4_trace)
if timeout is None:
timeout = BROKEN_TIMEOUT
res = subprocess.run(
cmd,
capture_output=True,
Expand Down

0 comments on commit fb9c040

Please sign in to comment.