Skip to content

Commit

Permalink
Fix Windows test skips and daemon launches.
Browse files Browse the repository at this point in the history
More work towards pex-tool#2658.
  • Loading branch information
jsirois committed Feb 20, 2025
1 parent bdd20fd commit 5f85319
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pex/docs/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pex.cache.dirs import CacheDir
from pex.common import safe_open
from pex.os import kill
from pex.subprocess import subprocess_daemon_kwargs
from pex.subprocess import launch_python_daemon
from pex.typing import TYPE_CHECKING
from pex.version import __version__

Expand Down Expand Up @@ -163,14 +163,13 @@ def launch(
# ephemeral port chosen.
env.update(PYTHONUNBUFFERED="1")
with safe_open(log, "w") as fp:
process = subprocess.Popen(
process = launch_python_daemon(
args=[sys.executable, "-m", http_server_module, str(port)],
env=env,
cwd=document_root,
bufsize=1,
stdout=fp.fileno(),
stderr=subprocess.STDOUT,
**subprocess_daemon_kwargs()
)

pidfile = Pidfile.record(server_log=log, pid=process.pid, timeout=timeout)
Expand Down
17 changes: 16 additions & 1 deletion pex/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pex.typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any, Dict
from typing import Any, Dict, List


def subprocess_daemon_kwargs():
Expand All @@ -33,3 +33,18 @@ def subprocess_daemon_kwargs():
# The os.setsid function is not available on Windows.
"preexec_fn": os.setsid # type: ignore[attr-defined]
}


def launch_python_daemon(
args, # type: List[str]
**kwargs # type: Any
):
# type: (...) -> subprocess.Popen
if WINDOWS:
python, _ = os.path.splitext(os.path.basename(args[0]))
if python == "python":
pythonw = os.path.join(os.path.dirname(args[0]), "pythonw.exe")
if os.path.exists(pythonw):
args[0] = pythonw
kwargs.update(subprocess_daemon_kwargs())
return subprocess.Popen(args=args, **kwargs)
5 changes: 2 additions & 3 deletions testing/devpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pex.common import safe_open, safe_rmtree
from pex.interpreter import PythonInterpreter
from pex.interpreter_constraints import InterpreterConstraint
from pex.subprocess import subprocess_daemon_kwargs
from pex.subprocess import launch_python_daemon
from pex.typing import TYPE_CHECKING, cast
from pex.venv.virtualenv import InvalidVirtualenvError, Virtualenv
from testing import PEX_TEST_DEV_ROOT
Expand Down Expand Up @@ -197,7 +197,7 @@ def launch(

log = os.path.join(DEVPI_DIR, "log.txt")
with safe_open(log, "w") as fp:
process = subprocess.Popen(
process = launch_python_daemon(
args=devpi_server.launch_args(
"--host",
host,
Expand All @@ -211,7 +211,6 @@ def launch(
cwd=DEVPI_DIR,
stdout=fp.fileno(),
stderr=subprocess.STDOUT,
**subprocess_daemon_kwargs()
)

pidfile = Pidfile.record(log=log, pid=process.pid, timeout=timeout)
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_sh_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from pex.common import safe_open
from pex.layout import Layout
from pex.os import WINDOWS
from pex.typing import TYPE_CHECKING
from testing import all_pythons, make_env, run_pex_command
from testing.pytest.tmp import Tempdir
Expand All @@ -20,6 +21,13 @@
from typing import Any, Iterable, Iterator, List, Text, Tuple


if WINDOWS:
pytest.skip(
"The --sh-boot shebang launch trick only works on systems with shebang support.",
allow_module_level=True,
)


@pytest.mark.parametrize(
["execution_mode_args"],
[
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_shebang_length_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def find_max_length(
# Pytest fails to cleanup tmp dirs used probing file_path_length_limit and this squashes a very
# large ream of warnings.
if WINDOWS:
pytestmark = pytest.mark.skip("The current process of probing limits can break Windows.")
pytest.skip("The current process of probing limits can break Windows.", allow_module_level=True)
else:
pytestmark = pytest.mark.filterwarnings(
"ignore:\\(rm_rf\\) error removing.*:pytest.PytestWarning"
Expand Down

0 comments on commit 5f85319

Please sign in to comment.