Show More
@@ -34,10 +34,24 b" if mainfrozen() and getattr(sys, 'frozen" | |||||
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) | |
40 |
|
51 | |||
|
52 | def _package_path(package): | |||
|
53 | return os.path.join(_rootpath, *package.split(b'.')) | |||
|
54 | ||||
41 | try: |
|
55 | try: | |
42 | from importlib import resources |
|
56 | from importlib import resources | |
43 |
|
57 | |||
@@ -63,9 +77,6 b' try:' | |||||
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') |
General Comments 0
You need to be logged in to leave comments.
Login now