sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Wrong path separators of plugins' resource paths

Open deathaxe opened this issue 1 month ago • 0 comments

Description of the bug

Maybe not a big deal, but it is a bit unexpected to see backslashes in resource paths of Package.plugin.__loader__.resource_path.

Not sure if it is intentional, but in case forwars slashes are not causing problems, replacing os.path. methods by simpler string manipulations may even cause some CPU cycles.

diff --git a/python313/sublime_plugin.py b/python313/sublime_plugin.py
index 7c1ab12..01aeabc 100644
--- a/python313/sublime_plugin.py
+++ b/python313/sublime_plugin.py
@@ -2335,18 +2335,18 @@ class PackagePathFinder(importlib.abc.MetaPathFinder):
         self.packages[name] = package
 
     def find_spec(self, fullname, path, target=None):
-        parts = fullname.partition('.')
+        parts = fullname.split('.')
         archive = parts[0]
 
         package = self.packages.get(archive)
         if not package:
             return None
 
-        res_path = os.path.join('Packages', *fullname.split('.'))
+        res_path = 'Packages/' + '/'.join(parts)
 
         paths = [
-            (os.path.join(res_path, '__init__.pyc'), True, True),
-            (os.path.join(res_path, '__init__.py'), False, True),
+            (res_path + '/__init__.pyc', True, True),
+            (res_path + '/__init__.py', False, True),
             (res_path + '.pyc', True, False),
             (res_path + '.py', False, False),
         ]

Steps to reproduce

  1. Open ST's console
  2. import a plugin
  3. query for plugin's loader's resource_path attribute

Example:

>>> import xpath.xpath as xp
>>> xp.__loader__.resource_path
'Packages\\xpath\\xpath.py'

Expected behavior

Resource paths usually use forward slashs on all OSs.

Actual behavior

A plugin's / module's resource path contains backslash on Windows.

Sublime Text build number

4202

Operating system & version

Windows

(Linux) Desktop environment and/or window manager

No response

Additional information

No response

OpenGL context information


deathaxe avatar Dec 03 '25 17:12 deathaxe