Skip to content

Commit

Permalink
Remove py dependency (#137)
Browse files Browse the repository at this point in the history
* Remove dependency on py

The `py.std` module is just an alias for the built in Python modules, so
doesn't serve any purpose over importing them directly.

`TerminalWriter` can instead be imported from Pytest directly via a private
import, which means the `py` dependency can be removed.

* Add entry to CHANGELOG
  • Loading branch information
Tenzer authored Sep 23, 2023
1 parent 04179d9 commit 1847ca7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
----------

- Remove dependency on `py`

0.22.2 (2023-01-05)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
setup(
name="pytest-xprocess",
# this is for GitHub's dependency graph
install_requires=["pytest>=2.8", "psutil", "py"],
install_requires=["pytest>=2.8", "psutil"],
)
4 changes: 2 additions & 2 deletions xprocess/pytest_xprocess.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

import py
import pytest
from _pytest._io import TerminalWriter

from xprocess import XProcess

Expand Down Expand Up @@ -35,7 +35,7 @@ def pytest_cmdline_main(config):
xshow = config.option.xshow
if xkill or xshow:
config._do_configure()
tw = py.io.TerminalWriter()
tw = TerminalWriter()
rootdir = getrootdir(config)
xprocess = XProcess(config, rootdir)
if xkill:
Expand Down
14 changes: 8 additions & 6 deletions xprocess/xprocess.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import itertools
import os
import re
import signal
import subprocess
import sys
import time
import traceback
from abc import ABC
from abc import abstractmethod
Expand All @@ -10,7 +13,6 @@
from time import sleep

import psutil
from py import std


XPROCESS_BLOCK_DELIMITER = "@@__xproc_block_delimiter__@@"
Expand Down Expand Up @@ -250,9 +252,9 @@ def ensure(self, name, preparefunc, restart=False, persist_logs=True):
**starter.popen_kwargs,
}
if sys.platform == "win32": # pragma: no cover
kwargs["startupinfo"] = sinfo = std.subprocess.STARTUPINFO()
sinfo.dwFlags |= std.subprocess.STARTF_USESHOWWINDOW
sinfo.wShowWindow |= std.subprocess.SW_HIDE
kwargs["startupinfo"] = sinfo = subprocess.STARTUPINFO()
sinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
sinfo.wShowWindow |= subprocess.SW_HIDE
else:
kwargs["close_fds"] = True
kwargs["preexec_fn"] = os.setpgrp # no CONTROL-C
Expand Down Expand Up @@ -396,7 +398,7 @@ def wait(self, log_file):
"""Wait until the pattern is mached and callback returns successful."""
self._max_time = datetime.now() + timedelta(seconds=self.timeout)
lines = map(self.log_line, self.filter_lines(self.get_lines(log_file)))
has_match = any(std.re.search(self.pattern, line) for line in lines)
has_match = any(re.search(self.pattern, line) for line in lines)
process_ready = self.wait_callback()
return has_match and process_ready

Expand All @@ -417,7 +419,7 @@ def get_lines(self, log_file):
while True:
line = log_file.readline()
if not line:
std.time.sleep(0.1)
time.sleep(0.1)
if datetime.now() > self._max_time:
raise TimeoutError(
"The provided start pattern {} could not be matched \
Expand Down

0 comments on commit 1847ca7

Please sign in to comment.