Skip to content

Commit

Permalink
Merge pull request #2331 from megies/optional_backend_config_check
Browse files Browse the repository at this point in the history
Make optional backends respect setup.cfg
  • Loading branch information
mdboom committed Sep 9, 2013
2 parents 637a565 + 829597b commit 8607047
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 57 deletions.
11 changes: 8 additions & 3 deletions setup.cfg.template
Expand Up @@ -54,13 +54,18 @@
# otherwise skip silently. This is the default
# behavior
#
#agg = auto
#cairo = auto
#gtk = auto
#gtk3agg = auto
#gtk3cairo = auto
#gtkagg = auto
#tkagg = auto
#macosx = auto
#pyside = auto
#qt4agg = auto
#tkagg = auto
#windowing = auto
#gtk3cairo = auto
#gtk3agg = auto
#wxagg = auto

[rc_options]
# User-configurable options
Expand Down
117 changes: 63 additions & 54 deletions setupext.py
Expand Up @@ -435,38 +435,66 @@ def _check_for_pkg_config(self, package, include_file, min_version=None,

class OptionalPackage(SetupPackage):
optional = True
force = False
config_category = "packages"

def get_config(self):
install = True
if config is not None:
try:
install = config.getboolean(
'packages', self.name)
except:
pass
return install
"""
Look at `setup.cfg` and return one of ["auto", True, False] indicating
if the package is at default state ("auto"), forced by the user (True)
or opted-out (False).
"""
try:
return config.getboolean(self.config_category, self.name)
except:
return "auto"

def check(self):
self.install = self.get_config()
if not self.install:
raise CheckFailed("skipping due to configuration")
return "installing"
"""
Do not override this method!
For custom dependency checks override self.check_requirements().
Two things are checked: Configuration file and requirements.
"""
# Check configuration file
conf = self.get_config()
# Default "auto" state or install forced by user
if conf in [True, 'auto']:
message = "installing"
# Set non-optional if user sets `True` in config
if conf is True:
self.optional = False
# Configuration opt-out by user
else:
# Some backend extensions (e.g. Agg) need to be built for certain
# other GUI backends (e.g. TkAgg) even when manually disabled
if self.force is True:
message = "installing forced (config override)"
else:
raise CheckFailed("skipping due to configuration")

class OptionalBackendPackage(SetupPackage):
optional = True
# Check requirements and add extra information (if any) to message.
# If requirements are not met a CheckFailed should be raised in there.
additional_info = self.check_requirements()
if additional_info:
message += ", " + additional_info

# No CheckFailed raised until now, return install message.
return message

def check_requirements(self):
"""
Override this method to do custom dependency checks.
- Raise CheckFailed() if requirements are not met.
- Return message with additional information, or an empty string
(or None) for no additional information.
"""
return ""

def get_config(self):
install = 'auto'
if config is not None:
try:
install = config.getboolean(
'gui_support', self.name)
except:
install = 'auto'
if install is True:
self.optional = False
return install

class OptionalBackendPackage(OptionalPackage):
config_category = "gui_support"


class Platform(SetupPackage):
Expand Down Expand Up @@ -1005,16 +1033,6 @@ def get_install_requires(self):

class BackendAgg(OptionalBackendPackage):
name = "agg"
force = False

def check(self):
# The Agg backend extension needs to be built even
# for certain GUI backends, such as TkAgg
config = self.get_config()
if config is False and self.force is False:
raise CheckFailed("skipping due to configuration")
else:
return "installing"

def get_extension(self):
sources = [
Expand All @@ -1036,10 +1054,7 @@ class BackendTkAgg(OptionalBackendPackage):
def __init__(self):
self.tcl_tk_cache = None

def check(self):
if self.get_config() is False:
raise CheckFailed("skipping due to configuration")

def check_requirements(self):
try:
if sys.version_info[0] < 3:
import Tkinter
Expand Down Expand Up @@ -1325,10 +1340,7 @@ def add_flags(self, ext):
class BackendGtk(OptionalBackendPackage):
name = "gtk"

def check(self):
if self.get_config() is False:
raise CheckFailed("skipping due to configuration")

def check_requirements(self):
try:
import gtk
except ImportError:
Expand Down Expand Up @@ -1483,7 +1495,7 @@ def backend_gtk3agg_internal_check(x):
class BackendGtk3Agg(OptionalBackendPackage):
name = "gtk3agg"

def check(self):
def check_requirements(self):
if 'TRAVIS' in os.environ:
raise CheckFailed("Can't build with Travis")

Expand Down Expand Up @@ -1548,7 +1560,7 @@ def backend_gtk3cairo_internal_check(x):
class BackendGtk3Cairo(OptionalBackendPackage):
name = "gtk3cairo"

def check(self):
def check_requirements(self):
if 'TRAVIS' in os.environ:
raise CheckFailed("Can't build with Travis")

Expand Down Expand Up @@ -1576,7 +1588,7 @@ def get_package_data(self):
class BackendWxAgg(OptionalBackendPackage):
name = "wxagg"

def check(self):
def check_requirements(self):
try:
import wxversion
except ImportError:
Expand Down Expand Up @@ -1614,10 +1626,7 @@ def check(self):
class BackendMacOSX(OptionalBackendPackage):
name = 'macosx'

def check(self):
if self.get_config() is False:
raise CheckFailed("skipping due to configuration")

def check_requirements(self):
if sys.platform != 'darwin':
raise CheckFailed("Mac OS-X only")

Expand All @@ -1644,7 +1653,7 @@ class Windowing(OptionalBackendPackage):
"""
name = "windowing"

def check(self):
def check_requirements(self):
if sys.platform != 'win32':
raise CheckFailed("Microsoft Windows only")
config = self.get_config()
Expand Down Expand Up @@ -1675,7 +1684,7 @@ def convert_qt_version(self, version):
temp.insert(0, str(int(chunk, 16)))
return '.'.join(temp)

def check(self):
def check_requirements(self):
try:
from PyQt4 import pyqtconfig
except ImportError:
Expand All @@ -1695,7 +1704,7 @@ def check(self):
class BackendPySide(OptionalBackendPackage):
name = "pyside"

def check(self):
def check_requirements(self):
try:
from PySide import __version__
from PySide import QtCore
Expand All @@ -1711,7 +1720,7 @@ def check(self):
class BackendCairo(OptionalBackendPackage):
name = "cairo"

def check(self):
def check_requirements(self):
try:
import cairo
except ImportError:
Expand Down

0 comments on commit 8607047

Please sign in to comment.