Skip to content

Commit 782b89c

Browse files
[Fix] Use the sublime.(find|load)_resources APIs.
This commit fixes issues that cropped up because I had CommandsBrowser in the packages directory. I was loading JSON files directly from the folder, but when the package will be installed, that folder will go into the installed packages and hence not available. So it can't read the files. So, the above API usage will ensure that it works when both installed & git cloned.
1 parent e677016 commit 782b89c

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

commands_browser.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ def plugin_loaded():
2121
"""
2222
load_commands_browser_settings()
2323

24+
browse_33_resource = [a for a in sublime.find_resources("*.py") if a.startswith("Packages/CommandsBrowser/src/py33")][0]
25+
2426
commands_browser_33_path = os.path.join(sublime.packages_path(), "CommandsBrowser33")
25-
file_to_copy_path = os.path.join(sublime.packages_path(), "CommandsBrowser", "src/py33/browse.py")
2627
dest_file_path = os.path.join(commands_browser_33_path, "browse.py")
28+
2729
if not os.path.exists(commands_browser_33_path):
2830
os.makedirs(commands_browser_33_path)
2931
if not os.path.exists(dest_file_path):
30-
with open(dest_file_path, "w"):
31-
pass
32-
33-
try:
34-
shutil.copyfile(file_to_copy_path, dest_file_path)
35-
except Exception as e:
36-
print(f"[CommandsBrowser]: Failed to add CommandsBrowser33 with exception {e}")
32+
with open(dest_file_path, "w") as f:
33+
f.write(sublime.load_resource(browse_33_resource))
3734

3835

3936
def plugin_unloaded():

src/utils/core_commands_utils.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@ def get_core_commands_data(application = "st"):
8282
Returns:
8383
final_dict (Dict): The final dictionary of commands and their docs.
8484
"""
85-
package_path = os.path.join(sublime.packages_path(), "CommandsBrowser")
86-
metadata_folder = os.path.join(package_path, f"{application}_commands_metadata")
87-
json_file_names = [name + ".json" for name in list(string.ascii_lowercase)]
85+
86+
json_file_names = [a for a in sublime.find_resources("*.json") if a.startswith(f"Packages/CommandsBrowser/{application}_commands_metadata")]
8887
final_dict = {}
8988
for file_name in json_file_names:
90-
with open(os.path.join(metadata_folder, file_name), "r") as file:
91-
data = json.loads(file.read())
92-
if data is not None:
93-
final_dict.update(data)
89+
data = json.loads(sublime.load_resource(file_name))
90+
if data is not None:
91+
final_dict.update(data)
9492
return final_dict

0 commit comments

Comments
 (0)