Show More
@@ -34,10 +34,24 b" if mainfrozen() and getattr(sys, 'frozen" | |||
|
34 | 34 | # executable version (py2exe) doesn't support __file__ |
|
35 | 35 | datapath = os.path.dirname(pycompat.sysexecutable) |
|
36 | 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 | 48 | else: |
|
38 | 49 | datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__))) |
|
39 | 50 | _rootpath = os.path.dirname(datapath) |
|
40 | 51 | |
|
52 | def _package_path(package): | |
|
53 | return os.path.join(_rootpath, *package.split(b'.')) | |
|
54 | ||
|
41 | 55 | try: |
|
42 | 56 | from importlib import resources |
|
43 | 57 | |
@@ -63,9 +77,6 b' try:' | |||
|
63 | 77 | |
|
64 | 78 | except (ImportError, AttributeError): |
|
65 | 79 | |
|
66 | def _package_path(package): | |
|
67 | return os.path.join(_rootpath, *package.split(b'.')) | |
|
68 | ||
|
69 | 80 | def open_resource(package, name): |
|
70 | 81 | path = os.path.join(_package_path(package), name) |
|
71 | 82 | return open(path, 'rb') |
General Comments 0
You need to be logged in to leave comments.
Login now