вторник, 4 июня 2013 г., 10:59:06 UTC+4 пользователь MarcWeber написал: > Excerpts from ZyX ZyX's message of Tue Jun 04 05:55:18 +0200 2013: > > I am no longer seeing why automatic sourcing of any python file from any > > directory should exist in case loadpyplugin() is implemented. > > It would be nice if you could include your idea about that function > in your gist: > https://gist.github.com/ZyX-I/5561409
Done, copy-pasting here: ============== Plugin loading ============== The following is additional stuff to ease creating python-only plugins by adding basic plugin management support: ``'pythoninstallprg'``/``'pip'`` and ``'python3installprg'``/``'pip3'`` options: Specify what program is used by ``:pyload``/``:py3load`` commands below in case importing failed. ``:pyload[!] module.submodule[ args]`` (and ``:py3load``) commands: Try to import ``module.submodule`` python module and run function ``__viminit__`` from it. In case importing module fails runs ``&pythoninstallprg . " " . args``. If there are no arguments uses ``module`` (without ``.submodule``) as an argument. Does not run ``&pythoninstallprg`` if bang was specified. If module was successfully imported, but it does not contain ``__viminit__`` function it errors out. Pseudo-code:: def pyload(module, args=None, bang=False): try: # Don't use this in real code, there is __import__! exec('import ' + module + ' as m') except ImportError: if not bang: vim.command('!' + vim.options['pip' + ('' if sys.version_info < (3,) else '3')] + + ' ' + (args or module.partition('.')[0])) pyload(module, bang=True) else: # Runs code if there was no exception, but outside of try: block # May raise AttributeError. Or any other error occurred in __viminit__ m.__viminit__() ``:confirm pyload`` should run confirmation before installing anything, otherwise program is installed using regular ``!`` (well, underlying C functions) without asking. ``silent pyload`` should supress any messages and installation process output like ``silent !pip install ...`` would do. I guess this part will be gained "for free". > > I'm interested in the following details: > > - where it should install the python code to (eg ~/.vim/pip or ~/.pip) Nowhere. It just calls pip and pip knows what to do. > Document a simple real world example: > P: a plugin > D: a dependency of P > call loadpyplugin('P', ..) ? There is setup.py. Dependencies are specified there. loadpyplugin() is here *only* for users, never for plugins. > - how you think a plugin writer should publish the plugin so that > everybody can use it easily (PyPi?) Anywhere reachable by pip. You can use 'git+git://github.com/Lokaltog/powerline' as a second argument to make pip install from that location. > - who is responsible for setting rtp, so that syntax/* etc will work We are talking about python-only plugins. What syntax/* or ftplugin/* in case of python-only? The only option here is using Filetype and Syntax events. Mixed python/vim are supposed to be managed as usual: via Vundle/VAM or manual installation from vim.org. It is though possible that runtimepath is modified based on the __file__ variable, but this is the responsibility of plugin. > - setting sys.path so that P and X related module will be found It is the job of pip. > - if pip is going to install something, will it ask me? (VAM does) With the function: not. I guess this need to be changed into the command so that :confirm can be used to force asking. Unless specifically requested to confirm it won't ask anything. > - if pip is going to install a dependency, do I going to ask me (VAM > does) Not in any case. Unless you take the pip sources and modify them to include something like --ask switch (this is why I added a note that `:pyload` will use regular `!`). > - should it be possible that one plugin requires another one / two > plugins require each other? Python-only plugins are not supposed to depend on vim ones. Other dependencies are specified in the setup.py as usual. Main idea is that python already has a package manager thus we don't want to invent another one. You can specify anything as &pythoninstallprg though, even `emerge` (it won't work unless under root though). There are even more then enough python packages with `pip install` argument identical to `emerge` one (it does not matter though because arguments may be any: if given they are not preprocessed in any fashion). > Marc Weber -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.