From d2217c5f73c365fe278eb6a0e74c67168657395a Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Thu, 29 Jan 2015 19:31:46 +0000 Subject: [PATCH 1/3] Handle ActiveTcl installs on OS X Fixes #621 --- PyInstaller/hooks/hook-_tkinter.py | 59 +++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/PyInstaller/hooks/hook-_tkinter.py b/PyInstaller/hooks/hook-_tkinter.py index c020bd3a08..d4c2d8c400 100644 --- a/PyInstaller/hooks/hook-_tkinter.py +++ b/PyInstaller/hooks/hook-_tkinter.py @@ -45,6 +45,59 @@ def _handle_broken_tk(): v['TIX_LIBRARY'] = abs_path +def _handle_activetcl_install(tcl_root, tcltree): + """ + Workaround ActiveTcl on OS X + + PyInstaller does not package all requirements of ActiveTcl + (most notable teapot, which is not typically required), which + means packages built against ActiveTcl usually won't run on + non-host systems. + + This method checks if ActiveTcl is being used, and if so reports + a warning if the problematic code is not commented out. + + https://github.com/pyinstaller/pyinstaller/issues/621 + """ + if not is_darwin: + # this is only relevant for ActiveTcl/OS X + return + + from PyInstaller.lib.macholib import util + if util.in_system_path(tcl_root): + # system libraries do not experience this problem + return + + # get the path to the 'init.tcl' script + try: + init_resource = [r[1] for r in tcltree if r[1].endswith('init.tcl')][0] + except IndexError: + # couldn't find the init script, return + return + + mentions_activetcl = False + mentions_teapot = False + with open(init_resource, 'r') as init_file: + for line in init_file.readlines(): + line = line.strip().lower() + if 'activetcl' in line and not line.startswith('#'): + mentions_activetcl = True + if 'teapot' in line and not line.startswith('#'): + mentions_teapot = True + if mentions_activetcl and mentions_teapot: + break + + if mentions_activetcl and mentions_teapot: + logger.warning("""It seems you are using an ActiveTcl build of Tcl/Tk.\ + This may not package correctly with PyInstaller. +To fix the problem, please try commenting out all mentions of 'teapot' in: + + %s + +See https://github.com/pyinstaller/pyinstaller/issues/621 for more information""" + % init_resource) + + def _find_tk_darwin_frameworks(binaries): """ Tcl and Tk are installed as Mac OS X Frameworks. @@ -137,6 +190,10 @@ def _collect_tkfiles(mod): tcltree = Tree(tcl_root, os.path.join('_MEI', tcldir), excludes=['demos', '*.lib', 'tclConfig.sh']) + + # handle workaround for ActiveTcl on OS X + _handle_activetcl_install(tcl_root, tcltree) + tktree = Tree(tk_root, os.path.join('_MEI', tkdir), excludes=['demos', '*.lib', 'tkConfig.sh']) return (tcltree + tktree) @@ -146,7 +203,7 @@ def hook(mod): # If not supported platform, skip TCL/TK detection. if not (is_win or is_darwin or is_unix): logger.info("... skipping TCL/TK detection on this platform (%s)", - sys.platform) + sys.platform) return mod # Get the Tcl/Tk data files for bundling with executable. From 2ba82a46d198b60190a58f112e14901503c93120 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Thu, 29 Jan 2015 19:34:54 +0000 Subject: [PATCH 2/3] Docstring improvements --- PyInstaller/hooks/hook-_tkinter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PyInstaller/hooks/hook-_tkinter.py b/PyInstaller/hooks/hook-_tkinter.py index d4c2d8c400..882a6f0172 100644 --- a/PyInstaller/hooks/hook-_tkinter.py +++ b/PyInstaller/hooks/hook-_tkinter.py @@ -50,11 +50,11 @@ def _handle_activetcl_install(tcl_root, tcltree): Workaround ActiveTcl on OS X PyInstaller does not package all requirements of ActiveTcl - (most notable teapot, which is not typically required), which + (most notably teapot, which is not typically required). This means packages built against ActiveTcl usually won't run on non-host systems. - This method checks if ActiveTcl is being used, and if so reports + This method checks if ActiveTcl is being used, and if so logs a warning if the problematic code is not commented out. https://github.com/pyinstaller/pyinstaller/issues/621 From 06cccc032ae9d5accec1c0b0d7e5fc61fcd33700 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Sat, 31 Jan 2015 09:18:52 +0000 Subject: [PATCH 3/3] Improvments as per @htgoebel's suggestions --- PyInstaller/hooks/hook-_tkinter.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/PyInstaller/hooks/hook-_tkinter.py b/PyInstaller/hooks/hook-_tkinter.py index 882a6f0172..c74ed67737 100644 --- a/PyInstaller/hooks/hook-_tkinter.py +++ b/PyInstaller/hooks/hook-_tkinter.py @@ -45,7 +45,7 @@ def _handle_broken_tk(): v['TIX_LIBRARY'] = abs_path -def _handle_activetcl_install(tcl_root, tcltree): +def _warn_if_actvivetcl_or_teapot_install(tcl_root, tcltree): """ Workaround ActiveTcl on OS X @@ -59,9 +59,6 @@ def _handle_activetcl_install(tcl_root, tcltree): https://github.com/pyinstaller/pyinstaller/issues/621 """ - if not is_darwin: - # this is only relevant for ActiveTcl/OS X - return from PyInstaller.lib.macholib import util if util.in_system_path(tcl_root): @@ -80,9 +77,11 @@ def _handle_activetcl_install(tcl_root, tcltree): with open(init_resource, 'r') as init_file: for line in init_file.readlines(): line = line.strip().lower() - if 'activetcl' in line and not line.startswith('#'): + if line.startswith('#'): + continue + if 'activetcl' in line: mentions_activetcl = True - if 'teapot' in line and not line.startswith('#'): + if 'teapot' in line: mentions_teapot = True if mentions_activetcl and mentions_teapot: break @@ -191,8 +190,9 @@ def _collect_tkfiles(mod): tcltree = Tree(tcl_root, os.path.join('_MEI', tcldir), excludes=['demos', '*.lib', 'tclConfig.sh']) - # handle workaround for ActiveTcl on OS X - _handle_activetcl_install(tcl_root, tcltree) + if is_darwin: + # handle workaround for ActiveTcl on OS X + _warn_if_actvivetcl_or_teapot_install(tcl_root, tcltree) tktree = Tree(tk_root, os.path.join('_MEI', tkdir), excludes=['demos', '*.lib', 'tkConfig.sh'])