Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f87cfce

Browse files
committed
Issue #15663: OS X installer builtin Tcl/Tk support
Make it easier for users to make use of the backup _tkinter linked with the third-party Tcl and Tk frameworks in /Library/Frameworks. The two tkinter variants are now installed in separate directories under a new lib-tkinter. This allows per-user selection by manipulating sys.path, directly or with PYTHONPATH. If this proves useful, we can supply a more convenient user interface to supply the paths. For now, this remains somewhat experimental.
1 parent 8444ebb commit f87cfce

2 files changed

Lines changed: 51 additions & 19 deletions

File tree

Mac/BuildScript/README.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,30 @@ for each release.
6868
- requires ActiveState Tcl/Tk 8.5.15 (or later) to be installed for building
6969

7070
* Beginning with Python 3.4 alpha2, this installer now includes its own
71-
private copy of Tcl and Tk 8.5.15 libraries and thus is no longer
71+
builtin copy of Tcl and Tk 8.5.15 libraries and thus is no longer
7272
dependent on the buggy releases of Aqua Cocoa Tk 8.5 shipped with
7373
OS X 10.6 or on installing a newer third-party version of Tcl/Tk
7474
in /Library/Frameworks, such as from ActiveState. Because this
7575
is a new feature, it should be considered somewhat experimental and
7676
subject to change prior to the final release of Python 3.4. If it
7777
is necessary to fallback to using a third-party Tcl/Tk because of
78-
a problem with the private Tcl/Tk, there is a backup version of
78+
a problem with the builtin Tcl/Tk, there is a backup version of
7979
the _tkinter extension included which will dynamically link to
8080
Tcl and Tk frameworks in /Library/Frameworks as in previous releases.
8181
To enable (for all users of this Python 3.4)::
8282

8383
sudo bash
8484
cd /Library/Frameworks/Python.framework/Versions/3.4
85-
cd ./lib/python3.4/lib-dynload
86-
cp -p _tkinter.so.framework _tkinter.so
85+
cd ./lib/python3.4
86+
cp -p ./lib-tkinter/library/_tkinter.so ./lib-dynload
8787
exit
8888

89-
To restore using Python's private versions of Tcl and Tk::
89+
To restore using Python's builtin versions of Tcl and Tk::
9090

9191
sudo bash
9292
cd /Library/Frameworks/Python.framework/Versions/3.4
93-
cd ./lib/python3.4/lib-dynload
94-
cp -p _tkinter.so.private _tkinter.so
93+
cd ./lib/python3.4
94+
cp -p ./lib-tkinter/builtin/_tkinter.so ./lib-dynload
9595
exit
9696

9797
- recommended build environment:

Mac/BuildScript/build-installer.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,11 @@ def checkEnvironment():
565565
]
566566

567567
# For 10.6+ builds, we build two versions of _tkinter:
568-
# - the traditional version (renamed to _tkinter.so.framework) linked
568+
# - the traditional version (renamed to _tkinter_library.so) linked
569569
# with /Library/Frameworks/{Tcl,Tk}.framework
570-
# - the default version linked with our private copies of Tcl and Tk
570+
# - the default version linked with our builtin copies of Tcl and Tk
571571
if DEPTARGET > '10.5':
572-
EXPECTED_SHARED_LIBS['_tkinter.so.framework'] = \
572+
EXPECTED_SHARED_LIBS['_tkinter_library.so'] = \
573573
EXPECTED_SHARED_LIBS['_tkinter.so']
574574
EXPECTED_SHARED_LIBS['_tkinter.so'] = [
575575
"/Library/Frameworks/Python.framework/Versions/%s/lib/libtcl%s.dylib"
@@ -966,18 +966,18 @@ def buildPython():
966966
# of Tcl and Cocoa Aqua Tk libs because the Apple-supplied Tk 8.5 is
967967
# out-of-date and has critical bugs. Save the _tkinter.so that was
968968
# linked with /Library/Frameworks/{Tck,Tk}.framework and build
969-
# another _tkinter.so linked with our private Tcl and Tk libs.
969+
# another _tkinter.so linked with our builtin Tcl and Tk libs.
970970
if DEPTARGET > '10.5':
971971
runCommand("find build -name '_tkinter.so' "
972-
" -execdir mv '{}' '{}'.framework \;")
973-
print("Running make to rebuild _tkinter")
972+
" -execdir mv '{}' _tkinter_library.so \;")
973+
print("Running make to build builtin _tkinter")
974974
runCommand("make TCLTK_INCLUDES='-I%s/libraries/usr/local/include' "
975975
"TCLTK_LIBS='-L%s/libraries/usr/local/lib -ltcl8.5 -ltk8.5'"%(
976976
shellQuote(WORKDIR)[1:-1],
977977
shellQuote(WORKDIR)[1:-1]))
978-
# make a backup copy, just in case
978+
# make a copy which will be moved to lib-tkinter later
979979
runCommand("find build -name '_tkinter.so' "
980-
" -execdir cp -p '{}' '{}'.private \;")
980+
" -execdir cp -p '{}' _tkinter_builtin.so \;")
981981

