Skip to content

Commit 87e61c1

Browse files
authored
fix(python): bump requires-python, portable sed, and signal forwarding (#1005)
* fix(python): bump requires-python, portable sed, and signal forwarding - Bump requires-python to >=3.8 and drop importlib_metadata fallback since Python 3.6/3.7 are long EOL - Replace GNU-only sed -i with redirect+mv pattern for macOS compat - Forward SIGTERM/SIGHUP to child process using subprocess.Popen to prevent orphaned processes on container shutdown Fixes #1004 Signed-off-by: Marc Nuri <marc@marcnuri.com> * fix(python): guard SIGHUP for Windows and handle send_signal race - Gate SIGHUP registration behind hasattr check since the constant is Unix-only and would crash the wrapper on Windows - Catch OSError in send_signal calls to handle the race where the child exits between signal arrival and forwarding Signed-off-by: Marc Nuri <marc@marcnuri.com> --------- Signed-off-by: Marc Nuri <marc@marcnuri.com>
1 parent 4026859 commit 87e61c1

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

build/python.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ CLEAN_TARGETS += ./python/dist ./python/*.egg-info
55
.PHONY: python-publish
66
python-publish: ## Publish the python packages
77
cd ./python && \
8-
sed -i "s/version = \".*\"/version = \"$(GIT_TAG_VERSION)\"/" pyproject.toml && \
8+
sed "s/version = \".*\"/version = \"$(GIT_TAG_VERSION)\"/" pyproject.toml > pyproject.toml.tmp && mv pyproject.toml.tmp pyproject.toml && \
99
uv build && \
1010
uv publish

python/kubernetes_mcp_server/kubernetes_mcp_server.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import os
22
import platform
3+
import signal
34
import subprocess
45
import sys
6+
from importlib.metadata import version
57
from pathlib import Path
68
import shutil
79
import tempfile
810
import urllib.request
911

10-
if sys.version_info >= (3, 8):
11-
from importlib.metadata import version
12-
else:
13-
from importlib_metadata import version
14-
1512
__version__ = version("kubernetes-mcp-server")
1613

1714
def get_platform_binary():
@@ -82,8 +79,26 @@ def execute(args=None):
8279
cmd = [str(binary_path)] + args
8380

8481
# Execute the binary with the provided arguments
85-
process = subprocess.run(cmd)
86-
return process.returncode
82+
process = subprocess.Popen(cmd)
83+
84+
def handle_signal(signum, frame):
85+
try:
86+
process.send_signal(signum)
87+
except OSError:
88+
pass
89+
90+
signal.signal(signal.SIGTERM, handle_signal)
91+
if hasattr(signal, "SIGHUP"):
92+
signal.signal(signal.SIGHUP, handle_signal)
93+
94+
try:
95+
return process.wait()
96+
except KeyboardInterrupt:
97+
try:
98+
process.send_signal(signal.SIGINT)
99+
except OSError:
100+
pass
101+
return process.wait()
87102
except Exception as e:
88103
print(f"Error executing kubernetes-mcp-server: {e}", file=sys.stderr)
89104
return 1

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "kubernetes-mcp-server"
77
version = "0.0.0"
88
description = "Kubernetes MCP Server (Model Context Protocol) with special support for OpenShift"
99
readme = {file="README.md", content-type="text/markdown"}
10-
requires-python = ">=3.6"
10+
requires-python = ">=3.8"
1111
license = "Apache-2.0"
1212
authors = [
1313
{ name = "Marc Nuri", email = "marc@marcnuri.com" }

0 commit comments

Comments
 (0)