vaanwd / Zeal

Zeal for Sublime Text 2/3
MIT License
184 stars 24 forks source link

Does not work on ST3 when installing via Package Control #1

Closed FichteFoll closed 10 years ago

FichteFoll commented 10 years ago

Your package does not work when it was installed via Package Control (or rather: installed using a sublime-package file). Since package on ST3 can be read from within .sublime-package files – and this is what ST prefers, see https://www.sublimetext.com/docs/3/packages.html – the file you want to copy does not exist on the target machine.

There is a feature in Package Control that tells it to extract the package by creating a .no-sublime-package file in the package root, but there is a better method for this. ST3 provides a sublime.load_resource() function that can open a package file's contents regardless of package position. See also https://github.com/Monnoroch/ColorHighlighter/pull/36#issuecomment-34321128.

Problematic source:

    if not os.path.exists(user_settings_path):
        shutil.copyfile(default_settings_path, user_settings_path)

Traceback:

Traceback (most recent call last):
  File "zeal in C:\Program Files\Sublime Text 3 Portable Beta\Data\Installed Packages\Zeal.sublime-package", line 209, in after_input
  File "zeal in C:\Program Files\Sublime Text 3 Portable Beta\Data\Installed Packages\Zeal.sublime-package", line 120, in open_zeal
  File "zeal in C:\Program Files\Sublime Text 3 Portable Beta\Data\Installed Packages\Zeal.sublime-package", line 20, in get_settings
  File "./shutil.py", line 109, in copyfile
    def copystat(src, dst):
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Program Files\\Sublime Text 3 Portable Beta\\Data\\Packages/Zeal/Zeal.sublime-settings'

Solution:

    if not os.path.exists(user_settings_path):
        if os.path.exists(default_settings_path):  # alternatively: `if int(sublime.version()) < 3000:`
            shutil.copyfile(default_settings_path, user_settings_path)
        else:
            with open(user_settings_path, 'w') as f:
                f.write(sublime.load_resource(default_settings_path))
vaanwd commented 10 years ago

Thank you! I will commit this changes very soon!

FichteFoll commented 10 years ago

I forgot that you have to create the path first if it doesn't exist. Likely not going to happen because the User package is pretty commen, but whatever.

    if not os.path.exists(user_path):
        os.makedirs(user_path)

Edit: You should also add "Python": {"lang": "python", "zeal_lang": "python"} to the default settings.