982982
print("Running make install")
983983
runCommand("make install DESTDIR=%s"%(
@@ -999,11 +999,31 @@ def buildPython():
999999
'Python.framework', 'Versions', getVersion(),
10001000
'lib'))))
10011001

1002+
path_to_lib = os.path.join(rootDir, 'Library', 'Frameworks',
1003+
'Python.framework', 'Versions',
1004+
version, 'lib', 'python%s'%(version,))
1005+
1006+
# If we made multiple versions of _tkinter, move them to
1007+
# their own directories under python lib. This allows
1008+
# users to select which to import by manipulating sys.path
1009+
# directly or with PYTHONPATH.
1010+
1011+
if DEPTARGET > '10.5':
1012+
TKINTERS = ['builtin', 'library']
1013+
tkinter_moves = [('_tkinter_' + tkn + '.so',
1014+
os.path.join(path_to_lib, 'lib-tkinter', tkn))
1015+
for tkn in TKINTERS]
1016+
# Create the destination directories under lib-tkinter.
1017+
# The permissions and uid/gid will be fixed up next.
1018+
for tkm in tkinter_moves:
1019+
os.makedirs(tkm[1])
1020+
10021021
print("Fix file modes")
10031022
frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework')
10041023
gid = grp.getgrnam('admin').gr_gid
10051024

10061025
shared_lib_error = False
1026+
moves_list = []
10071027
for dirpath, dirnames, filenames in os.walk(frmDir):
10081028
for dn in dirnames:
10091029
os.chmod(os.path.join(dirpath, dn), STAT_0o775)
@@ -1029,9 +1049,25 @@ def buildPython():
10291049
% (sl, p))
10301050
shared_lib_error = True
10311051

1052+
# If this is a _tkinter variant, move it to its own directory
1053+
# now that we have fixed its permissions and checked that it
1054+
# was linked properly. The directory was created earlier.
1055+
# The files are moved after the entire tree has been walked
1056+
# since the shared library checking depends on the files
1057+
# having unique names.
1058+
if DEPTARGET > '10.5':
1059+
for tkm in tkinter_moves:
1060+
if fn == tkm[0]:
1061+
moves_list.append(
1062+
(p, os.path.join(tkm[1], '_tkinter.so')))
1063+
10321064
if shared_lib_error:
10331065
fatal("Unexpected shared library errors.")
10341066

1067+
# Now do the moves.
1068+
for ml in moves_list:
1069+
shutil.move(ml[0], ml[1])
1070+
10351071
if PYTHON_3:
10361072
LDVERSION=None
10371073
VERSION=None
@@ -1061,10 +1097,6 @@ def buildPython():
10611097
include_path = '-I%s/libraries/usr/local/include' % (WORKDIR,)
10621098
lib_path = '-L%s/libraries/usr/local/lib' % (WORKDIR,)
10631099

1064-
path_to_lib = os.path.join(rootDir, 'Library', 'Frameworks',
1065-
'Python.framework', 'Versions',
1066-
version, 'lib', 'python%s'%(version,))
1067-
10681100
# fix Makefile
10691101
path = os.path.join(path_to_lib, 'config' + config_suffix, 'Makefile')
10701102
fp = open(path, 'r')

0 commit comments

Comments
 (0)