Skip to content

Commit cdec6b9

Browse files
committed
Prepare inlining MovieWriter.cleanup() into MovieWriter.finish().
The docs only mention `finish()`; but the implementations of `finish()` simply forwards themselves to `cleanup()` (and do a bit more). One can instead just put all the relevant logic in `finish()` and not expose a separate (basically internal) API.
1 parent 7c813db commit cdec6b9

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``MovieWriter.cleanup`` is deprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Cleanup logic is now fully implemented in `.MovieWriter.finish`. Third-party
4+
movie writers should likewise move the relevant cleanup logic there, as
5+
overridden ``cleanup``\s will no longer be called in the future.

doc/missing-references.json

+10-6
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,15 @@
251251
],
252252
"matplotlib.axes._axes.Axes": [
253253
"doc/api/artist_api.rst:189",
254-
"doc/api/axes_api.rst:617",
254+
"doc/api/axes_api.rst:609",
255255
"lib/matplotlib/projections/polar.py:docstring of matplotlib.projections.polar.PolarAxes:1",
256256
"lib/mpl_toolkits/axes_grid1/mpl_axes.py:docstring of mpl_toolkits.axes_grid1.mpl_axes.Axes:1",
257257
"lib/mpl_toolkits/axisartist/axislines.py:docstring of mpl_toolkits.axisartist.axislines.Axes:1",
258258
"lib/mpl_toolkits/mplot3d/axes3d.py:docstring of mpl_toolkits.mplot3d.axes3d.Axes3D:1"
259259
],
260260
"matplotlib.axes._base._AxesBase": [
261261
"doc/api/artist_api.rst:189",
262-
"doc/api/axes_api.rst:617",
262+
"doc/api/axes_api.rst:609",
263263
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes.Axes:1"
264264
],
265265
"matplotlib.backend_bases.FigureCanvas": [
@@ -831,6 +831,7 @@
831831
"lib/matplotlib/image.py:docstring of matplotlib.image.composite_images:9"
832832
],
833833
"cleanup": [
834+
"lib/matplotlib/animation.py:docstring of matplotlib.animation.FileMovieWriter.setup:18",
834835
"lib/matplotlib/animation.py:docstring of matplotlib.animation.HTMLWriter.setup:18"
835836
],
836837
"colorbar.ColorbarBase.outline": [
@@ -895,7 +896,7 @@
895896
"lib/mpl_toolkits/mplot3d/axes3d.py:docstring of mpl_toolkits.mplot3d.axes3d.Axes3D.get_ylim3d:24"
896897
],
897898
"ipykernel.pylab.backend_inline": [
898-
"doc/users/interactive.rst:256"
899+
"doc/users/interactive.rst:257"
899900
],
900901
"kde.covariance_factor": [
901902
"lib/matplotlib/mlab.py:docstring of matplotlib.mlab.GaussianKDE:41"
@@ -1102,16 +1103,19 @@
11021103
"doc/api/_as_gen/matplotlib.animation.FFMpegWriter.rst:28:<autosummary>:1"
11031104
],
11041105
"matplotlib.animation.FileMovieWriter.args_key": [
1105-
"lib/matplotlib/animation.py:docstring of matplotlib.animation.FileMovieWriter.cleanup:1:<autosummary>:1"
1106+
"lib/matplotlib/animation.py:docstring of matplotlib.animation.FileMovieWriter.clear_temp:1:<autosummary>:1"
11061107
],
11071108
"matplotlib.animation.FileMovieWriter.bin_path": [
11081109
"doc/api/_as_gen/matplotlib.animation.FileMovieWriter.rst:28:<autosummary>:1"
11091110
],
1111+
"matplotlib.animation.FileMovieWriter.cleanup": [
1112+
"doc/api/_as_gen/matplotlib.animation.FileMovieWriter.rst:28:<autosummary>:1"
1113+
],
11101114
"matplotlib.animation.FileMovieWriter.exec_key": [
1111-
"lib/matplotlib/animation.py:docstring of matplotlib.animation.FileMovieWriter.cleanup:1:<autosummary>:1"
1115+
"lib/matplotlib/animation.py:docstring of matplotlib.animation.FileMovieWriter.clear_temp:1:<autosummary>:1"
11121116
],
11131117
"matplotlib.animation.FileMovieWriter.frame_size": [
1114-
"lib/matplotlib/animation.py:docstring of matplotlib.animation.FileMovieWriter.cleanup:1:<autosummary>:1"
1118+
"lib/matplotlib/animation.py:docstring of matplotlib.animation.FileMovieWriter.clear_temp:1:<autosummary>:1"
11151119
],
11161120
"matplotlib.animation.FileMovieWriter.isAvailable": [
11171121
"doc/api/_as_gen/matplotlib.animation.FileMovieWriter.rst:28:<autosummary>:1"

lib/matplotlib/animation.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,12 @@ def _run(self):
335335

336336
def finish(self):
337337
"""Finish any processing for writing the movie."""
338-
self.cleanup()
338+
overridden_cleanup = cbook._deprecate_method_override(
339+
__class__.cleanup, self, since="3.4", alternative="finish()")
340+
if overridden_cleanup is not None:
341+
overridden_cleanup()
342+
else:
343+
self._cleanup() # Inline _cleanup() once cleanup() is removed.
339344

340345
def grab_frame(self, **savefig_kwargs):
341346
# docstring inherited
@@ -355,7 +360,7 @@ def _args(self):
355360
"""Assemble list of encoder-specific command-line arguments."""
356361
return NotImplementedError("args needs to be implemented by subclass.")
357362

358-
def cleanup(self):
363+
def _cleanup(self): # Inline to finish() once cleanup() is removed.
359364
"""Clean-up and collect the process used to write the movie file."""
360365
out, err = self._proc.communicate()
361366
self._frame_sink().close()
@@ -374,6 +379,10 @@ def cleanup(self):
374379
raise subprocess.CalledProcessError(
375380
self._proc.returncode, self._proc.args, out, err)
376381

382+
@_api.deprecated("3.4")
383+
def cleanup(self):
384+
self._cleanup()
385+
377386
@classmethod
378387
def bin_path(cls):
379388
"""
@@ -505,8 +514,8 @@ def finish(self):
505514
self._run()
506515
super().finish() # Will call clean-up
507516

508-
def cleanup(self):
509-
super().cleanup()
517+
def _cleanup(self): # Inline to finish() once cleanup() is removed.
518+
super()._cleanup()
510519
if self._tmpdir:
511520
_log.debug('MovieWriter: clearing temporary path=%s', self._tmpdir)
512521
self._tmpdir.cleanup()

0 commit comments

Comments
 (0)