Silence errors caused by missing pep8. #383

Closed
apetresc opened this Issue Jan 26, 2012 · 12 comments

2 participants

@apetresc

I love the pep8 plugin and I certainly don't want to disable it. However, sometimes I'm running in a virtualenv where I don't have pep8 installed for whatever reason. In those situations, janus' pep8 plugin throws an exception on every single keystroke, of the form:

Error detected while processing CursorMoved Auto commands for "<buffer=1>":
E117: Unknown function: <SNR>98_GetMessage

This makes vim completely unusable, since you have to acknowledge an error message with each character you type.

Is there any way we can have the pep8 plugin silently fail if pep8 is not on the current PYTHONPATH?

Again, I don't want to disable it, it's useful most of the time, it's just that PYTHONPATHs can be a very volatile thing.

@adrianrego
carlhuda member

Are you switching virtualenvs after loading vim?

@apetresc

Not usually. Mostly I'll have separate iTerm tabs open for each project (many of which come with their own virtualenvs) at once. I'll run vim from any combination of those tabs.

Why, are you having trouble reproducing this?

@adrianrego
carlhuda member

I haven't been able to reproduce it. I pip uninstall pep8 and janus disables the plugin as intended.

@apetresc

Oh, interesting. Well, I'm interested in helping diagnose this, then; I am certainly not the only person who's running into this: #358

Any clues where to start digging?

@adrianrego
carlhuda member

we disable plugins that are missing dependencies in janus/vim/core/before/plugin/plugins.vim

i'm wondering if you're picking up the executable because it's in your $PATH but then it's not available in your virtualenv. I'll have a look when I'm back at my machine.

@apetresc

Interesting. executable("pep8") is correctly evaluating to false. I know this because I made the following change in plugins.vim:

echomsg("Here!")
" Pep8 requires pep8 installed
if !executable("pep8")
  echomsg("pep8 doesn't exist")
  call janus#disable_plugin("pep8", "The pep8 program is not installed")
endif

Sure enough, when I run this in a virtualenv that does have pep8, the second line isn't printed, and when I run it in a brand new virtualenv (or no virtualenv at all), the second line is printed!

So for some reason it looks like the actual call to disable pep8 is failing. I'll see if I can find out why.

@apetresc

Made a bit of progress diagnosing. I don't know much about how Janus works (or Vimscript in general), but janus#disable_plugin works by adding the plugin to this global structure called g:janus_disabled_plugins. This happens successfully, the pep8 plugins' path is making it into this structure.

There are two complementary functions, janus#is_plugin_disabled(name) and janus#is_plugin_enabled(name), which read this structure. I added an echomsg to each of these functions to print out the name of the plugin being checked for enable/disable status. Here's the result:

Checking if the following plugin is enabled: fugitive
Checking if the following plugin is disabled: fugitive
Checking if the following plugin is enabled: syntastic
Checking if the following plugin is disabled: syntastic
Checking if the following plugin is enabled: nerdcommenter
Checking if the following plugin is disabled: nerdcommenter
Checking if the following plugin is enabled: nerdcommenter
Checking if the following plugin is disabled: nerdcommenter
Checking if the following plugin is enabled: ack 
Checking if the following plugin is disabled: ack 
Checking if the following plugin is enabled: ctrlp
Checking if the following plugin is disabled: ctrlp
Checking if the following plugin is enabled: ctrlp
Checking if the following plugin is disabled: ctrlp
Checking if the following plugin is enabled: ctrlp
Checking if the following plugin is disabled: ctrlp
Checking if the following plugin is enabled: fugitive
Checking if the following plugin is disabled: fugitive
Checking if the following plugin is enabled: fugitive
Checking if the following plugin is disabled: fugitive
Checking if the following plugin is enabled: fugitive
Checking if the following plugin is disabled: fugitive
Checking if the following plugin is enabled: fugitive
Checking if the following plugin is disabled: fugitive
Checking if the following plugin is enabled: fugitive
Checking if the following plugin is disabled: fugitive
Checking if the following plugin is enabled: fugitive
Checking if the following plugin is disabled: fugitive
Checking if the following plugin is enabled: gist
Checking if the following plugin is disabled: gist
Checking if the following plugin is enabled: gundo
Checking if the following plugin is disabled: gundo
Checking if the following plugin is enabled: gundo
Checking if the following plugin is disabled: gundo
Checking if the following plugin is enabled: kwbd
Checking if the following plugin is disabled: kwbd
Checking if the following plugin is enabled: nerdtree
Checking if the following plugin is disabled: nerdtree
Checking if the following plugin is enabled: nerdtree
Checking if the following plugin is disabled: nerdtree
Checking if the following plugin is enabled: syntastic
Checking if the following plugin is disabled: syntastic
Checking if the following plugin is enabled: tagbar
Checking if the following plugin is disabled: tagbar
Checking if the following plugin is enabled: unimpaired
Checking if the following plugin is disabled: unimpaired
Checking if the following plugin is enabled: unimpaired
Checking if the following plugin is disabled: unimpaired
Checking if the following plugin is enabled: unimpaired
Checking if the following plugin is disabled: unimpaired
Checking if the following plugin is enabled: unimpaired
Checking if the following plugin is disabled: unimpaired
Checking if the following plugin is enabled: zoomwin
Checking if the following plugin is disabled: zoomwin

This is only a subset of all of janus' plugins. It doesn't include pep8, regardless of whether I run it in a virtualenv with or without it, and on a .py file or some other file. It never shows up.

Looking at janus.vim with my vimscript-beginner eyes, it looks like these functions which check for disabled plugins are only called in a single place: janus#add_mapping. If the name is any indication, this means the only time Janus checks if a module is disabled is when it needs to add a key mapping for it. Modules which don't have any mappings (like, I suppose, pep8) will never even look at the list of disabled plugins. It's easy to imagine this going unnoticed, since most people disable plugins because it interferes with some mapping that they prefer.

None of this explains why it seems to work fine for you though... any suggestions of where to go from here?

@adrianrego
carlhuda member

the disable_plugin function should also add the plugin to g:pathogen_disabled which should prevent pathogen from loading the plugin.

try echo &rtp after vim has loaded and check if there is a reference to pep8 in your vim runtimepath.

@apetresc

Yes, /Users/apetresc/.vim/janus/vim/tools/pep8 is on that path in both cases (in the virtualenv with pep8, and in the one without).

@apetresc

Hm, pathogen#is_disabled checks to see:

   elseif !exists("g:pathogen_disabled")

and by putting an echomsg there, I see that this evaluates to true for every single call that happens! (Which does include pep8).

Of course, g:pathogen_disabled is supposed to be created on line 194 of janus.vim, so I put an echomsg there too. It turns out this is called after all the calls to pathogen#is_disabled. First all the pathogen modules get loaded, and then everything gets added to the disabled list. That looks like it's definitely the cause of the problem.

I have no idea why this is the case, though. My janus install is totally vanilla.

@adrianrego adrianrego added a commit that closed this issue Jan 27, 2012
@adrianrego adrianrego source plugins.vim before loading pathogen
moved plugins.vim to core folder to prevent it from loading twice
thanks @apetresc closes #383
e17e410
@apetresc

Confirmed, works now. Thanks, Adrian!

@adrianrego
carlhuda member

thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment