Skip to content

Commit 1847ca7

Browse files
authored
Remove py dependency (#137)
* 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
1 parent 04179d9 commit 1847ca7

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Unreleased
2+
----------
3+
4+
- Remove dependency on `py`
5+
16
0.22.2 (2023-01-05)
27
-------------------
38

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
setup(
55
name="pytest-xprocess",
66
# this is for GitHub's dependency graph
7-
install_requires=["pytest>=2.8", "psutil", "py"],
7+
install_requires=["pytest>=2.8", "psutil"],
88
)

xprocess/pytest_xprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

3-
import py
43
import pytest
4+
from _pytest._io import TerminalWriter
55

66
from xprocess import XProcess
77

@@ -35,7 +35,7 @@ def pytest_cmdline_main(config):
3535
xshow = config.option.xshow
3636
if xkill or xshow:
3737
config._do_configure()
38-
tw = py.io.TerminalWriter()
38+
tw = TerminalWriter()
3939
rootdir = getrootdir(config)
4040
xprocess = XProcess(config, rootdir)
4141
if xkill:

xprocess/xprocess.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import itertools
22
import os
3+
import re
34
import signal
5+
import subprocess
46
import sys
7+
import time
58
import traceback
69
from abc import ABC
710
from abc import abstractmethod
@@ -10,7 +13,6 @@
1013
from time import sleep
1114

1215
import psutil
13-
from py import std
1416

1517

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

@@ -417,7 +419,7 @@ def get_lines(self, log_file):
417419
while True:
418420
line = log_file.readline()
419421
if not line:
420-
std.time.sleep(0.1)
422+
time.sleep(0.1)
421423
if datetime.now() > self._max_time:
422424
raise TimeoutError(
423425
"The provided start pattern {} could not be matched \

0 commit comments

Comments
 (0)