Skip to content

Commit

Permalink
Depend: Improve error messages when reading a pefile files.
Browse files Browse the repository at this point in the history
* In ``matchDLLArch`` state the name of the affected file and
  terminate (what effetivly suppresses the traceback).
* In ``getImports``: No longer print the traceback, but state the
  name of the affected file.
  • Loading branch information
htgoebel committed Jan 23, 2019
1 parent d5a902d commit e984fe1
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions PyInstaller/depend/bindepend.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,23 @@ def matchDLLArch(filename):
return True

global _exe_machine_type
if _exe_machine_type is None:
exe_pe = pefile.PE(sys.executable, fast_load=True)
_exe_machine_type = exe_pe.FILE_HEADER.Machine
exe_pe.close()

pe = pefile.PE(filename, fast_load=True)

match_arch = pe.FILE_HEADER.Machine == _exe_machine_type
pe.close()
try:
if _exe_machine_type is None:
pefilename = sys.executable # for exception handling
exe_pe = pefile.PE(sys.executable, fast_load=True)
_exe_machine_type = exe_pe.FILE_HEADER.Machine
exe_pe.close()

pefilename = filename # for exception handling
pe = pefile.PE(filename, fast_load=True)
match_arch = pe.FILE_HEADER.Machine == _exe_machine_type
pe.close()
except pefile.PEFormatError as exc:
raise SystemExit('Can not get architecture from file: %s\n'
' Reason: %s' % (pefilename, exception))
return match_arch


def Dependencies(lTOC, xtrapath=None, manifest=None, redirects=None):
"""
Expand LTOC to include all the closure of binary dependencies.
Expand Down Expand Up @@ -724,8 +730,11 @@ def getImports(pth):
# dependencies should already have been handled by
# selectAssemblies in that case, so just warn, return an empty
# list and continue.
logger.warning('Can not get binary dependencies for file: %s', pth,
exc_info=1)
# For less specific errors also log the traceback.
logger.warning('Can not get binary dependencies for file: %s', pth)
logger.warning(
' Reason: %s', exception,
exc_info=not isinstance(exception, pefile.PEFormatError))
return []
elif is_darwin:
return _getImports_macholib(pth)
Expand Down

0 comments on commit e984fe1

Please sign in to comment.