@@ -1524,9 +1524,6 @@ def get_extension(self):
1524
1524
class BackendTkAgg (OptionalBackendPackage ):
1525
1525
name = "tkagg"
1526
1526
1527
- def __init__ (self ):
1528
- self .tcl_tk_cache = None
1529
-
1530
1527
def check_requirements (self ):
1531
1528
try :
1532
1529
if PY3min :
@@ -1541,9 +1538,6 @@ def check_requirements(self):
1541
1538
if Tkinter .TkVersion < 8.3 :
1542
1539
raise CheckFailed ("Tcl/Tk v8.3 or later required." )
1543
1540
1544
- ext = self .get_extension ()
1545
- check_include_file (ext .include_dirs , "tk.h" , "Tk" )
1546
-
1547
1541
try :
1548
1542
tk_v = Tkinter .__version__ .split ()[- 2 ]
1549
1543
except (AttributeError , IndexError ):
@@ -1566,252 +1560,12 @@ def get_extension(self):
1566
1560
LibAgg ().add_flags (ext , add_sources = False )
1567
1561
return ext
1568
1562
1569
- def query_tcltk (self ):
1570
- """
1571
- Tries to open a Tk window in order to query the Tk object
1572
- about its library paths. This should never be called more
1573
- than once by the same process, as Tk intricacies may cause the
1574
- Python interpreter to hang. The function also has a workaround
1575
- if no X server is running (useful for autobuild systems).
1576
- """
1577
- # Use cached values if they exist, which ensures this function
1578
- # only executes once
1579
- if self .tcl_tk_cache is not None :
1580
- return self .tcl_tk_cache
1581
-
1582
- # By this point, we already know that Tkinter imports correctly
1583
- if PY3min :
1584
- import tkinter as Tkinter
1585
- else :
1586
- import Tkinter
1587
- tcl_lib_dir = ''
1588
- tk_lib_dir = ''
1589
- # First try to open a Tk window (requires a running X server)
1590
- try :
1591
- tk = Tkinter .Tk ()
1592
- except Tkinter .TclError :
1593
- # Next, start Tcl interpreter without opening a Tk window
1594
- # (no need for X server) This feature is available in
1595
- # python version 2.4 and up
1596
- try :
1597
- tcl = Tkinter .Tcl ()
1598
- except AttributeError : # Python version not high enough
1599
- pass
1600
- except Tkinter .TclError : # Something went wrong while opening Tcl
1601
- pass
1602
- else :
1603
- tcl_lib_dir = str (tcl .getvar ('tcl_library' ))
1604
- # Guess Tk location based on Tcl location
1605
- (head , tail ) = os .path .split (tcl_lib_dir )
1606
- tail = tail .replace ('Tcl' , 'Tk' ).replace ('tcl' , 'tk' )
1607
- tk_lib_dir = os .path .join (head , tail )
1608
- if not os .path .exists (tk_lib_dir ):
1609
- tk_lib_dir = tcl_lib_dir .replace (
1610
- 'Tcl' , 'Tk' ).replace ('tcl' , 'tk' )
1611
- else :
1612
- # Obtain Tcl and Tk locations from Tk widget
1613
- tk .withdraw ()
1614
- tcl_lib_dir = str (tk .getvar ('tcl_library' ))
1615
- tk_lib_dir = str (tk .getvar ('tk_library' ))
1616
- tk .destroy ()
1617
-
1618
- # Save directories and version string to cache
1619
- self .tcl_tk_cache = tcl_lib_dir , tk_lib_dir , str (Tkinter .TkVersion )[:3 ]
1620
- return self .tcl_tk_cache
1621
-
1622
- def parse_tcl_config (self , tcl_lib_dir , tk_lib_dir ):
1623
- try :
1624
- if PY3min :
1625
- import tkinter as Tkinter
1626
- else :
1627
- import Tkinter
1628
- except ImportError :
1629
- return None
1630
-
1631
- tcl_poss = [tcl_lib_dir ,
1632
- os .path .normpath (os .path .join (tcl_lib_dir , '..' )),
1633
- "/usr/lib/tcl" + str (Tkinter .TclVersion ),
1634
- "/usr/lib" ]
1635
- tk_poss = [tk_lib_dir ,
1636
- os .path .normpath (os .path .join (tk_lib_dir , '..' )),
1637
- "/usr/lib/tk" + str (Tkinter .TkVersion ),
1638
- "/usr/lib" ]
1639
- for ptcl , ptk in zip (tcl_poss , tk_poss ):
1640
- tcl_config = os .path .join (ptcl , "tclConfig.sh" )
1641
- tk_config = os .path .join (ptk , "tkConfig.sh" )
1642
- if (os .path .exists (tcl_config ) and os .path .exists (tk_config )):
1643
- break
1644
- if not (os .path .exists (tcl_config ) and os .path .exists (tk_config )):
1645
- return None
1646
-
1647
- def get_var (file , varname ):
1648
- p = subprocess .Popen (
1649
- '. %s ; eval echo ${%s}' % (file , varname ),
1650
- shell = True ,
1651
- executable = "/bin/sh" ,
1652
- stdout = subprocess .PIPE )
1653
- result = p .communicate ()[0 ]
1654
- return result .decode ('ascii' )
1655
-
1656
- tcl_lib_dir = get_var (
1657
- tcl_config , 'TCL_LIB_SPEC' ).split ()[0 ][2 :].strip ()
1658
- tcl_inc_dir = get_var (
1659
- tcl_config , 'TCL_INCLUDE_SPEC' )[2 :].strip ()
1660
- tcl_lib = get_var (tcl_config , 'TCL_LIB_FLAG' )[2 :].strip ()
1661
-
1662
- tk_lib_dir = get_var (tk_config , 'TK_LIB_SPEC' ).split ()[0 ][2 :].strip ()
1663
- tk_inc_dir = get_var (tk_config , 'TK_INCLUDE_SPEC' ).strip ()
1664
- if tk_inc_dir == '' :
1665
- tk_inc_dir = tcl_inc_dir
1666
- else :
1667
- tk_inc_dir = tk_inc_dir [2 :]
1668
- tk_lib = get_var (tk_config , 'TK_LIB_FLAG' )[2 :].strip ()
1669
-
1670
- if not os .path .exists (os .path .join (tk_inc_dir , 'tk.h' )):
1671
- return None
1672
-
1673
- return (tcl_lib_dir , tcl_inc_dir , tcl_lib ,
1674
- tk_lib_dir , tk_inc_dir , tk_lib )
1675
-
1676
- def guess_tcl_config (self , tcl_lib_dir , tk_lib_dir , tk_ver ):
1677
- if not (os .path .exists (tcl_lib_dir ) and os .path .exists (tk_lib_dir )):
1678
- return None
1679
-
1680
- tcl_lib = os .path .normpath (os .path .join (tcl_lib_dir , '../' ))
1681
- tk_lib = os .path .normpath (os .path .join (tk_lib_dir , '../' ))
1682
-
1683
- tcl_inc = os .path .normpath (
1684
- os .path .join (tcl_lib_dir ,
1685
- '../../include/tcl' + tk_ver ))
1686
- if not os .path .exists (tcl_inc ):
1687
- tcl_inc = os .path .normpath (
1688
- os .path .join (tcl_lib_dir ,
1689
- '../../include' ))
1690
-
1691
- tk_inc = os .path .normpath (os .path .join (
1692
- tk_lib_dir ,
1693
- '../../include/tk' + tk_ver ))
1694
- if not os .path .exists (tk_inc ):
1695
- tk_inc = os .path .normpath (os .path .join (
1696
- tk_lib_dir ,
1697
- '../../include' ))
1698
-
1699
- if not os .path .exists (os .path .join (tk_inc , 'tk.h' )):
1700
- tk_inc = tcl_inc
1701
-
1702
- if not os .path .exists (tcl_inc ):
1703
- # this is a hack for suse linux, which is broken
1704
- if (sys .platform .startswith ('linux' ) and
1705
- os .path .exists ('/usr/include/tcl.h' ) and
1706
- os .path .exists ('/usr/include/tk.h' )):
1707
- tcl_inc = '/usr/include'
1708
- tk_inc = '/usr/include'
1709
-
1710
- if not os .path .exists (os .path .join (tk_inc , 'tk.h' )):
1711
- return None
1712
-
1713
- return tcl_lib , tcl_inc , 'tcl' + tk_ver , tk_lib , tk_inc , 'tk' + tk_ver
1714
-
1715
- def hardcoded_tcl_config (self ):
1716
- tcl_inc = "/usr/local/include"
1717
- tk_inc = "/usr/local/include"
1718
- tcl_lib = "/usr/local/lib"
1719
- tk_lib = "/usr/local/lib"
1720
- return tcl_lib , tcl_inc , 'tcl' , tk_lib , tk_inc , 'tk'
1721
-
1722
1563
def add_flags (self , ext ):
1564
+ ext .include_dirs .extend (['src' ])
1723
1565
if sys .platform == 'win32' :
1724
- if os .getenv ('CONDA_DEFAULT_ENV' ):
1725
- # We are in conda and conda builds against tcl85 for all versions
1726
- # includes are directly in the conda\library\include dir and
1727
- # libs in DLL or lib
1728
- ext .include_dirs .extend (['include' ])
1729
- else :
1730
- major , minor1 , minor2 , s , tmp = sys .version_info
1731
- if sys .version_info [0 :2 ] < (3 , 4 ):
1732
- ext .include_dirs .extend (['win32_static/include/tcl85' ])
1733
- else :
1734
- ext .include_dirs .extend (['win32_static/include/tcl86' ])
1735
- # PSAPI library needed for finding TCL / Tk at run time
1566
+ # PSAPI library needed for finding Tcl / Tk at run time
1736
1567
ext .libraries .extend (['psapi' ])
1737
1568
1738
- elif sys .platform == 'darwin' :
1739
- # this config section lifted directly from Imaging - thanks to
1740
- # the effbot!
1741
-
1742
- # First test for a MacOSX/darwin framework install
1743
- from os .path import join , exists
1744
- framework_dirs = [
1745
- join (os .getenv ('HOME' ), '/Library/Frameworks' ),
1746
- '/Library/Frameworks' ,
1747
- '/System/Library/Frameworks/' ,
1748
- ]
1749
-
1750
- # Find the directory that contains the Tcl.framework and
1751
- # Tk.framework bundles.
1752
- tk_framework_found = 0
1753
- for F in framework_dirs :
1754
- # both Tcl.framework and Tk.framework should be present
1755
- for fw in 'Tcl' , 'Tk' :
1756
- if not exists (join (F , fw + '.framework' )):
1757
- break
1758
- else :
1759
- # ok, F is now directory with both frameworks. Continure
1760
- # building
1761
- tk_framework_found = 1
1762
- break
1763
- if tk_framework_found :
1764
- # For 8.4a2, we must add -I options that point inside
1765
- # the Tcl and Tk frameworks. In later release we
1766
- # should hopefully be able to pass the -F option to
1767
- # gcc, which specifies a framework lookup path.
1768
-
1769
- tk_include_dirs = [
1770
- join (F , fw + '.framework' , H )
1771
- for fw in ('Tcl' , 'Tk' )
1772
- for H in ('Headers' , 'Versions/Current/PrivateHeaders' )
1773
- ]
1774
-
1775
- # For 8.4a2, the X11 headers are not included. Rather
1776
- # than include a complicated search, this is a
1777
- # hard-coded path. It could bail out if X11 libs are
1778
- # not found...
1779
-
1780
- # tk_include_dirs.append('/usr/X11R6/include')
1781
- ext .include_dirs .extend (tk_include_dirs )
1782
-
1783
- # you're still here? ok we'll try it this way...
1784
- else :
1785
- # There are 3 methods to try, in decreasing order of "smartness"
1786
- #
1787
- # 1. Parse the tclConfig.sh and tkConfig.sh files that have
1788
- # all the information we need
1789
- #
1790
- # 2. Guess the include and lib dirs based on the location of
1791
- # Tkinter's 'tcl_library' and 'tk_library' variables.
1792
- #
1793
- # 3. Use some hardcoded locations that seem to work on a lot
1794
- # of distros.
1795
-
1796
- # Query Tcl/Tk system for library paths and version string
1797
- try :
1798
- tcl_lib_dir , tk_lib_dir , tk_ver = self .query_tcltk ()
1799
- except :
1800
- tk_ver = ''
1801
- result = self .hardcoded_tcl_config ()
1802
- else :
1803
- result = self .parse_tcl_config (tcl_lib_dir , tk_lib_dir )
1804
- if result is None :
1805
- result = self .guess_tcl_config (
1806
- tcl_lib_dir , tk_lib_dir , tk_ver )
1807
- if result is None :
1808
- result = self .hardcoded_tcl_config ()
1809
-
1810
- # Add final versions of directories and libraries to ext lists
1811
- (tcl_lib_dir , tcl_inc_dir , tcl_lib ,
1812
- tk_lib_dir , tk_inc_dir , tk_lib ) = result
1813
- ext .include_dirs .extend ([tcl_inc_dir , tk_inc_dir ])
1814
-
1815
1569
1816
1570
class BackendGtk (OptionalBackendPackage ):
1817
1571
name = "gtk"
0 commit comments