Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading plugins from "Installed Packages" fails if a corresponding dir exists in "Packages" #55

Closed
FichteFoll opened this issue May 30, 2013 · 3 comments

Comments

@FichteFoll
Copy link
Collaborator

Loading plugins from "Installed Packages" archives fails when a directory with the same name exists in "Packages".

Steps to reproduce

  • Create a "TestPackage.sublime-package" zip archive with a Python plugin file named "test.py" with the following content:

    print("testing")
  • Place this package into your "Installed Packages" dir and restart ST. You will find the following in the console:

    reloading plugin TestPackage.test
    testing
    
  • Now, go to your "Packages" dir and create a folder named "TestPackage". When restarting ST you will find the following:

    reloading plugin TestPackage.test
    Traceback (most recent call last):
    File "C:\Program Files\Sublime Text 3 Portable Beta\sublime_plugin.py", line 73, in reload_plugin
      m = importlib.import_module(modulename)
    File "X/importlib/__init__.py", line 88, in import_module
    File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1522, in _find_and_load_unlocked
    ImportError: No module named 'TestPackage.test'
    

Expected behaviour

"test.py" loads successfully and prints "testing" when the module is not overridden. I know that the Packages dir is supposed to override the Installed Packages but it should only override those (files) if they actually exist.

Note: This is gonna get complicated when plugins are importing modules relative from their dir. Would it be possible to replace certain modules only in this situation?

Tested on Windows 7x64 with ST3 3035 Portable.

Forum link: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=12564

FichteFoll added a commit to SublimeText/InactivePanes that referenced this issue May 31, 2013
This requires a few workarounds but I also decided to assume that "Package/..."
paths are the only accepted for color schemes. This should very rarely result
in issues if at all and simplifies the path math a lot.
Furthermore, work around a bug in ST which prevents me from creating a dir
named `module_path` in the Packages dir. See sublimehq/sublime_text#55.
@FichteFoll
Copy link
Collaborator Author

Said to be fixed now according to http://www.sublimetext.com/forum/viewtopic.php?f=2&t=12814&p=50072#p50072 but I will test this later.

@FichteFoll
Copy link
Collaborator Author

As of 3043 the particular error in this issue has been fixed (loading modules when a folder with an installed package's name exists fails) but overriding installed packages is still not working that great.

For instance (assuming the same file structure as above):

  • Create a file named Packages/TestPackage/test.py and put something like print("not testing") in it. Console after restarting/saving:

    reloading plugin TestPackage.test
    testing
    
  • Create a file named Packages/TestPackage/test2.py and enter something like print("testing again") (contents don't matter). Console after restarting/saving:

    reloading plugin TestPackage.test2
    Traceback (most recent call last):
    File "C:\Program Files\Sublime Text 3 Portable Beta\sublime_plugin.py", line 73, in reload_plugin
      m = importlib.import_module(modulename)
    File "X/importlib/__init__.py", line 88, in import_module
    File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1522, in _find_and_load_unlocked
    ImportError: No module named 'TestPackage.test2'
    

New issue?


I actually wanted to test this but due to the above error it wouldn't work: Can I import moduels from installed packages from the same "uninstalled" package? E.g., would from . import test work in test2.py?

@FichteFoll
Copy link
Collaborator Author

The above concerns have been fixed with 3045 and another bug in 3046, marking this as fixed. Read the forum thread linked in the first post for more information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant