Skip to content

Simplify lookup of animation external commands. #11229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 12 additions & 32 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import os
from pathlib import Path
import platform
import shutil
import subprocess
import sys
from tempfile import TemporaryDirectory
Expand Down Expand Up @@ -408,27 +409,9 @@ def bin_path(cls):
@classmethod
def isAvailable(cls):
'''
Check to see if a MovieWriter subclass is actually available by
running the commandline tool.
Check to see if a MovieWriter subclass is actually available.
'''
bin_path = cls.bin_path()
if not bin_path:
return False
try:
p = subprocess.Popen(
bin_path,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
creationflags=subprocess_creation_flags)
return cls._handle_subprocess(p)
except OSError:
return False

@classmethod
def _handle_subprocess(cls, process):
process.communicate()
return True
return shutil.which(cls.bin_path()) is not None


class FileMovieWriter(MovieWriter):
Expand Down Expand Up @@ -633,13 +616,14 @@ def output_args(self):
return args + ['-y', self.outfile]

@classmethod
def _handle_subprocess(cls, process):
_, err = process.communicate()
# Ubuntu 12.04 ships a broken ffmpeg binary which we shouldn't use
# NOTE : when removed, remove the same method in AVConvBase.
if 'Libav' in err.decode():
return False
return True
def isAvailable(cls):
return (
super().isAvailable()
# Ubuntu 12.04 ships a broken ffmpeg binary which we shouldn't use.
# NOTE: when removed, remove the same method in AVConvBase.
and b'LibAv' not in subprocess.run(
[cls.bin_path()], creationflags=subprocess_creation_flags,
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE).stderr)


# Combine FFMpeg options with pipe-based writing
Expand Down Expand Up @@ -697,9 +681,7 @@ class AVConvBase(FFMpegBase):
args_key = 'animation.avconv_args'

# NOTE : should be removed when the same method is removed in FFMpegBase.
@classmethod
def _handle_subprocess(cls, process):
return MovieWriter._handle_subprocess(process)
isAvailable = classmethod(MovieWriter.isAvailable.__func__)


# Combine AVConv options with pipe-based writing
Expand Down Expand Up @@ -772,8 +754,6 @@ def isAvailable(cls):
cls._init_from_registry()
return super().isAvailable()

ImageMagickBase._init_from_registry()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we need this any more?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐑 read the whole PR top matter.



# Note: the base classes need to be in that order to get
# isAvailable() from ImageMagickBase called and not the
Expand Down