Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make optional backends respect setup.cfg #2331

Merged
merged 7 commits into from Sep 9, 2013
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 @@ -981,16 +1009,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 @@ -1012,10 +1030,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 @@ -1301,10 +1316,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 @@ -1457,7 +1469,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 @@ -1520,7 +1532,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 @@ -1548,7 +1560,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 @@ -1586,10 +1598,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 @@ -1616,7 +1625,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 @@ -1647,7 +1656,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 @@ -1665,7 +1674,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 @@ -1681,7 +1690,7 @@ def check(self):
class BackendCairo(OptionalBackendPackage):
name = "cairo"

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