wbond / package_control

The Sublime Text package manager
https://packagecontrol.io
4.8k stars 814 forks source link

Can we have seprated package name and package file/folder name support. #598

Closed xpol closed 11 years ago

xpol commented 11 years ago

Some package name have spaces, which is not good for the ST3 import:

This works,

import Default.comment

But this is not for Markdown Preview plugin,

import Markdown Preview.markdown

And we wan't keep package name unchanged and rename the package filename/floder to MarkdownPreview.

Is there any way to do this smoothly? (User can upgrade form old filename/floder to new without knowing it has renamed).

FichteFoll commented 11 years ago
markdown_preview = __import__("Markdown Preview.markdown", globals(), locals(), [], 0)

is what is used in the docs; __import__ being translated to from the import statement. Maybe there is a better way of doing this , but it works. (Note: the preferred importlib can not be imported in ST)

Edit: Looking into sublime_plugin.py there doesn't seem to be another way to easily invoke the plugin-importing aside from __import__.

xpol commented 11 years ago

@FichteFoll thanks.

How about

form Markdown Preview.markdown import OneClass

Translate into __import()__.

Is it like this?

OneClass = __import__("Markdown Preview.markdown", globals(), locals(), [], 0).OneClass
wbond commented 11 years ago

No, I won't be implementing separate folder/package names since Sublime Text itself uses the folder/.sublime-package file name as the package name. Trying to make Package Control go against the grain is not worth it.

Your choices include:

  1. Using __import__
  2. Renaming your package to a name without spaces and adding a previous_names key to the channel JSON file
FichteFoll commented 11 years ago

@xpol, almost. See http://docs.python.org/3.3/library/functions.html#__import__.

xpol commented 11 years ago

Thanks @FichteFoll & @wbond.