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

Skip to content

Commit 45e4a46

Browse files
authored
Merge pull request #7530 from matthew-brett/tkagg-depends-on-tkinter
BLD: TkAgg default backend depends on tkinter
2 parents 3fad2d5 + 677801a commit 45e4a46

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
@@ -193,9 +193,10 @@ def run(self):
193193
required_failed.append(package)
194194
else:
195195
good_packages.append(package)
196-
if isinstance(package, setupext.OptionalBackendPackage):
197-
if default_backend is None:
198-
default_backend = package.name
196+
if (isinstance(package, setupext.OptionalBackendPackage) and
197+
package.runtime_check() and
198+
default_backend is None):
199+
default_backend = package.name
199200
print_raw('')
200201

201202
# 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
@@ -424,13 +426,20 @@ class SetupPackage(object):
424426

425427
def check(self):
426428
"""
427-
Checks whether the dependencies are met. Should raise a
428-
`CheckFailed` exception if the dependency could not be met,
429-
otherwise return a string indicating a version number or some
430-
other message indicating what was found.
429+
Checks whether the build dependencies are met. Should raise a
430+
`CheckFailed` exception if the dependency could not be met, otherwise
431+
return a string indicating a version number or some other message
432+
indicating what was found.
431433
"""
432434
pass
433435

436+
def runtime_check(self):
437+
"""
438+
True if the runtime dependencies of the backend are met. Assumes that
439+
the build-time dependencies are met.
440+
"""
441+
return True
442+
434443
def get_packages(self):
435444
"""
436445
Get a list of package names to add to the configuration.
@@ -1643,6 +1652,16 @@ class BackendTkAgg(OptionalBackendPackage):
16431652
def check(self):
16441653
return "installing; run-time loading from Python Tcl / Tk"
16451654

1655+
def runtime_check(self):
1656+
""" Checks whether TkAgg runtime dependencies are met
1657+
"""
1658+
pkg_name = 'tkinter' if PY3min else 'Tkinter'
1659+
try:
1660+
import_module(pkg_name)
1661+
except ImportError:
1662+
return False
1663+
return True
1664+
16461665
def get_extension(self):
16471666
sources = [
16481667
'src/py_converters.cpp',

0 commit comments

Comments
 (0)