Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/con_duct/_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
import os
import platform
import subprocess
import sys
from typing import Callable, Optional
from con_duct._models import Averages, ProcessStats, Sample

SYSTEM = platform.system()

_SUPPORTED_SYSTEMS = {"Linux", "Darwin"}
if SYSTEM not in _SUPPORTED_SYSTEMS:
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting sys.tracebacklimit = 0 modifies global state that affects all future tracebacks in the Python process. While this is acceptable for this use case (since the program will terminate after raising the error), consider documenting this side effect with a comment. If someone were to catch this exception and continue execution, all subsequent tracebacks would be suppressed.

Suggested change
if SYSTEM not in _SUPPORTED_SYSTEMS:
if SYSTEM not in _SUPPORTED_SYSTEMS:
# NOTE: This modifies global interpreter state and will suppress all subsequent
# tracebacks in the current Python process. This is intentional here to avoid
# noisy stack traces on unsupported platforms; if this exception is caught and
# execution continues, traceback output will remain suppressed.

Copilot uses AI. Check for mistakes.
sys.tracebacklimit = 0
message = (
f"`con_duct` does not currently support the detected operating system ({SYSTEM}).\n\n"
"If you would like to request support, please open an issue at: "
"https://github.com/con/duct/issues/new"
)
raise NotImplementedError(message)

lgr = logging.getLogger("con-duct")


Expand Down
28 changes: 28 additions & 0 deletions test/test_windows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations
import importlib
import sys
from typing import Generator
from unittest import mock
import pytest


@pytest.fixture
def _reload_sampling() -> Generator:
"""Ensure _sampling module is restored after tests that reload it."""
import con_duct._sampling as mod

yield
if hasattr(sys, "tracebacklimit"):
del sys.tracebacklimit
importlib.reload(mod)


@mock.patch("platform.system", return_value="Windows")
@pytest.mark.usefixtures("_reload_sampling")
def test_unsupported_system_raises(_mock_system: mock.MagicMock) -> None:
import con_duct._sampling as mod

with pytest.raises(
NotImplementedError, match="does not currently support.*Windows"
):
importlib.reload(mod)
Loading