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 finding location of wakatime-cli on Windows #117

Merged
merged 3 commits into from
Dec 25, 2021
Merged
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
63 changes: 31 additions & 32 deletions plugin/wakatime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ let s:VERSION = '9.0.1'
let path = path . '.exe'
endif

" Check for wakatime-cli installed via Homebrew
Copy link
Member

Choose a reason for hiding this comment

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

We still need this for Mac users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the user config is correct, there should be no problem.
If we are worried about failure, we should set these paths:

Homebrew
macOS Intel: /usr/local/bin
macOS ARM: /opt/homebrew/bin
Linux: /home/linuxbrew/.linuxbrew/bin
or: ~/.linuxbrew/bin

if !filereadable(path) && filereadable('/usr/local/bin/wakatime-cli')
let s:wakatime_cli = '/usr/local/bin/wakatime-cli'
" Check for wakatime-cli
if !filereadable(path) && executable('wakatime-cli')
let s:wakatime_cli = 'wakatime-cli'

" Check for wakatime binary in /usr/bin
elseif !filereadable(path) && filereadable('/usr/bin/wakatime')
let s:wakatime_cli = '/usr/bin/wakatime'
" Check for wakatime
elseif !filereadable(path) && executable('wakatime')
let s:wakatime_cli = 'wakatime'

" Default to ~/.wakatime/wakatime-cli-<os>-<arch>
else
Expand All @@ -144,17 +144,17 @@ let s:VERSION = '9.0.1'
endfunction

function! s:InstallCLI(use_external_python)
if !s:autoupdate_cli && filereadable(s:wakatime_cli)
if !s:autoupdate_cli && executable(s:wakatime_cli)
moeshin marked this conversation as resolved.
Show resolved Hide resolved
return
endif

let python_bin = s:false
let python_bin = ''
if a:use_external_python
let python_bin = s:GetPythonBinary()
endif

" First try install wakatime-cli in background, then using Vim's Python
if !empty(python_bin) && python_bin != s:false
moeshin marked this conversation as resolved.
Show resolved Hide resolved
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:has_async
Expand Down Expand Up @@ -371,36 +371,35 @@ EOF
if has('g:wakatime_PythonBinary')
let python_bin = g:wakatime_PythonBinary
endif
if !empty(python_bin) && !filereadable(python_bin) && !executable(python_bin)
if empty(python_bin) || !filereadable(python_bin) || !executable(python_bin)
if executable('python3')
let python_bin = 'python3'
elseif executable('python')
let python_bin = 'python'
endif
endif
if !empty(python_bin) && !filereadable(python_bin) && !executable(python_bin)
let paths = ['python3']
if s:IsWindows()
let pyver = 39
while pyver >= 27
let paths = paths + [printf('/Python%d/pythonw', pyver), printf('/python%d/pythonw', pyver), printf('/Python%d/python', pyver), printf('/python%d/python', pyver)]
let pyver = pyver - 1
endwhile
else
let paths = paths + ['/usr/bin/python3', '/usr/local/bin/python3', '/usr/bin/python3.6', '/usr/local/bin/python3.6', '/usr/bin/python', '/usr/local/bin/python', '/usr/bin/python2', '/usr/local/bin/python2']
endif
let paths = paths + ['python']
let index = 0
let limit = len(paths)
while index < limit
if filereadable(paths[index])
let python_bin = paths[index]
let index = limit
let paths = ['python3']
if s:IsWindows()
let pyver = 39
while pyver >= 27
let paths = paths + [printf('/Python%d/pythonw', pyver), printf('/python%d/pythonw', pyver), printf('/Python%d/python', pyver), printf('/python%d/python', pyver)]
let pyver = pyver - 1
endwhile
else
let paths = paths + ['/usr/bin/python3', '/usr/local/bin/python3', '/usr/bin/python3.6', '/usr/local/bin/python3.6', '/usr/bin/python', '/usr/local/bin/python', '/usr/bin/python2', '/usr/local/bin/python2']
endif
let index = index + 1
endwhile
let paths = paths + ['python']
let index = 0
let limit = len(paths)
while index < limit
if filereadable(paths[index])
let python_bin = paths[index]
let index = limit
endif
let index = index + 1
endwhile
endif
endif
if s:IsWindows() && !empty(python_bin) && (filereadable(printf('%sw', python_bin)) || executable(printf('%sw', python_bin)))
if !empty(python_bin) && 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
24 changes: 17 additions & 7 deletions scripts/install_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@
from urllib.error import HTTPError


def getOsName():
os = platform.system().lower()
if os.startswith('cygwin') or os.startswith('mingw') or os.startswith('msys'):
return 'windows'
return os


GITHUB_RELEASES_STABLE_URL = 'https://api.github.com/repos/wakatime/wakatime-cli/releases/latest'
GITHUB_DOWNLOAD_PREFIX = 'https://github.com/wakatime/wakatime-cli/releases/download'
PLUGIN = 'vim'

is_py2 = (sys.version_info[0] == 2)
is_py3 = (sys.version_info[0] == 3)
is_win = platform.system() == 'Windows'
is_win = getOsName() == 'windows'

HOME_FOLDER = None
CONFIGS = None
Expand All @@ -49,10 +56,13 @@ def main(home=None):
if not isCliLatest():
downloadCLI()

try:
os.symlink(getCliLocation(), os.path.join(getResourcesFolder(), 'wakatime-cli'))
except:
pass
cli = os.path.join(getResourcesFolder(), 'wakatime-cli')
if not os.path.exists(cli):
try:
os.symlink(getCliLocation(), cli)
except:
# May not have permission on Windows
pass


if is_py2:
Expand Down Expand Up @@ -223,7 +233,7 @@ def getCliLocation():

if not WAKATIME_CLI_LOCATION:
binary = 'wakatime-cli-{osname}-{arch}{ext}'.format(
osname=platform.system().lower(),
osname=getOsName(),
arch=architecture(),
ext='.exe' if is_win else '',
)
Expand Down Expand Up @@ -337,7 +347,7 @@ def extractVersion(text):


def cliDownloadUrl():
osname = platform.system().lower()
osname = getOsName()
arch = architecture()

validCombinations = [
Expand Down