Sublime Forum

Python Errors When Loaded Through Package Control

#1

I seem to be having a problem with my now published package. When I try to install it from Package Control, and then have a VHDL file, I get the following error: error: Error loading syntax file "Packages/vhdl_mode/VHDL.sublime-syntax": Unable to read Packages/vhdl_mode/VHDL.sublime-syntax. Now, I’ve looked at the .sublime-package file and the VHDL syntax is in there.

The only clue I’ve got is that Package/vhdl_mode is where I used to develop it. Is there something in Sublime that would have saved a reference to that?

EDIT: Actually, I might have found it. I’d opened ST3 and had a bunch of VHDL files already loaded. They were all with white lettering. However if I clicked the language tile in the corner and RESELECTED the language, they’re okay. Is the source of the syntax stored in the workspace?

EDIT2: Well hell, there is another error. The Python main file is not loading properly now, when it worked fine in its own directory. It has to do with the import scoping.

So during all of development, I kept everything in the packages directory under User/vhdl_mode. I discovered that when I was loading my secondary packages, I ended up having to scope them under the package name. So I have the following lines:

import vhdl_mode.vhdl_lang as vhdl
import vhdl_mode.vhdl_util as util

However now when ST3 starts up, it’s creating the error:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 109, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 915, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "vhdl_mode in C:\Users\mnorton\AppData\Roaming\Sublime Text 3\Installed Packages\VHDL Mode.sublime-package", line 16, in <module>
ImportError: No module named 'vhdl_mode'

Does the import hierarchy change when in a Package Control repository?

EDIT3: I changed the title to be more relevant. I think the language setting had to be due to the fact I had a workspace already initiated. Every other VHDL file after that was lexically handled. My commands are screwed but that’s a different error.

0 Likes

#2

I seem to remember that your package name was not “vhdl_mode” but that’s what you expect the package folder to be. There are workarounds for this, however.

For python imports, just use relative imports from within the package. For the syntax file, you likely have a hard-coded path reference. You can determine the containing package name with __package__.split(".")[0].

0 Likes

#3

Well when I developed originally, I put things into %appdata%\Sublime Text 3\Packages\vhdl_mode. I had two ancillary modules vhdl_util and vhdl_lang (utility methods and language methods). I found early that I couldn’t just import them as named. It seemed like however ST3 was arranging packages that there was an additional layer of scope. So I had to do import vhdl_mode.vhdl_util. It wouldn’t work any other way.

I’ll have to check some other packages that have ancillary modules and see if there’s something there. Maybe once it gets wrapped into the package zip, I can get rid of the initial vhdl_mode scope.

0 Likes

#4

With relative imports you can just use from . import vhdl_util as util instead of import vhdl_mode.vhdl_util as util

4 Likes

#5

Thank you so much. Finally back in town. I’ve felt bad that it got released at the most inappropriate time personally for fixing anything as I had to go out of town to fight a problem at a different plant. However I’m back and should have an opportunity to see if I can fix this today!

If I just update the source in github, create a new version tag, will Package Control pick it up automatically? Or do I need to issue a new pull request to Package Control? (I’m hoping it just updates automatically if I do proper version control.)

0 Likes

#6

Package Control will pick it up automatically.

0 Likes

#7

Great. I think I have the change set integrated and I created a new release. At least now people can get a proper chance to try it out.

0 Likes

#8

Usually I try to spot errors like these, but I may have been tired when looking at your package in particular.

0 Likes

#9

Not your fault at all. Always lies with the coder in the first place. I hadn’t realized that my ‘solution’ to the module loading was not a particularly good solution (and now, to be honest. I’m not entirely sure why it worked to begin with).

In any event, bug is fixed, Package Control has caught up with the release, and it works! Thank you.

0 Likes

#10

It worked because your local package was named vhdl_mode, but it fails for other users because you published it with the name VHDL Mode.

2 Likes

#11

Yeah, when the package name stays the same it makes no difference for absolute import statements. Wether it’s in “Installed Packages” or “Packages” also doesn’t matter.

1 Like

#12

Okay. I was never completely clear if it was a thing Sublime Text did with scoping the python modules it imports for packages (dots usually mean scope or class hierarchy) or if it was Python’s way of dealing with directories (I was originally in that vhdl_mode directory for development. Having the name be the same does definitely confuse matters.

This morning I am realizing I had a lot of things also break because they were looking in vhdl_mode so I’ve been trying to clean that up as well. I think I’ve got them covered now, but it’s always interesting to find out what fresh new issue I’ve managed to bungle when the Package Control database updates and the plugin updates :slight_smile:

0 Likes