randy3k / AutomaticPackageReloader

Automatically reload submodules while developing a Sublime Text package.
MIT License
38 stars 13 forks source link

Use sublime.find_resources instead of os.listdir to find plugins. #23

Closed Thom1729 closed 5 years ago

Thom1729 commented 5 years ago

In reload_plugin, os.listdir was used to find top-level plugins. This fails when the package in question is zipped (such as an installed package). Ordinarily, this wouldn't matter, because reloading is triggered when you edit a package file (which is by definition not zipped). However, there are two situations in which this could fail:

  1. You're reloading a file in an override, and non-overridden files in the installed package refer to the overridden file.
  2. You're reloading a dependency, and an installed package refers to that dependency.

In either case, os.listdir will raise FileNotFoundError.

This PR uses sublime.find_resources instead of os.listdir to find top-level plugin scripts. It should cover both these cases. Outside these cases, there should be no change in behavior.

Note: posixpath is used to manipulate the resource paths. This should be correct regardless of the underlying platform. As an alternative, I suggest that sublime_lib.ResourcePath might help to simplify this logic and a good deal of other path-related logic in this package. Adding a sublime_lib dependency is outside the scope of this PR.

randy3k commented 5 years ago

Thanks for the work.

Adding a sublime_lib dependency is outside the scope of this PR.

I agree.

randy3k commented 5 years ago

Thomas, I have added you as a collaborator because you have some better understanding of some part of the code than I do. It's okay if you don't want to be a collaborator though.