Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/resourceutil.py @ 44303:aea79f41ee55
resourceutil: blacken
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 03 Feb 2020 11:56:02 -0500 |
parents | aab70b540d3d |
children | 6c8384afbf77 |
comparison
equal
deleted
inserted
replaced
44302:15eb90965a00 | 44303:aea79f41ee55 |
---|---|
28 or imp.is_frozen("__main__") # old py2exe | 28 or imp.is_frozen("__main__") # old py2exe |
29 ) # tools/freeze | 29 ) # tools/freeze |
30 | 30 |
31 | 31 |
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 | 37 |
38 # The installers store the files outside of library.zip, like | 38 # The installers store the files outside of library.zip, like |
39 # C:\Program Files\Mercurial\defaultrc\*.rc. This strips the | 39 # C:\Program Files\Mercurial\defaultrc\*.rc. This strips the |
40 # leading "mercurial." off of the package name, so that these | 40 # leading "mercurial." off of the package name, so that these |
41 # pseudo resources are found in their directory next to the | 41 # pseudo resources are found in their directory next to the |
42 # executable. | 42 # executable. |
43 def _package_path(package): | 43 def _package_path(package): |
44 dirs = package.split(b'.') | 44 dirs = package.split(b".") |
45 assert dirs[0] == b'mercurial' | 45 assert dirs[0] == b"mercurial" |
46 return os.path.join(_rootpath, *dirs[1:]) | 46 return os.path.join(_rootpath, *dirs[1:]) |
47 | |
47 | 48 |
48 else: | 49 else: |
49 datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__))) | 50 datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__))) |
50 _rootpath = os.path.dirname(datapath) | 51 _rootpath = os.path.dirname(datapath) |
51 | 52 |
52 def _package_path(package): | 53 def _package_path(package): |
53 return os.path.join(_rootpath, *package.split(b'.')) | 54 return os.path.join(_rootpath, *package.split(b".")) |
55 | |
54 | 56 |
55 try: | 57 try: |
56 from importlib import resources | 58 from importlib import resources |
57 | 59 |
58 from .. import encoding | 60 from .. import encoding |
77 | 79 |
78 except (ImportError, AttributeError): | 80 except (ImportError, AttributeError): |
79 | 81 |
80 def open_resource(package, name): | 82 def open_resource(package, name): |
81 path = os.path.join(_package_path(package), name) | 83 path = os.path.join(_package_path(package), name) |
82 return open(path, 'rb') | 84 return open(path, "rb") |
83 | 85 |
84 def is_resource(package, name): | 86 def is_resource(package, name): |
85 path = os.path.join(_package_path(package), name) | 87 path = os.path.join(_package_path(package), name) |
86 | 88 |
87 try: | 89 try: |