Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7322046

Browse files
committed
Merge pull request #7530 from matthew-brett/tkagg-depends-on-tkinter
BLD: TkAgg default backend depends on tkinter
1 parent ac15633 commit 7322046

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ def run(self):
194194
required_failed.append(package)
195195
else:
196196
good_packages.append(package)
197-
if isinstance(package, setupext.OptionalBackendPackage):
198-
if default_backend is None:
199-
default_backend = package.name
197+
if (isinstance(package, setupext.OptionalBackendPackage) and
198+
package.runtime_check() and
199+
default_backend is None):
200+
default_backend = package.name
200201
print_raw('')
201202

202203
# Abort if any of the required packages can not be built.

setupext.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import print_function, absolute_import
22

3+
from importlib import import_module
4+
35
from distutils import sysconfig
46
from distutils import version
57
from distutils.core import Extension
@@ -402,13 +404,20 @@ class SetupPackage(object):
402404

403405
def check(self):
404406
"""
405-
Checks whether the dependencies are met. Should raise a
406-
`CheckFailed` exception if the dependency could not be met,
407-
otherwise return a string indicating a version number or some
408-
other message indicating what was found.
407+
Checks whether the build dependencies are met. Should raise a
408+
`CheckFailed` exception if the dependency could not be met, otherwise
409+
return a string indicating a version number or some other message
410+
indicating what was found.
409411
"""
410412
pass
411413

414+
def runtime_check(self):
415+
"""
416+
True if the runtime dependencies of the backend are met. Assumes that
417+
the build-time dependencies are met.
418+
"""
419+
return True
420+
412421
def get_packages(self):
413422
"""
414423
Get a list of package names to add to the configuration.
@@ -1519,6 +1528,16 @@ class BackendTkAgg(OptionalBackendPackage):
15191528
def check(self):
15201529
return "installing; run-time loading from Python Tcl / Tk"
15211530

1531+
def runtime_check(self):
1532+
""" Checks whether TkAgg runtime dependencies are met
1533+
"""
1534+
pkg_name = 'tkinter' if PY3min else 'Tkinter'
1535+
try:
1536+
import_module(pkg_name)
1537+
except ImportError:
1538+
return False
1539+
return True
1540+
15221541
def get_extension(self):
15231542
sources = [
15241543
'src/py_converters.cpp',

0 commit comments

Comments
 (0)