Skip to content
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

Fix python in msys2 #124

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 44 additions & 28 deletions plugin/wakatime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ let s:VERSION = '9.0.1'
" Buffering heartbeats disabled in Windows, unless have async support
let s:buffering_heartbeats_enabled = s:has_async || s:nvim_async || !s:IsWindows()

" Fix for MSYS2 https://github.com/wakatime/vim-wakatime/issues/122
if s:IsWindows()
let result = matchlist(s:plugin_root_folder, '^/\([a-zA-Z]\)/.\+/\([a-zA-Z]\):/.\+')
if len(result) > 1 && toupper(result[1]) == toupper(result[2])
let s:plugin_root_folder = substitute(s:plugin_root_folder, '^/\([a-zA-Z]\)/.\+/\([a-zA-Z]\):/', '/\2/', '')
endif
endif

" Turn on autoupdate only when using default ~/.wakatime/wakatime-cli
let s:autoupdate_cli = s:false

Expand Down Expand Up @@ -150,17 +142,26 @@ let s:VERSION = '9.0.1'
" First try install wakatime-cli in background, then using Vim's Python
if !empty(python_bin)
let install_script = s:plugin_root_folder . '/scripts/install_cli.py'
let cmd = [python_bin, '-W', 'ignore', install_script, s:home]
if s:IsWindows() && &shell =~ 'cmd'
let job_cmd = split(&shell) + split(&shellcmdflag) + cmd
else
let job_cmd = split(&shell) + split(&shellcmdflag) + [s:JoinArgs(cmd)]
if s:IsWindows() && s:Chomp(system(s:JoinArgs([python_bin, '-VV'])) !~ 'MSC')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use system() during init because it slows down startup for all Windows users.

Copy link
Member

@alanhamlett alanhamlett Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work instead?

if s:IsWindows() && &shell =~ '/msys'

" MSYS2
let install_script = '/' . substitute(install_script, ':', '', '')
endif
let cmd = [python_bin, '-W', 'ignore', install_script, s:home]
if s:has_async
if s:IsWindows() && &shell =~ 'cmd'
let job_cmd = [&shell, &shellcmdflag] + cmd
else
let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
endif
let job = job_start(job_cmd, {
\ 'stoponexit': '',
\ 'callback': {channel, output -> s:AsyncInstallHandler(output)}})
elseif s:nvim_async
if s:IsWindows()
let job_cmd = cmd
else
let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
endif
let s:nvim_async_output = ['']
let job_opts = {
\ 'on_stdout': function('s:NeovimAsyncInstallOutputHandler'),
Expand Down Expand Up @@ -217,14 +218,19 @@ EOF
endif
let code = py . " import sys, vim;from os.path import abspath, join;sys.path.insert(0, abspath(join('" . s:plugin_root_folder . "', 'scripts')));from install_cli import main;main(home='" . s:home . "');"
let cmd = [v:progname, '-u', 'NONE', '-c', code, '+qall']
if s:IsWindows() && &shell =~ 'cmd'
let job_cmd = split(&shell) + split(&shellcmdflag) + cmd
else
let job_cmd = split(&shell) + split(&shellcmdflag) + [s:JoinArgs(cmd)]
endif
if s:has_async
if s:IsWindows() && &shell =~ 'cmd'
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_opts = {}
if !s:IsWindows()
let job_opts['detach'] = 1
Expand Down Expand Up @@ -500,12 +506,12 @@ EOF
set shell=sh shellredir=>%s\ 2>&1
endif

if s:IsWindows() && &shell =~ 'cmd'
let job_cmd = [&shell, &shellcmdflag] + cmd
else
let job_cmd = split(&shell) + split(&shellcmdflag) + [s:JoinArgs(cmd)]
endif
if s:has_async
if s:IsWindows() && &shell =~ 'cmd'
let job_cmd = [&shell, &shellcmdflag] + cmd
else
let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
endif
let job = job_start(job_cmd, {
\ 'stoponexit': '',
\ 'callback': {channel, output -> s:AsyncHandler(output, cmd)}})
Expand All @@ -514,6 +520,11 @@ EOF
call ch_sendraw(channel, extra_heartbeats . "\n")
endif
elseif s:nvim_async
if s:IsWindows()
let job_cmd = cmd
else
let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
endif
let s:nvim_async_output = ['']
let job_opts = {
\ 'on_stdout': function('s:NeovimAsyncOutputHandler'),
Expand Down Expand Up @@ -720,17 +731,22 @@ EOF

function! g:WakaTimeToday()
let cmd = [s:wakatime_cli, '--today']
if s:IsWindows() && &shell =~ 'cmd'
let job_cmd = [&shell, &shellcmdflag] + cmd
else
let job_cmd = split(&shell) + split(&shellcmdflag) + [s:JoinArgs(cmd)]
endif

if s:has_async
if s:IsWindows() && &shell =~ 'cmd'
let job_cmd = [&shell, &shellcmdflag] + cmd
else
let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
endif
let job = job_start(job_cmd, {
\ 'stoponexit': '',
\ 'callback': {channel, output -> s:AsyncTodayHandler(output, cmd)}})
elseif s:nvim_async
if s:IsWindows()
let job_cmd = cmd
else
let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
endif
let job_opts = {
\ 'on_stdout': function('s:NeovimAsyncTodayOutputHandler'),
\ 'on_stderr': function('s:NeovimAsyncTodayOutputHandler'),
Expand Down
16 changes: 11 additions & 5 deletions scripts/install_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,21 @@ def download(url, filePath):
def createSymlink():
if is_win:
link = os.path.join(getResourcesFolder(), 'wakatime-cli.exe')
if os.path.exists(link):
exists = os.path.exists(link)
if exists and not os.path.islink(link):
try:
os.remove(link)
exists = False
except:
log(traceback.format_exc())
try:
shutil.copy2(getCliLocation(), link)
except:
log(traceback.format_exc())
if not exists:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change this to try copying even when already exists, but only if we've successfully downloaded an updated wakatime-cli.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to master with 9c1c0b5 and bbfa0fb.

try:
os.symlink(getCliLocation(), link)
except:
try:
shutil.copy2(getCliLocation(), link)
except:
log(traceback.format_exc())
else:
link = os.path.join(getResourcesFolder(), 'wakatime-cli')
if not os.path.exists(link):
Expand Down