diff mbox series

[scarthgap,v2,1/2] python3-setuptools-scm: add subprocess timeout control env var

Message ID 20250218133736.2113804-1-hongxu.jia@windriver.com
State Rejected
Delegated to: Steve Sakoman
Headers show
Series [scarthgap,v2,1/2] python3-setuptools-scm: add subprocess timeout control env var | expand

Commit Message

Hongxu Jia Feb. 18, 2025, 1:37 p.m. UTC
Backport patch from upstream to add subprocess timeout control env var

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 .../0001-fix-957-add-subprocess-timeout.patch | 78 +++++++++++++++++++
 .../python/python3-setuptools-scm_8.0.4.bb    |  4 +
 2 files changed, 82 insertions(+)
 create mode 100644 meta/recipes-devtools/python/python3-setuptools-scm/0001-fix-957-add-subprocess-timeout.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/python/python3-setuptools-scm/0001-fix-957-add-subprocess-timeout.patch b/meta/recipes-devtools/python/python3-setuptools-scm/0001-fix-957-add-subprocess-timeout.patch
new file mode 100644
index 0000000000..1af1ea0334
--- /dev/null
+++ b/meta/recipes-devtools/python/python3-setuptools-scm/0001-fix-957-add-subprocess-timeout.patch
@@ -0,0 +1,78 @@ 
+From 2ac4f084def6db53b454b967b062bed2f945aa03 Mon Sep 17 00:00:00 2001
+From: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de>
+Date: Fri, 5 Jan 2024 13:34:37 +0100
+Subject: [PATCH] fix #957 - add subprocess timeout
+
+Upstream-Status: Backport [https://github.com/pypa/setuptools-scm/commit/2ac4f084def6db53b454b967b062bed2f945aa03]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ changelog.d/20240105_133254_subprocess_timeout_var.md |  4 ++++
+ docs/overrides.md                                     |  7 +++++++
+ src/setuptools_scm/_run_cmd.py                        | 11 +++++++++--
+ 3 files changed, 20 insertions(+), 2 deletions(-)
+ create mode 100644 changelog.d/20240105_133254_subprocess_timeout_var.md
+
+diff --git a/changelog.d/20240105_133254_subprocess_timeout_var.md b/changelog.d/20240105_133254_subprocess_timeout_var.md
+new file mode 100644
+index 0000000..78ecab2
+--- /dev/null
++++ b/changelog.d/20240105_133254_subprocess_timeout_var.md
+@@ -0,0 +1,4 @@
++
++### Changed
++
++- fix #957 - add subprocess timeout control env var
+diff --git a/docs/overrides.md b/docs/overrides.md
+index 5114a84..22d285e 100644
+--- a/docs/overrides.md
++++ b/docs/overrides.md
+@@ -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.
++
+diff --git a/src/setuptools_scm/_run_cmd.py b/src/setuptools_scm/_run_cmd.py
+index 3dfbda5..a64f904 100644
+--- a/src/setuptools_scm/_run_cmd.py
++++ b/src/setuptools_scm/_run_cmd.py
+@@ -25,7 +25,12 @@ else:
+ # 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")
+ 
+@@ -132,7 +137,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):
+@@ -141,6 +146,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,
+-- 
+2.25.1
+
diff --git a/meta/recipes-devtools/python/python3-setuptools-scm_8.0.4.bb b/meta/recipes-devtools/python/python3-setuptools-scm_8.0.4.bb
index 64b5050c3b..bed1039e20 100644
--- a/meta/recipes-devtools/python/python3-setuptools-scm_8.0.4.bb
+++ b/meta/recipes-devtools/python/python3-setuptools-scm_8.0.4.bb
@@ -10,6 +10,10 @@  SRC_URI[sha256sum] = "b5f43ff6800669595193fd09891564ee9d1d7dcb196cab4b2506d53a2e
 
 inherit pypi python_setuptools_build_meta
 
+SRC_URI += " \
+    file://0001-fix-957-add-subprocess-timeout.patch \
+"
+
 UPSTREAM_CHECK_REGEX = "scm-(?P<pver>.*)\.tar"
 
 DEPENDS += "python3-tomli-native python3-packaging-native python3-typing-extensions-native"