Skip to content

Commit 1f121d1

Browse files
committed
added readable() and writable() NPopen methods
1 parent f765948 commit 1f121d1

File tree

8 files changed

+38
-9
lines changed

8 files changed

+38
-9
lines changed

.github/workflows/test_n_pub.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ jobs:
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:
18-
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
18+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
1919
os: [ubuntu-latest, macos-latest, windows-latest]
2020
exclude:
21-
- os: macos-latest
22-
python-version: 3.8
23-
- os: windows-latest
24-
python-version: 3.8
2521
- os: macos-latest
2622
python-version: 3.9
2723
- os: windows-latest
@@ -34,6 +30,10 @@ jobs:
3430
python-version: 3.11
3531
- os: windows-latest
3632
python-version: 3.11
33+
- os: macos-latest
34+
python-version: 3.12
35+
- os: windows-latest
36+
python-version: 3.12
3737

3838
steps:
3939
- run: echo ${{github.ref}}

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
## [0.2.0] - 2025-02-04
10+
11+
### Added
12+
13+
- Added `NPopen.readable()` and `NPopen.writable()` methods
14+
915
## [0.1.1] - 2024-03-27
1016

1117
### Changed
18+
1219
- Dropped support for py3.7
1320
- Removed unnecessary dependency `"typing_extensions;python_version<'3.8'"`
1421

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ license = { text = "GPL-2.0 License" }
1414
classifiers = [
1515
"Development Status :: 4 - Beta",
1616
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
17-
"Programming Language :: Python :: 3.8",
1817
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
2019
"Programming Language :: Python :: 3.11",
2120
"Programming Language :: Python :: 3.12",
21+
"Programming Language :: Python :: 3.13",
2222
]
2323
dynamic = ["version"]
24-
requires-python = ">=3.8"
24+
requires-python = ">=3.9"
2525
dependencies = ["pywin32;platform_system=='Windows'"]
2626

2727
[project.urls]

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ with NPopen('r+') as pipe: # bidirectional (duplex) binary pipe
2828
# - for an inbound pipe, specify the read access mode 'rb' or 'rt'
2929
# - for an outbound pipe, specify the write access mode 'wb or 'wt'
3030

31+
pipe.readable() # returns True if yields a readable stream
32+
pipe.writable() # returns True if yields a writable stream
33+
3134
# 2. Get the pipe path via pipe.path or str(pipe) to start the client program
3235
sp.run(['my_client', pipe.path])
3336

src/namedpipe/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.1"
1+
__version__ = "0.2.0"
22

33
from os import name as _os_name
44

src/namedpipe/_posix.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,12 @@ def __enter__(self):
113113

114114
def __exit__(self, *_):
115115
self.close()
116+
117+
def readable(self)->bool:
118+
"""True if pipe's stream is readable"""
119+
return any(c in self._open_args['mode'] for c in 'r+')
120+
121+
def writable(self)->bool:
122+
"""True if pipe's stream is writable"""
123+
return any(c in self._open_args['mode'] for c in 'wxa+')
124+

src/namedpipe/_win32.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,15 @@ def __enter__(self):
164164
def __exit__(self, *_):
165165
self.close()
166166

167-
167+
def readable(self)->bool:
168+
"""True if pipe's stream is readable"""
169+
return self._rd
170+
171+
def writable(self)->bool:
172+
"""True if pipe's stream is writable"""
173+
return self._wr
174+
175+
168176
class Win32RawIO(io.RawIOBase):
169177
"""Raw I/O stream layer over open Windows pipe handle.
170178

tests/test_read.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def run_ffmpeg(pipe):
2424

2525
def test_read_all():
2626
with NPopen("r") as pipe:
27+
assert pipe.readable()
28+
assert not pipe.writable()
2729
proc, nbytes = run_ffmpeg(pipe)
2830
f = pipe.wait()
2931
while f.read(nbytes):

0 commit comments

Comments
 (0)