@@ -1371,13 +1371,8 @@ def check(self):
1371
1371
return "installing; run-time loading from Python Tcl / Tk"
1372
1372
1373
1373
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
1381
1376
1382
1377
def get_extension (self ):
1383
1378
sources = [
@@ -1398,144 +1393,44 @@ def add_flags(self, ext):
1398
1393
ext .libraries .extend (['dl' ])
1399
1394
1400
1395
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
-
1425
1396
class BackendGtk3Agg (OptionalBackendPackage ):
1426
1397
name = "gtk3agg"
1427
1398
1428
1399
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. " )
1431
1402
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.
1435
1403
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
1473
1405
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." )
1501
1407
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.
1509
1408
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
+
1513
1416
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." )
1529
1420
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 () )
1534
1425
1535
1426
def get_package_data (self ):
1536
1427
return {'matplotlib' : ['mpl-data/*.glade' ]}
1537
1428
1538
1429
1430
+ class BackendGtk3Cairo (BackendGtk3Agg ):
1431
+ name = "gtk3cairo"
1432
+
1433
+
1539
1434
class BackendWxAgg (OptionalBackendPackage ):
1540
1435
name = "wxagg"
1541
1436
0 commit comments