mercurial/utils/resourceutil.py
branchstable
changeset 44219 aab70b540d3d
parent 44208 9e367157a990
child 44241 aea79f41ee55
equal deleted inserted replaced
44218:f010a80ec967 44219:aab70b540d3d
    32 # the location of data files matching the source code
    32 # the location of data files matching the source code
    33 if mainfrozen() and getattr(sys, 'frozen', None) != 'macosx_app':
    33 if mainfrozen() and getattr(sys, 'frozen', None) != 'macosx_app':
    34     # executable version (py2exe) doesn't support __file__
    34     # executable version (py2exe) doesn't support __file__
    35     datapath = os.path.dirname(pycompat.sysexecutable)
    35     datapath = os.path.dirname(pycompat.sysexecutable)
    36     _rootpath = datapath
    36     _rootpath = datapath
       
    37 
       
    38     # The installers store the files outside of library.zip, like
       
    39     # C:\Program Files\Mercurial\defaultrc\*.rc.  This strips the
       
    40     # leading "mercurial." off of the package name, so that these
       
    41     # pseudo resources are found in their directory next to the
       
    42     # executable.
       
    43     def _package_path(package):
       
    44         dirs = package.split(b'.')
       
    45         assert dirs[0] == b'mercurial'
       
    46         return os.path.join(_rootpath, *dirs[1:])
       
    47 
    37 else:
    48 else:
    38     datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__)))
    49     datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__)))
    39     _rootpath = os.path.dirname(datapath)
    50     _rootpath = os.path.dirname(datapath)
       
    51 
       
    52     def _package_path(package):
       
    53         return os.path.join(_rootpath, *package.split(b'.'))
    40 
    54 
    41 try:
    55 try:
    42     from importlib import resources
    56     from importlib import resources
    43 
    57 
    44     from .. import encoding
    58     from .. import encoding
    61             yield encoding.strtolocal(r)
    75             yield encoding.strtolocal(r)
    62 
    76 
    63 
    77 
    64 except (ImportError, AttributeError):
    78 except (ImportError, AttributeError):
    65 
    79 
    66     def _package_path(package):
       
    67         return os.path.join(_rootpath, *package.split(b'.'))
       
    68 
       
    69     def open_resource(package, name):
    80     def open_resource(package, name):
    70         path = os.path.join(_package_path(package), name)
    81         path = os.path.join(_package_path(package), name)
    71         return open(path, 'rb')
    82         return open(path, 'rb')
    72 
    83 
    73     def is_resource(package, name):
    84     def is_resource(package, name):