ZyX wrote:
> > Interesting. So we would have a $VIMRUNTIME/python directory and we can
> > put Python scripts there that we include with the distribution.
> >
> > I'm sure it is only a small step that users will ask to have a python
> > directory in ~/.vim/python. Or more general, using 'runtimepath'.
> >
> > Then a plugin does not require to have its Python code in between a
> > :python << EOF and EOF. That would be a lot nicer, right?
> >
> > What do others think?
>
> Automatically adding all items from `&rtp` to sys.path would be good.
> It (and python3/) is already a standard directory in frawor for python
> files.
>
> But I would vote against the patch to os.chdir implemented in python
> and (as there is no better variant) for the solution based on
> comparing current directories before and after `os.chdir`:
>
> 1. Implementation based on comparing current directories can be
> written once and easily applied to all other interfaces.
> 2. `os.chdir` is most common, but not the only way to change
> directories from python: there are also at least `posix.chdir` and
> calls to libc (e.g. indirectly from some bindings or directly using
> ctypes, though I can’t imagine why the latter may be required).
> 3. Proposed implementation will break once somebody deletes `os` from
> sys.modules for some reason (I used to use this variant to reset `os`
> module after mocking its methods for testing purposes; though as for
> all non-builtin modules touching `sys.modules`).
I think this implies we need to get and save the current directory for
every Python command that is executed. Doesn't this add quite a bit of
overhead? I originally asked for some kind of hook or callback, so that
we can do something when Python changes directory at a lower level.
I suppose we do need to wait with the Vim implementation of :cd until
the Python command finishes. Thus os.chdir() would set a flag. Then
when the Python command restores the directory we don't need to do
anything. I would expect this to be quite common:
saved_curdir = os.cwd()
os.chdir(somewhere)
... do something with curdir ..
os.chdir(saved_curdir)
> About the implementation of `&rtp` handling: you can add there to
> `sys.path` a special path like `'_vim_runtimepaths_'` and add hook to
> `sys.path_hooks` that can handle it. Requires dropping python 2.2
> support (`path_hooks` were added in python 2.3), but you won’t then
> need to hack `options.c` to add or remove appropriate paths from
> `sys.path` when changing `&rtp`.
Do we need this kind of magic? Updating sys.path is much simpler and
also does not hide what we are doing (in case someone is debugging
what's going on). The only trick we need is when the user changes
'runtimepath'. But that would happen very infrequently.
--
Arthur pulls Pin out. The MONK blesses the grenade as ...
ARTHUR: (quietly) One, two, five ...
GALAHAD: Three, sir!
ARTHUR: Three.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.