Commit 6a2ddc7e8b1e32037dbf57b14bf48f02435962ff

Authored by decalage2
1 parent c5c1b504

ezhexviewer: fixed absolute imports

Showing 1 changed file with 19 additions and 4 deletions
oletools/ezhexviewer.py
... ... @@ -16,7 +16,7 @@ Usage in a python application:
16 16  
17 17 ezhexviewer project website: http://www.decalage.info/python/ezhexviewer
18 18  
19   -ezhexviewer is copyright (c) 2012-2016, Philippe Lagadec (http://www.decalage.info)
  19 +ezhexviewer is copyright (c) 2012-2017, Philippe Lagadec (http://www.decalage.info)
20 20 All rights reserved.
21 21  
22 22 Redistribution and use in source and binary forms, with or without modification,
... ... @@ -47,16 +47,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 47 # 2016-09-06 v0.50 PL: - added main function for entry points in setup.py
48 48 # 2016-10-26 PL: - fixed to run on Python 2+3
49 49 # 2017-03-23 v0.51 PL: - fixed display of control characters (issue #151)
  50 +# 2017-04-26 PL: - fixed absolute imports (issue #141)
50 51  
51 52 __version__ = '0.51'
52 53  
53   -#------------------------------------------------------------------------------
  54 +#-----------------------------------------------------------------------------
54 55 # TODO:
55 56 # + options to set title and msg
56 57  
  58 +# === IMPORTS ================================================================
  59 +
  60 +import sys, os
  61 +
  62 +# IMPORTANT: it should be possible to run oletools directly as scripts
  63 +# in any directory without installing them with pip or setup.py.
  64 +# In that case, relative imports are NOT usable.
  65 +# And to enable Python 2+3 compatibility, we need to use absolute imports,
  66 +# so we add the oletools parent folder to sys.path (absolute+normalized path):
  67 +_thismodule_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
  68 +# print('_thismodule_dir = %r' % _thismodule_dir)
  69 +_parent_dir = os.path.normpath(os.path.join(_thismodule_dir, '..'))
  70 +# print('_parent_dir = %r' % _thirdparty_dir)
  71 +if not _parent_dir in sys.path:
  72 + sys.path.insert(0, _parent_dir)
57 73  
58   -from .thirdparty.easygui import easygui
59   -import sys
  74 +from oletools.thirdparty.easygui import easygui
60 75  
61 76 # === PYTHON 2+3 SUPPORT ======================================================
62 77  
... ...