Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 31074:2912b06905dc
py3: use pycompat.fsencode() to convert __file__ to bytes
__file__ returns unicodes on Python 3. This patch uses pycompat.fsencode() to
convert them to bytes.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 20 Feb 2017 18:40:42 +0530 |
parents | d194f0dba7ac |
children | 3f8f53190d6a |
comparison
equal
deleted
inserted
replaced
31073:2cf1e5207fdf | 31074:2912b06905dc |
---|---|
953 # the location of data files matching the source code | 953 # the location of data files matching the source code |
954 if mainfrozen() and getattr(sys, 'frozen', None) != 'macosx_app': | 954 if mainfrozen() and getattr(sys, 'frozen', None) != 'macosx_app': |
955 # executable version (py2exe) doesn't support __file__ | 955 # executable version (py2exe) doesn't support __file__ |
956 datapath = os.path.dirname(pycompat.sysexecutable) | 956 datapath = os.path.dirname(pycompat.sysexecutable) |
957 else: | 957 else: |
958 datapath = os.path.dirname(__file__) | 958 datapath = os.path.dirname(pycompat.fsencode(__file__)) |
959 | |
960 if not isinstance(datapath, bytes): | |
961 datapath = pycompat.fsencode(datapath) | |
962 | 959 |
963 i18n.setdatapath(datapath) | 960 i18n.setdatapath(datapath) |
964 | 961 |
965 _hgexecutable = None | 962 _hgexecutable = None |
966 | 963 |
978 if getattr(sys, 'frozen', None) == 'macosx_app': | 975 if getattr(sys, 'frozen', None) == 'macosx_app': |
979 # Env variable set by py2app | 976 # Env variable set by py2app |
980 _sethgexecutable(encoding.environ['EXECUTABLEPATH']) | 977 _sethgexecutable(encoding.environ['EXECUTABLEPATH']) |
981 else: | 978 else: |
982 _sethgexecutable(pycompat.sysexecutable) | 979 _sethgexecutable(pycompat.sysexecutable) |
983 elif os.path.basename(getattr(mainmod, '__file__', '')) == 'hg': | 980 elif (os.path.basename( |
984 _sethgexecutable(mainmod.__file__) | 981 pycompat.fsencode(getattr(mainmod, '__file__', ''))) == 'hg'): |
982 _sethgexecutable(pycompat.fsencode(mainmod.__file__)) | |
985 else: | 983 else: |
986 exe = findexe('hg') or os.path.basename(sys.argv[0]) | 984 exe = findexe('hg') or os.path.basename(sys.argv[0]) |
987 _sethgexecutable(exe) | 985 _sethgexecutable(exe) |
988 return _hgexecutable | 986 return _hgexecutable |
989 | 987 |