Skip to content

Commit 93fb959

Browse files
Thomas SmithThomas Smith
authored andcommitted
Accounted for a couple edge cases.
1 parent 9e875c8 commit 93fb959

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

st3/sublime_lib/resource_path.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,13 @@ def from_file_path(cls, file_path):
108108

109109
for base in get_installed_resource_roots():
110110
try:
111-
package, *rest = file_path.relative_to(base).parts
111+
rel = file_path.relative_to(base).parts
112112
except ValueError:
113113
pass
114114
else:
115+
if rel == ():
116+
return cls('Packages')
117+
package, *rest = rel
115118
package_path = cls('Packages', package)
116119
if package_path.suffix == '.sublime-package':
117120
return package_path.with_suffix('').joinpath(*rest)

tests/test_resource_path.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def test_from_file_path_installed_packages_not_installed(self):
5858
Path(sublime.installed_packages_path(), 'test_package', 'foo.py')
5959
),
6060

61+
def test_from_file_path_installed_packages_root(self):
62+
self.assertEqual(
63+
ResourcePath.from_file_path(Path(sublime.installed_packages_path())),
64+
ResourcePath("Packages")
65+
)
66+
6167
def test_from_file_path_default_packages(self):
6268
self.assertEqual(
6369
ResourcePath.from_file_path(
@@ -68,6 +74,14 @@ def test_from_file_path_default_packages(self):
6874
ResourcePath("Packages/test_package/foo.py")
6975
)
7076

77+
def test_from_file_path_default_packages_root(self):
78+
self.assertEqual(
79+
ResourcePath.from_file_path(
80+
Path(sublime.executable_path()).parent / 'Packages'
81+
),
82+
ResourcePath("Packages")
83+
)
84+
7185
def test_from_file_path_error(self):
7286
with self.assertRaises(ValueError):
7387
ResourcePath.from_file_path(Path('/test_package')),

0 commit comments

Comments
 (0)