Skip to content

Commit

Permalink
MAINT: TkAgg default backend depends on tkinter
Browse files Browse the repository at this point in the history
We now always build the TkAgg backend, because it does not depend on the
Tk libraries being on the building system.

This had the unwanted effect of making the TkAgg backend be the default
even if Python tkinter libraries were not installed.

Make a `runtime_check` function for the optional packages, that gives
True if the package can be used at run time, and use that to reject
TkAgg as default backend when tkinter not available.
  • Loading branch information
matthew-brett committed Nov 29, 2016
1 parent b9c3b64 commit 603f06f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ def run(self):
required_failed.append(package)
else:
good_packages.append(package)
if isinstance(package, setupext.OptionalBackendPackage):
if default_backend is None:
default_backend = package.name
if (isinstance(package, setupext.OptionalBackendPackage)
and package.runtime_check()
and default_backend is None):
default_backend = package.name
print_raw('')

# Abort if any of the required packages can not be built.
Expand Down
25 changes: 21 additions & 4 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,20 @@ class SetupPackage(object):

def check(self):
"""
Checks whether the dependencies are met. Should raise a
`CheckFailed` exception if the dependency could not be met,
otherwise return a string indicating a version number or some
other message indicating what was found.
Checks whether the build dependencies are met. Should raise a
`CheckFailed` exception if the dependency could not be met, otherwise
return a string indicating a version number or some other message
indicating what was found.
"""
pass

def runtime_check(self):
"""
True if the runtime dependencies of the backend are met. Assumes that
the build-time dependencies are met.
"""
return True

def get_packages(self):
"""
Get a list of package names to add to the configuration.
Expand Down Expand Up @@ -1643,6 +1650,16 @@ class BackendTkAgg(OptionalBackendPackage):
def check(self):
return "installing; run-time loading from Python Tcl / Tk"

def runtime_check(self):
""" Checks whether TkAgg runtime dependencies are met
"""
pkg_name = 'tkinter' if PY3min else 'Tkinter'
try:
__import__(pkg_name)
except ImportError:
return False
return True

def get_extension(self):
sources = [
'src/py_converters.cpp',
Expand Down

0 comments on commit 603f06f

Please sign in to comment.