-
Notifications
You must be signed in to change notification settings - Fork 33
Switching to installed python when vim is not compiled with +python3 #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few notes.
ilya-bobyr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
A few minor notes.
| if !ollama#edit#HasEmbeddedPython() | ||
| echoerr "OllamaEdit features require Vim compiled with +python3 support." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the same error message is repeated after every invocation to ollama#edit#HasEmbeddedPython() maybe it would make sense to move the error message into the same function?
function! ollama#edit#EnsureEmbeddedPythonIsAvailable() abort
if exists('g:ollama_embedded_python') && g:ollama_embedded_python != 0
echoerr "OllamaEdit features require Vim compiled with +python3 support."
return v:true
else
return v:false
endif
endfunctionAnd then the usage looks like this:
if !ollama#edit#EnsureEmbeddedPythonIsAvailable()
return
endif|
|
||
| " Function to check if embedded Python is available | ||
| function! ollama#edit#HasEmbeddedPython() abort | ||
| return exists('g:ollama_embedded_python') && g:ollama_embedded_python != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor
In autoload/ollama/setup.vim only the value of g:ollama_embedded_python is checked:
if g:ollama_embedded_python
call s:SetupPyVEnv()
endifHere both existence and value are checked. While checking existence is more robust, if the assumption is that this value will always be set by the plugin setup code, the existence check becomes redundant.
In any case, it seems inconsistent to treat this variable one way in one location and another way in another.
I think either both locations should check existence, or neither should.
I would probably recommend the latter.
It would make the check simpler.
| venv_site_packages = os.path.join( | ||
| venv_path, | ||
| 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', | ||
| 'site-packages' | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor
If you are switching to vertical formatting, maybe format all the argument vertically:
| venv_site_packages = os.path.join( | |
| venv_path, | |
| 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', | |
| 'site-packages' | |
| ) | |
| venv_site_packages = os.path.join( | |
| venv_path, | |
| 'lib', | |
| f'python{sys.version_info.major}.{sys.version_info.minor}', | |
| 'site-packages' | |
| ) |
| sys.path.insert(0, venv_site_packages) | ||
| else: | ||
| print('Venv not found: '. venv_path) | ||
| print('Venv not found: ' + venv_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor
This has been fixed already.
It seems that this project uses merges for PRs, so maybe it does not matter much.
But if you rebase this minor fix should disappear.
I usually work with preinstalled versions of vim which doesn't have
+python3compiled and I see that in this case the plugin is fully disabled.This PR will switch to the python version installed in the system in case embedded python is not found and only
OllamaEditwill be disabled (error messages are displayed if the user tries to use it).