Home Download Buy Blog Forum Support

ST3: Loading plugins from "Installed Packages" may fail ...

ST3: Loading plugins from "Installed Packages" may fail ...

Postby FichteFoll on Fri May 31, 2013 12:02 am

Sorry, the subject input is not long enough to describe the full issue.

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

Steps to reproduce:

  1. Create a "TestPackage.sublime-package" zip archive with a Python plugin file named "test.py" with the following content:
    Code: Select all
    print("testing")

  2. Place this package into your "Installed Packages" dir and restart ST. You will find the following in the console:
    Code: Select all
    reloading plugin TestPackage.test
    testing

  3. Now, go to your "Packages" dir and create a folder named "TestPackage". When restarting ST you will find the following:
    Code: Select all
    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". I know that the Packages dir is supposed to override the Installed Packages but it should only override those (files) if they actually exist.

Tested on Windows 7x64 with ST3 3035 Portable.

On issue tracker: https://github.com/SublimeText/Issues/issues/55
FichteFoll
 
Posts: 388
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby FichteFoll on Mon Jun 24, 2013 2:25 am

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:

    Code: Select all
    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:

    Code: Select all
    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'


---------------------

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
 
Posts: 388
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby jps on Mon Jun 24, 2013 7:01 am

FichteFoll: I believe these issues should be fixed in 3044, please let me know if they aren't
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby FichteFoll on Mon Jun 24, 2013 11:52 am

I'm still experiencing exactly the same issues as above with 3044:

Code: Select all
reloading plugin TestPackage.test
testing
[... other packages ...]
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'
FichteFoll
 
Posts: 388
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby jps on Tue Jun 25, 2013 1:30 am

Unfortunately, it's working for me. My setup is:

test.py in Installed Packages/TestPackage.sublime-package
test.py in Packages/TestPackage
test2.py in Packages/TestPackage

Both test.py and test2.py are getting imported as expected here in 3044.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby drifter on Tue Jun 25, 2013 2:06 am

On Linux it's working as expected. Tested on LMDE.
On Windows, it doesn't work at all - test.py seems to get imported without error but does not override, test2.py fails to import - as FichteFoll reported. Tested on Win8 x64 and WinXP 32-bit, with portable and installed versions of ST 3044.
drifter
 
Posts: 13
Joined: Tue Apr 23, 2013 12:17 pm

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby jps on Tue Jun 25, 2013 5:27 am

Thanks for the reports FichteFoll and Drifter, 3045 is out now fixing the issue on Windows
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby FichteFoll on Tue Jun 25, 2013 9:04 pm

Yes, confirmed to be working now with 3045. And even more, this is actually possible:

test.py in Installed Packages/TestPackage.sublime-package:
Code: Select all
print("testing")
some_var = "something"


test.py in Packages/TestPackage:
Code: Select all
print("before import")

from . import test

print("this module: " + __file__)
print("installed module: " + test.__file__)

print("some_var before: " + test.some_var)
test.some_var = "nothing"
print("overridden")


Which gives me this in the console:
Code: Select all
reloading plugin TestPackage.test
before import
testing
this module: C:\Program Files\Sublime Text 3 Portable Beta\Data\Installed Packages\TestPackage.sublime-package/TestPackage.test
installed module: C:\Program Files\Sublime Text 3 Portable Beta\Data\Installed Packages\TestPackage.sublime-package\test.py
some_var before: something
overridden


And in the console I can do this:
Code: Select all
>>> import TestPackage.test
>>> dir(TestPackage.test)
['__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', 'test']
>>> TestPackage.test.test
<module 'TestPackage.test.test' from 'C:\\Program Files\\Sublime Text 3 Portable Beta\\Data\\Installed Packages\\TestPackage.sublime-package\\test.py'>
>>> TestPackage.test.test.some_var
'nothing'


Yes, cool stuff because now I can for example override only parts of a single module/plugin and just import the rest.


However, it seems that this introduced a regression in terms of relative imports as seen here: https://github.com/wbond/sublime_packag ... issues/490 (Windows 8)
In particular:
Code: Select all
reloading plugin Package Control.Package Control
Traceback (most recent call last):
  File "C:\Users\Manuel\Programs\Sublime Text 3\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 1525, in _find_and_load_unlocked
  File "C:\Users\Manuel\Programs\Sublime Text 3\sublime_plugin.py", line 663, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "C:\Users\Manuel\Programs\Sublime Text 3\Data\Packages\Package Control\Package Control.py", line 60, in <module>
    from .package_control import reloader
ImportError: No module named 'Package Control.Package Control.package_control'
plugins loaded


Note that this works fine on my machine.
FichteFoll
 
Posts: 388
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby jps on Wed Jun 26, 2013 8:11 am

This should now be fixed in 3046.

The observed issue was caused by having a Package Control.sublime-package file, as well as Package Control extracted. The importer in sublime_plugin.py wasn't correctly distinguishing between packages and modules, which caused relative imports to work incorrectly.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: ST3: Loading plugins from "Installed Packages" may fail ...

Postby FichteFoll on Sat Jul 20, 2013 2:15 pm

With 3049 (and I think 3046 because that's probably the version I had before) the outlined behavior in my previous post no longer works. It now prints:

Code: Select all
reloading plugin TestPackage.test
before import
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 1525, in _find_and_load_unlocked
  File "C:\Program Files\Sublime Text 3 Portable Beta\sublime_plugin.py", line 671, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "C:\Program Files\Sublime Text 3 Portable Beta\Data\Packages\TestPackage\test.py", line 3, in <module>
    from . import test
ImportError: cannot import name test


This is essentially crutial because relative imports don't seem to work at all right now, not even with another module name.

I need to investigate this further though because it seems to work for Package Control. :S
FichteFoll
 
Posts: 388
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Next

Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 26 guests