Skip to content

Commit

Permalink
Handle ActiveTcl installs on OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
pjrobertson committed Jan 29, 2015
1 parent 707e2e6 commit d2217c5
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion PyInstaller/hooks/hook-_tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit d2217c5

Please sign in to comment.