Skip to content

Commit

Permalink
Fix slow startup on Windows when Python not installed on machine
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Dec 10, 2021
1 parent 02405f1 commit 0e9d48c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
55 changes: 51 additions & 4 deletions plugin/wakatime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -192,29 +192,69 @@ let s:VERSION = '9.0.1'
endif
endif
elseif has('python3')
python3 << EOF
if executable(v:progname)
call s:InstallCLIRoundAbout()
else
python3 << EOF
import sys
import vim
from os.path import abspath, join
sys.path.insert(0, abspath(join(vim.eval('s:plugin_root_folder'), 'scripts')))
from install_cli import main
main(home=vim.eval('s:home'))
EOF
endif
elseif has('python')
python << EOF
if executable(v:progname)
call s:InstallCLIRoundAbout()
else
python << EOF
import sys
import vim
from os.path import abspath, join
sys.path.insert(0, abspath(join(vim.eval('s:plugin_root_folder'), 'scripts')))
from install_cli import main
main(home=vim.eval('s:home'))
EOF
endif
else
let url = printf('https://github.com/wakatime/wakatime-cli/releases/latest/download/wakatime-cli-%s-%s.zip', s:osname, s:architecture)
echo printf("Download wakatime-cli and extract into the ~/.wakatime/ folder:\n%s", url)
endif
endfunction

function! s:InstallCLIRoundAbout()
let install_script = s:plugin_root_folder . '/scripts/install.vim'
let cmd = [v:progname, '-u', 'NONE', '-c', 'source ' . install_script, '+qall']
if s:has_async
if s:IsWindows()
let job_cmd = [&shell, &shellcmdflag] + cmd
else
let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
endif
let job = job_start(job_cmd, {'stoponexit': ''})
elseif s:nvim_async
if s:IsWindows()
let job_cmd = cmd
else
let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
endif
let job = jobstart(job_cmd, {'detach': 1})
elseif s:IsWindows()
if s:is_debug_on
let stdout = system('(' . s:JoinArgs(cmd) . ')')
else
exec 'silent !start /b cmd /c "' . s:JoinArgs(cmd) . ' > nul 2> nul"'
endif
else
if s:is_debug_on
let stdout = system(s:JoinArgs(cmd))
else
let stdout = system(s:JoinArgs(cmd) . ' &')
endif
endif
endfunction

" }}}


Expand Down Expand Up @@ -332,7 +372,14 @@ EOF
if has('g:wakatime_PythonBinary')
let python_bin = g:wakatime_PythonBinary
endif
if !filereadable(python_bin)
if !filereadable(python_bin) && !executable(python_bin)
if executable('python3')
let python_bin = 'python3'
elseif executable('python')
let python_bin = 'python'
endif
endif
if !filereadable(python_bin) && !executable(python_bin)
let paths = ['python3']
if s:IsWindows()
let pyver = 39
Expand All @@ -354,7 +401,7 @@ EOF
let index = index + 1
endwhile
endif
if s:IsWindows() && filereadable(printf('%sw', python_bin))
if s:IsWindows() && (filereadable(printf('%sw', python_bin)) || executable(printf('%sw', python_bin)))
let python_bin = printf('%sw', python_bin)
endif
return python_bin
Expand Down
26 changes: 26 additions & 0 deletions scripts/install.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let s:home = expand("$WAKATIME_HOME")
if s:home == '$WAKATIME_HOME'
let s:home = expand("$HOME")
endif

let s:plugin_root_folder = substitute(expand("<sfile>:p:h:h"), '\', '/', 'g')

if has('python3')
python3 << EOF
import sys
import vim
from os.path import abspath, join
sys.path.insert(0, abspath(join(vim.eval('s:plugin_root_folder'), 'scripts')))
from install_cli import main
main(home=vim.eval('s:home'))
EOF
elseif has('python')
python << EOF
import sys
import vim
from os.path import abspath, join
sys.path.insert(0, abspath(join(vim.eval('s:plugin_root_folder'), 'scripts')))
from install_cli import main
main(home=vim.eval('s:home'))
EOF
endif

0 comments on commit 0e9d48c

Please sign in to comment.