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 b9fef3a

Browse filesBrowse files
committed
Move check for ImageMagick Windows path to bin_path().
That's a perfectly reasonable place to put the registry check and avoids introducing an additional private helper method.
1 parent 7bcf618 commit b9fef3a
Copy full SHA for b9fef3a

File tree

Expand file treeCollapse file tree

1 file changed

+24
-36
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-36
lines changed

‎lib/matplotlib/animation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/animation.py
+24-36Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -724,42 +724,30 @@ def output_args(self):
724724
return [self.outfile]
725725

726726
@classmethod
727-
def _init_from_registry(cls):
728-
if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
729-
return
730-
import winreg
731-
for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
732-
try:
733-
hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
734-
r'Software\Imagemagick\Current',
735-
0, winreg.KEY_QUERY_VALUE | flag)
736-
binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
737-
winreg.CloseKey(hkey)
738-
break
739-
except Exception:
740-
binpath = ''
741-
if binpath:
742-
for exe in ('convert.exe', 'magick.exe'):
743-
path = os.path.join(binpath, exe)
744-
if os.path.exists(path):
745-
binpath = path
746-
break
747-
else:
748-
binpath = ''
749-
rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath
750-
751-
@classmethod
752-
def isAvailable(cls):
753-
'''
754-
Check to see if a ImageMagickWriter is actually available.
755-
756-
Done by first checking the windows registry (if applicable) and then
757-
running the commandline tool.
758-
'''
759-
bin_path = cls.bin_path()
760-
if bin_path == "convert":
761-
cls._init_from_registry()
762-
return super().isAvailable()
727+
def bin_path(cls):
728+
binpath = super().bin_path()
729+
if sys.platform == 'win32' and binpath == 'convert':
730+
# Check the registry to avoid confusing ImageMagick's convert with
731+
# Windows's builtin convert.exe.
732+
import winreg
733+
binpath = ''
734+
for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
735+
try:
736+
with winreg.OpenKeyEx(
737+
winreg.HKEY_LOCAL_MACHINE,
738+
r'Software\Imagemagick\Current',
739+
0, winreg.KEY_QUERY_VALUE | flag) as hkey:
740+
parent = winreg.QueryValueEx(hkey, 'BinPath')[0]
741+
except OSError:
742+
pass
743+
if binpath:
744+
for exe in ('convert.exe', 'magick.exe'):
745+
candidate = os.path.join(parent, exe)
746+
if os.path.exists(candidate):
747+
binpath = candidate
748+
break
749+
rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath
750+
return binpath
763751

764752

765753
# Note: the base classes need to be in that order to get

0 commit comments

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