diff --git a/pyproject.toml b/pyproject.toml index a930b8b..835ff80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -172,11 +172,13 @@ fail_under = 79 # https://github.com/wemake-services/coverage-conditional-plugin [tool.coverage.coverage_conditional_plugin.omit] "sys_platform != 'win32'" = [ - "src/openjd/sessions/_linux/*.py", "src/openjd/sessions/_win32/*.py", "src/openjd/sessions/_scripts/_windows/*.py", "src/openjd/sessions/_windows*.py" ] +"sys_platform == 'win32'" = [ + "src/openjd/sessions/_linux/*.py", +] [tool.coverage.coverage_conditional_plugin.rules] # This cannot be empty otherwise coverage-conditional-plugin crashes with: diff --git a/src/openjd/sessions/_subprocess.py b/src/openjd/sessions/_subprocess.py index e77fb20..cc70fb9 100644 --- a/src/openjd/sessions/_subprocess.py +++ b/src/openjd/sessions/_subprocess.py @@ -216,6 +216,9 @@ def _find_sudo_child_process_ids( *, timeout_seconds: float = 1, ) -> Optional[SudoChildProcessIDs]: + # Hint to mypy to not raise module attribute errors (e.g. missing os.getpgid) + if sys.platform == "win32": + raise NotImplementedError("This method is for POSIX hosts only") process = self._process if process is None: raise ValueError("Process not launched") @@ -593,6 +596,10 @@ def _posix_signal_subprocess( ) -> None: """Send a given named signal to the subprocess.""" + # Hint to mypy to not raise module attribute errors (e.g. missing os.getpgid) + if sys.platform == "win32": + raise NotImplementedError("This method is for POSIX hosts only") + # We can run into a race condition where the process exits (and another thread sets self._process to None) # before the cancellation happens, so we swap to a local variable to ensure a cancellation that is not needed, # does not raise an exception here. @@ -633,8 +640,7 @@ def _posix_signal_subprocess( f"INTERRUPT: Unable to send {signal_name} to {process.pid}", extra=LogExtraInfo(openjd_log_content=LogContent.PROCESS_CONTROL), ) - finally: - return + return elif signal_name == "kill": numeric_signal = signal.SIGKILL else: diff --git a/testing_containers/localuser_sudo_environment/Dockerfile b/testing_containers/localuser_sudo_environment/Dockerfile index d02f35e..3db697a 100644 --- a/testing_containers/localuser_sudo_environment/Dockerfile +++ b/testing_containers/localuser_sudo_environment/Dockerfile @@ -20,7 +20,7 @@ ENV PIP_INDEX_URL=$PIP_INDEX_URL # hostuser: hostuser, sharedgroup # targetuser: targetuser, sharedgroup # disjointuser: disjointuser, disjointgroup -RUN apt-get update && apt-get install -y sudo psmisc libcap2-bin libcap2 libcap-dev gcc && \ +RUN apt-get update && apt-get install -y libcap2-bin libcap2 libcap-dev gcc psmisc sudo && \ # Clean up apt cache rm -rf /var/lib/apt/lists/* && \ apt-get clean && \