Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe74179

Browse filesBrowse files
authored
Lazy import av (#432)
1 parent 775556e commit fe74179
Copy full SHA for fe74179

File tree

2 files changed

+14
-13
lines changed
Filter options

2 files changed

+14
-13
lines changed

‎fastplotlib/layouts/_frame/_toolbar.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_frame/_toolbar.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from fastplotlib.layouts._subplot import Subplot
1+
from .._subplot import Subplot
22

33

44
class ToolBar:

‎fastplotlib/layouts/_record_mixin.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_record_mixin.py
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
from multiprocessing import Queue, Process
44
from time import time
55

6-
try:
7-
import av
8-
except ImportError:
9-
HAS_AV = False
10-
else:
11-
HAS_AV = True
6+
7+
def _get_av():
8+
try:
9+
import av
10+
except ImportError:
11+
raise ModuleNotFoundError(
12+
"Recording to video file requires `av`:\n"
13+
"https://github.com/PyAV-Org/PyAV"
14+
) from None
15+
else:
16+
return av
1217

1318

1419
class VideoWriterAV(Process):
@@ -28,6 +33,7 @@ def __init__(
2833
super().__init__()
2934
self.queue = queue
3035

36+
av = _get_av()
3137
self.container = av.open(path, mode="w")
3238

3339
self.stream = self.container.add_stream(codec, rate=fps, options=options)
@@ -45,6 +51,7 @@ def __init__(
4551
self.stream.pix_fmt = pixel_format
4652

4753
def run(self):
54+
av = _get_av()
4855
while True:
4956
if self.queue.empty(): # no frame to write
5057
continue
@@ -177,12 +184,6 @@ def record_start(
177184
178185
"""
179186

180-
if not HAS_AV:
181-
raise ModuleNotFoundError(
182-
"Recording to video file requires `av`:\n"
183-
"https://github.com/PyAV-Org/PyAV"
184-
)
185-
186187
if Path(path).exists():
187188
raise FileExistsError(f"File already exists at given path: {path}")
188189

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.