Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 1d6a90b

Browse files
committed
mypy clean
1 parent fa9853b commit 1d6a90b

File tree

11 files changed

+83
-69
lines changed

11 files changed

+83
-69
lines changed

.gitattributes

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
2+
3+
name: publish
4+
5+
on:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
release:
11+
12+
runs-on: ubuntu-latest
13+
14+
environment: release
15+
16+
permissions:
17+
id-token: write
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.x'
26+
27+
- name: Install builder
28+
run: pip install build
29+
30+
- name: Build package
31+
run: python -m build
32+
33+
- name: Publish package
34+
uses: pypa/gh-action-pypi-publish@release/v1

pyproject.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[build-system]
22
requires = ["setuptools>=61.0.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
34

45
[project]
56
name = "pylivestream"
@@ -34,7 +35,3 @@ line-length = 100
3435
[tool.mypy]
3536
files = ["src"]
3637
ignore_missing_imports = true
37-
strict_optional = false
38-
allow_redefinition = true
39-
show_error_context = false
40-
show_column_numbers = true

src/pylivestream/api.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def stream_file(
3030
ini_file: Path,
3131
websites: str | list[str],
3232
video_file: Path,
33-
loop: bool = None,
33+
loop: bool | None = None,
3434
assume_yes: bool = False,
35-
timeout: float = None,
35+
timeout: float | None = None,
3636
):
3737
S = FileIn(ini_file, websites, infn=video_file, loop=loop, yes=assume_yes, timeout=timeout)
3838
sites: list[str] = list(S.streams.keys())
@@ -50,9 +50,9 @@ def stream_microphone(
5050
ini_file: Path,
5151
websites: list[str],
5252
*,
53-
still_image: Path = None,
54-
assume_yes: bool = False,
55-
timeout: float = None,
53+
still_image: Path | None = None,
54+
assume_yes: bool | None = False,
55+
timeout: float | None = None,
5656
):
5757
"""
5858
livestream audio, with still image background
@@ -70,7 +70,7 @@ def stream_microphone(
7070

7171

7272
def capture_screen(
73-
ini_file: Path, *, out_file: Path, assume_yes: bool = False, timeout: float = None
73+
ini_file: Path, *, out_file: Path, assume_yes: bool = False, timeout: float | None = None
7474
):
7575

7676
s = SaveDisk(ini_file, out_file, yes=assume_yes, timeout=timeout)

src/pylivestream/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, inifn: Path, site: str, **kwargs) -> None:
7575
+ ["-f", "null", "-"] # camera needs at output
7676
)
7777

78-
def startlive(self, sinks: list[str] = None):
78+
def startlive(self, sinks: list[str] | None = None):
7979
"""
8080
start the stream(s)
8181
"""
@@ -141,7 +141,7 @@ def startlive(self, sinks: list[str] = None):
141141
proc.terminate()
142142
yield
143143

144-
def check_device(self, site: str = None) -> bool:
144+
def check_device(self, site: str | None = None) -> bool:
145145
"""
146146
requires stream to have been configured first.
147147
does a quick test stream to "null" to verify device is actually accessible
@@ -251,7 +251,7 @@ def golive(self) -> None:
251251

252252

253253
class SaveDisk(Stream):
254-
def __init__(self, inifn: Path, outfn: Path = None, **kwargs):
254+
def __init__(self, inifn: Path, outfn: Path | None = None, **kwargs):
255255
"""
256256
records to disk screen capture with audio
257257

src/pylivestream/ffmpeg.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self):
2323

2424
self.THROTTLE = "-re"
2525

26-
def timelimit(self, t: str | int | float) -> list[str]:
26+
def timelimit(self, t: str | int | float | None) -> list[str]:
2727
if t is None:
2828
return []
2929

@@ -36,7 +36,7 @@ def timelimit(self, t: str | int | float) -> list[str]:
3636
else:
3737
return []
3838

39-
def drawtext(self, text: str = None) -> list[str]:
39+
def drawtext(self, text: str) -> list[str]:
4040
# fontfile=/path/to/font.ttf:
4141
if not text: # None or '' or [] etc.
4242
return []
@@ -85,7 +85,7 @@ def listener(self):
8585

8686
return proc
8787

88-
def movingBG(self, bgfn: Path = None) -> list[str]:
88+
def movingBG(self, bgfn: Path | None = None) -> list[str]:
8989
if not bgfn:
9090
return []
9191

@@ -125,9 +125,9 @@ def get_ffprobe() -> str:
125125
return get_exe("ffprobe")
126126

127127

128-
def get_meta(fn: Path, exein: str = None) -> dict[str, T.Any]:
128+
def get_meta(fn: Path, exein: str | None = None) -> dict[str, T.Any]:
129129
if not fn: # audio-only
130-
return None
130+
return {}
131131

132132
fn = Path(fn).expanduser()
133133

@@ -147,6 +147,6 @@ def get_meta(fn: Path, exein: str = None) -> dict[str, T.Any]:
147147
str(fn),
148148
]
149149

150-
ret = subprocess.check_output(cmd, universal_newlines=True)
150+
ret = subprocess.check_output(cmd, text=True)
151151
# %% decode JSON from FFprobe
152152
return json.loads(ret)

src/pylivestream/glob.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def stream_files(
1818
websites: list[str],
1919
*,
2020
video_path: Path,
21-
glob: str = None,
21+
glob: str | None = None,
2222
assume_yes: bool = False,
23-
loop: bool = None,
24-
shuffle: bool = None,
25-
still_image: Path = None,
26-
no_meta: bool = None,
27-
timeout: float = None,
23+
loop: bool = False,
24+
shuffle: bool = False,
25+
still_image: Path | None = None,
26+
no_meta: bool = False,
27+
timeout: float | None = None,
2828
):
2929
# %% file / glob wranging
3030
flist = fileglob(video_path, glob)
@@ -49,19 +49,19 @@ def stream_files(
4949

5050
def playonce(
5151
flist: list[Path],
52-
image: Path,
52+
image: Path | None,
5353
sites: list[str],
5454
inifn: Path,
5555
shuffle: bool,
5656
usemeta: bool,
5757
yes: bool,
58-
timeout: float = None,
58+
timeout: float | None = None,
5959
):
6060

6161
if shuffle:
6262
random.shuffle(flist)
6363

64-
caption: str
64+
caption: str | None
6565

6666
for f in flist:
6767
if usemeta and TinyTag:
@@ -80,7 +80,7 @@ def playonce(
8080
s.golive()
8181

8282

83-
def fileglob(path: Path, glob: str) -> list[Path]:
83+
def fileglob(path: Path, glob: str | None) -> list[Path]:
8484

8585
path = Path(path).expanduser()
8686

src/pylivestream/screen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def stream_screen(
10-
ini_file: Path, websites: list[str], *, assume_yes: bool = False, timeout: float = None
10+
ini_file: Path, websites: list[str], *, assume_yes: bool = False, timeout: float | None = None
1111
):
1212

1313
S = Screenshare(ini_file, websites, yes=assume_yes, timeout=timeout)

src/pylivestream/stream.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,16 @@ def __init__(self, inifn: Path, site: str, **kwargs):
3636
self.site: str = site
3737
self.vidsource = kwargs.get("vidsource")
3838

39-
if kwargs.get("image"):
40-
self.image = Path(kwargs["image"]).expanduser()
41-
else:
42-
self.image = None
39+
self.image = Path(kwargs["image"]).expanduser() if kwargs.get("image") else None
4340

44-
self.loop: bool = kwargs.get("loop")
41+
self.loop: bool = kwargs.get("loop", False)
4542

4643
self.infn = Path(kwargs["infn"]).expanduser() if kwargs.get("infn") else None
4744
self.yes: list[str] = self.F.YES if kwargs.get("yes") else []
4845

4946
self.queue: list[str] = [] # self.F.QUEUE
5047

51-
self.caption: str = kwargs.get("caption")
48+
self.caption: str = kwargs.get("caption", "")
5249

5350
self.timelimit: list[str] = self.F.timelimit(kwargs.get("timeout"))
5451

@@ -80,7 +77,7 @@ def osparam(self, fn: Path) -> None:
8077

8178
if self.vidsource == "camera":
8279
self.res: list[str] = C.get("camera_size")
83-
self.fps: float = C.get("camera_fps")
80+
self.fps: float | None = C.get("camera_fps")
8481
self.movingimage = self.staticimage = False
8582
elif self.vidsource == "screen":
8683
self.res = C.get("screencap_size")
@@ -94,10 +91,10 @@ def osparam(self, fn: Path) -> None:
9491
self.res = utils.get_resolution(self.infn, self.probeexe)
9592
self.fps = utils.get_framerate(self.infn, self.probeexe)
9693
else: # audio-only
97-
self.res = None
94+
self.res = []
9895
self.fps = None
9996

100-
if self.res is not None and len(self.res) != 2:
97+
if self.res and len(self.res) != 2:
10198
raise ValueError(f"need height, width of video resolution, I have: {self.res}")
10299

103100
self.audio_rate: str = C.get("audio_rate")
@@ -236,7 +233,7 @@ def video_bitrate(self) -> None:
236233
if self.video_kbps: # per-site override
237234
return
238235

239-
if self.res is not None:
236+
if self.res:
240237
x: int = int(self.res[1])
241238
elif self.vidsource is None or self.vidsource == "file":
242239
logging.info("assuming 480p input.")

src/pylivestream/tests/test_class.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_exe(rex):
1717

1818
@pytest.mark.parametrize("inp", (None, ""))
1919
def test_attrs(inp):
20-
assert pls.utils.get_resolution(inp) is None
20+
assert not pls.utils.get_resolution(inp)
2121

2222
with importlib.resources.as_file(
2323
importlib.resources.files("pylivestream.data").joinpath("bunny.avi")

src/pylivestream/utils.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def run(cmd: list[str]):
2727
I don't like putting enormous amounts in a PIPE, this can be unstable.
2828
Better to let users know there's a problem.
2929
30-
ret = subprocess.run(cmd, stderr=subprocess.PIPE, universal_newlines=True)
30+
ret = subprocess.run(cmd, stderr=subprocess.PIPE, text=True)
3131
3232
if ret.returncode != 0:
3333
if "Connection reset by peer" in ret.stderr:
@@ -48,7 +48,7 @@ def check_device(cmd: list[str]) -> bool:
4848
return ok
4949

5050

51-
def check_display(fn: Path = None) -> bool:
51+
def check_display(fn: Path | None = None) -> bool:
5252
"""see if it's possible to display something with a test file"""
5353

5454
def _check_disp(fn: Path | contextlib.AbstractContextManager[Path]) -> int:
@@ -83,7 +83,7 @@ def meta_caption(meta) -> str:
8383
return caption
8484

8585

86-
def get_resolution(fn: Path, exe: str = None) -> list[str]:
86+
def get_resolution(fn: Path | None, exe: str | None = None) -> list[str]:
8787
"""
8888
get resolution (widthxheight) of video file
8989
http://trac.ffmpeg.org/wiki/FFprobeTips#WidthxHeight
@@ -101,11 +101,14 @@ def get_resolution(fn: Path, exe: str = None) -> list[str]:
101101
if not a video file, None is returned.
102102
"""
103103

104+
if fn is None:
105+
return []
106+
104107
meta = get_meta(fn, exe)
105-
if meta is None:
106-
return None
108+
if not meta:
109+
return []
107110

108-
res = None
111+
res = []
109112

110113
for s in meta["streams"]:
111114
if s["codec_type"] != "video":
@@ -116,7 +119,7 @@ def get_resolution(fn: Path, exe: str = None) -> list[str]:
116119
return res
117120

118121

119-
def get_framerate(fn: Path, exe: str = None) -> float:
122+
def get_framerate(fn: Path | None, exe: str | None = None) -> float | None:
120123
"""
121124
get framerate of video file
122125
http://trac.ffmpeg.org/wiki/FFprobeTips#FrameRate
@@ -136,8 +139,11 @@ def get_framerate(fn: Path, exe: str = None) -> float:
136139
video framerate (frames/second). If not a video file, None is returned.
137140
"""
138141

142+
if fn is None:
143+
return None
144+
139145
meta = get_meta(fn, exe)
140-
if meta is None:
146+
if not meta:
141147
return None
142148

143149
fps = None

0 commit comments

Comments
 (0)