Skip to content

Commit 9555535

Browse files
authored
Merge pull request #10885 from anntzer/setupext-gtk3
BLD: Move GTK3 setupext checks to within the process.
2 parents ec14df9 + 5690503 commit 9555535

File tree

1 file changed

+24
-129
lines changed

1 file changed

+24
-129
lines changed

setupext.py

Lines changed: 24 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,13 +1371,8 @@ def check(self):
13711371
return "installing; run-time loading from Python Tcl / Tk"
13721372

13731373
def runtime_check(self):
1374-
""" Checks whether TkAgg runtime dependencies are met
1375-
"""
1376-
try:
1377-
import tkinter
1378-
except ImportError:
1379-
return False
1380-
return True
1374+
"""Checks whether TkAgg runtime dependencies are met."""
1375+
return importlib.util.find_spec("tkinter") is not None
13811376

13821377
def get_extension(self):
13831378
sources = [
@@ -1398,144 +1393,44 @@ def add_flags(self, ext):
13981393
ext.libraries.extend(['dl'])
13991394

14001395

1401-
def backend_gtk3agg_internal_check(x):
1402-
try:
1403-
import gi
1404-
except ImportError:
1405-
return (False, "Requires pygobject to be installed.")
1406-
1407-
try:
1408-
gi.require_version("Gtk", "3.0")
1409-
except ValueError:
1410-
return (False, "Requires gtk3 development files to be installed.")
1411-
except AttributeError:
1412-
return (False, "pygobject version too old.")
1413-
1414-
try:
1415-
from gi.repository import Gtk, Gdk, GObject
1416-
except (ImportError, RuntimeError):
1417-
return (False, "Requires pygobject to be installed.")
1418-
1419-
return (True, "version %s.%s.%s" % (
1420-
Gtk.get_major_version(),
1421-
Gtk.get_micro_version(),
1422-
Gtk.get_minor_version()))
1423-
1424-
14251396
class BackendGtk3Agg(OptionalBackendPackage):
14261397
name = "gtk3agg"
14271398

14281399
def check_requirements(self):
1429-
if 'TRAVIS' in os.environ:
1430-
raise CheckFailed("Can't build with Travis")
1400+
if not any(map(importlib.util.find_spec, ["cairocffi", "cairo"])):
1401+
raise CheckFailed("Requires cairocffi or pycairo to be installed.")
14311402

1432-
# This check needs to be performed out-of-process, because
1433-
# importing gi and then importing regular old pygtk afterward
1434-
# segfaults the interpreter.
14351403
try:
1436-
p = multiprocessing.Pool()
1437-
except:
1438-
return "unknown (can not use multiprocessing to determine)"
1439-
try:
1440-
res = p.map_async(backend_gtk3agg_internal_check, [0])
1441-
success, msg = res.get(timeout=10)[0]
1442-
except multiprocessing.TimeoutError:
1443-
p.terminate()
1444-
# No result returned. Probably hanging, terminate the process.
1445-
success = False
1446-
raise CheckFailed("Check timed out")
1447-
except:
1448-
p.close()
1449-
# Some other error.
1450-
success = False
1451-
msg = "Could not determine"
1452-
raise
1453-
else:
1454-
p.close()
1455-
finally:
1456-
p.join()
1457-
1458-
if success:
1459-
return msg
1460-
else:
1461-
raise CheckFailed(msg)
1462-
1463-
def get_package_data(self):
1464-
return {'matplotlib': ['mpl-data/*.glade']}
1465-
1466-
1467-
def backend_gtk3cairo_internal_check(x):
1468-
try:
1469-
import cairocffi
1470-
except ImportError:
1471-
try:
1472-
import cairo
1404+
import gi
14731405
except ImportError:
1474-
return (False, "Requires cairocffi or pycairo to be installed.")
1475-
1476-
try:
1477-
import gi
1478-
except ImportError:
1479-
return (False, "Requires pygobject to be installed.")
1480-
1481-
try:
1482-
gi.require_version("Gtk", "3.0")
1483-
except ValueError:
1484-
return (False, "Requires gtk3 development files to be installed.")
1485-
except AttributeError:
1486-
return (False, "pygobject version too old.")
1487-
1488-
try:
1489-
from gi.repository import Gtk, Gdk, GObject
1490-
except (RuntimeError, ImportError):
1491-
return (False, "Requires pygobject to be installed.")
1492-
1493-
return (True, "version %s.%s.%s" % (
1494-
Gtk.get_major_version(),
1495-
Gtk.get_micro_version(),
1496-
Gtk.get_minor_version()))
1497-
1498-
1499-
class BackendGtk3Cairo(OptionalBackendPackage):
1500-
name = "gtk3cairo"
1406+
raise CheckFailed("Requires pygobject to be installed.")
15011407

1502-
def check_requirements(self):
1503-
if 'TRAVIS' in os.environ:
1504-
raise CheckFailed("Can't build with Travis")
1505-
1506-
# This check needs to be performed out-of-process, because
1507-
# importing gi and then importing regular old pygtk afterward
1508-
# segfaults the interpreter.
15091408
try:
1510-
p = multiprocessing.Pool()
1511-
except:
1512-
return "unknown (can not use multiprocessing to determine)"
1409+
gi.require_version("Gtk", "3.0")
1410+
except ValueError:
1411+
raise CheckFailed(
1412+
"Requires gtk3 development files to be installed.")
1413+
except AttributeError:
1414+
raise CheckFailed("pygobject version too old.")
1415+
15131416
try:
1514-
res = p.map_async(backend_gtk3cairo_internal_check, [0])
1515-
success, msg = res.get(timeout=10)[0]
1516-
except multiprocessing.TimeoutError:
1517-
p.terminate()
1518-
# No result returned. Probably hanging, terminate the process.
1519-
success = False
1520-
raise CheckFailed("Check timed out")
1521-
except:
1522-
p.close()
1523-
success = False
1524-
raise
1525-
else:
1526-
p.close()
1527-
finally:
1528-
p.join()
1417+
from gi.repository import Gtk, Gdk, GObject
1418+
except (ImportError, RuntimeError):
1419+
raise CheckFailed("Requires pygobject to be installed.")
15291420

1530-
if success:
1531-
return msg
1532-
else:
1533-
raise CheckFailed(msg)
1421+
return "version {}.{}.{}".format(
1422+
Gtk.get_major_version(),
1423+
Gtk.get_minor_version(),
1424+
Gtk.get_micro_version())
15341425

15351426
def get_package_data(self):
15361427
return {'matplotlib': ['mpl-data/*.glade']}
15371428

15381429

1430+
class BackendGtk3Cairo(BackendGtk3Agg):
1431+
name = "gtk3cairo"
1432+
1433+
15391434
class BackendWxAgg(OptionalBackendPackage):
15401435
name = "wxagg"
15411436

0 commit comments

Comments
 (0)