Skip to content

Commit d2f42d6

Browse files
authored
Remove support for Python2 (#1129)
Python 3 is > 10 years old and Python 2 will no longer be supported in a few months. Time to get rid of it, simplifying the code base (slightly) and opening the opportunities to use the Py3 quality of life improvements.
1 parent 7dc30c5 commit d2f42d6

38 files changed

+169
-390
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.pyc
22
*.swp
33
doc/tags
4-
.ropeproject/
4+
/.ropeproject/
5+
/.mypy_cache/

Diff for: .travis.yml

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ sudo: required
22
services: docker
33

44
env:
5-
- VIM_VERSION="7.4" PYTHON_IMAGE=2.7-stretch TAG=vim_74_py2
6-
- VIM_VERSION="8.0" PYTHON_IMAGE=2.7-stretch TAG=vim_80_py2
7-
- VIM_VERSION="8.1" PYTHON_IMAGE=2.7-stretch TAG=vim_81_py2
8-
- VIM_VERSION="git" PYTHON_IMAGE=2.7-stretch TAG=vim_git_py2
95
- VIM_VERSION="7.4" PYTHON_IMAGE=3.6-stretch TAG=vim_74_py36
106
- VIM_VERSION="8.0" PYTHON_IMAGE=3.6-stretch TAG=vim_80_py36
117
- VIM_VERSION="8.1" PYTHON_IMAGE=3.6-stretch TAG=vim_81_py36

Diff for: Makefile

-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@ MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
22
MAKEFILE_DIR := $(dir ${MAKEFILE_PATH})
33

44
# Test images as run on CI.
5-
image_vim_74_py2:
6-
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=2.7-stretch --build-arg VIM_VERSION=7.4 .
7-
image_vim_80_py2:
8-
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=2.7-stretch --build-arg VIM_VERSION=8.0 .
9-
image_vim_81_py2:
10-
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=2.7-stretch --build-arg VIM_VERSION=8.1 .
11-
image_vim_git_py2:
12-
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=2.7-stretch --build-arg VIM_VERSION=git .
135
image_vim_74_py36:
146
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.6-stretch --build-arg VIM_VERSION=7.4 .
157
image_vim_80_py36:

Diff for: after/plugin/UltiSnips_after.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Called after everything else to reclaim keys (Needed for Supertab)
22

3-
if exists("b:did_after_plugin_ultisnips_after") || !exists("g:_uspy")
3+
if exists("b:did_after_plugin_ultisnips_after")
44
finish
55
endif
66
let b:did_after_plugin_ultisnips_after = 1

Diff for: autoload/UltiSnips.vim

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
if exists("b:did_autoload_ultisnips") || !exists("g:_uspy")
1+
if exists("b:did_autoload_ultisnips")
22
finish
33
endif
44
let b:did_autoload_ultisnips = 1
55

66
" Also import vim as we expect it to be imported in many places.
7-
exec g:_uspy "import vim"
8-
exec g:_uspy "from UltiSnips import UltiSnips_Manager"
7+
py3 import vim
8+
py3 from UltiSnips import UltiSnips_Manager
99

1010
function! s:compensate_for_pum() abort
1111
""" The CursorMovedI event is not triggered while the popup-menu is visible,
1212
""" and it's by this event that UltiSnips updates its vim-state. The fix is
1313
""" to explicitly check for the presence of the popup menu, and update
1414
""" the vim-state accordingly.
1515
if pumvisible()
16-
exec g:_uspy "UltiSnips_Manager._cursor_moved()"
16+
py3 UltiSnips_Manager._cursor_moved()
1717
endif
1818
endfunction
1919

@@ -23,7 +23,7 @@ function! UltiSnips#Edit(bang, ...) abort
2323
else
2424
let type = ""
2525
endif
26-
exec g:_uspy "vim.command(\"let file = '%s'\" % UltiSnips_Manager._file_to_edit(vim.eval(\"type\"), vim.eval('a:bang')))"
26+
py3 vim.command("let file = '%s'" % UltiSnips_Manager._file_to_edit(vim.eval("type"), vim.eval('a:bang')))
2727

2828
if !len(file)
2929
return
@@ -48,7 +48,7 @@ function! UltiSnips#Edit(bang, ...) abort
4848
endfunction
4949

5050
function! UltiSnips#AddFiletypes(filetypes) abort
51-
exec g:_uspy "UltiSnips_Manager.add_buffer_filetypes('" . a:filetypes . "')"
51+
py3 UltiSnips_Manager.add_buffer_filetypes('" . a:filetypes . "')
5252
return ""
5353
endfunction
5454

@@ -69,18 +69,18 @@ function! UltiSnips#FileTypeComplete(arglead, cmdline, cursorpos) abort
6969
endfunction
7070

7171
function! UltiSnips#ExpandSnippet() abort
72-
exec g:_uspy "UltiSnips_Manager.expand()"
72+
py3 UltiSnips_Manager.expand()
7373
return ""
7474
endfunction
7575

7676
function! UltiSnips#ExpandSnippetOrJump() abort
7777
call s:compensate_for_pum()
78-
exec g:_uspy "UltiSnips_Manager.expand_or_jump()"
78+
py3 UltiSnips_Manager.expand_or_jump()
7979
return ""
8080
endfunction
8181

8282
function! UltiSnips#ListSnippets() abort
83-
exec g:_uspy "UltiSnips_Manager.list_snippets()"
83+
py3 UltiSnips_Manager.list_snippets()
8484
return ""
8585
endfunction
8686

@@ -90,69 +90,69 @@ function! UltiSnips#SnippetsInCurrentScope(...) abort
9090
if all
9191
let g:current_ulti_dict_info = {}
9292
endif
93-
exec g:_uspy "UltiSnips_Manager.snippets_in_current_scope(" . all . ")"
93+
py3 UltiSnips_Manager.snippets_in_current_scope(int(vim.eval("all")))
9494
return g:current_ulti_dict
9595
endfunction
9696

9797
function! UltiSnips#SaveLastVisualSelection() range abort
98-
exec g:_uspy "UltiSnips_Manager._save_last_visual_selection()"
98+
py3 UltiSnips_Manager._save_last_visual_selection()
9999
return ""
100100
endfunction
101101

102102
function! UltiSnips#JumpBackwards() abort
103103
call s:compensate_for_pum()
104-
exec g:_uspy "UltiSnips_Manager.jump_backwards()"
104+
py3 UltiSnips_Manager.jump_backwards()
105105
return ""
106106
endfunction
107107

108108
function! UltiSnips#JumpForwards() abort
109109
call s:compensate_for_pum()
110-
exec g:_uspy "UltiSnips_Manager.jump_forwards()"
110+
py3 UltiSnips_Manager.jump_forwards()
111111
return ""
112112
endfunction
113113

114114
function! UltiSnips#AddSnippetWithPriority(trigger, value, description, options, filetype, priority) abort
115-
exec g:_uspy "trigger = vim.eval(\"a:trigger\")"
116-
exec g:_uspy "value = vim.eval(\"a:value\")"
117-
exec g:_uspy "description = vim.eval(\"a:description\")"
118-
exec g:_uspy "options = vim.eval(\"a:options\")"
119-
exec g:_uspy "filetype = vim.eval(\"a:filetype\")"
120-
exec g:_uspy "priority = vim.eval(\"a:priority\")"
121-
exec g:_uspy "UltiSnips_Manager.add_snippet(trigger, value, description, options, filetype, priority)"
115+
py3 trigger = vim.eval("a:trigger")
116+
py3 value = vim.eval("a:value")
117+
py3 description = vim.eval("a:description")
118+
py3 options = vim.eval("a:options")
119+
py3 filetype = vim.eval("a:filetype")
120+
py3 priority = vim.eval("a:priority")
121+
py3 UltiSnips_Manager.add_snippet(trigger, value, description, options, filetype, priority)
122122
return ""
123123
endfunction
124124

125125
function! UltiSnips#Anon(value, ...) abort
126126
" Takes the same arguments as SnippetManager.expand_anon:
127127
" (value, trigger="", description="", options="")
128-
exec g:_uspy "args = vim.eval(\"a:000\")"
129-
exec g:_uspy "value = vim.eval(\"a:value\")"
130-
exec g:_uspy "UltiSnips_Manager.expand_anon(value, *args)"
128+
py3 args = vim.eval("a:000")
129+
py3 value = vim.eval("a:value")
130+
py3 UltiSnips_Manager.expand_anon(value, *args)
131131
return ""
132132
endfunction
133133

134134
function! UltiSnips#CursorMoved() abort
135-
exec g:_uspy "UltiSnips_Manager._cursor_moved()"
135+
py3 UltiSnips_Manager._cursor_moved()
136136
endf
137137

138138
function! UltiSnips#LeavingBuffer() abort
139139
let from_preview = getwinvar(winnr('#'), '&previewwindow')
140140
let to_preview = getwinvar(winnr(), '&previewwindow')
141141

142142
if !(from_preview || to_preview)
143-
exec g:_uspy "UltiSnips_Manager._leaving_buffer()"
143+
py3 UltiSnips_Manager._leaving_buffer()
144144
endif
145145
endf
146146

147147
function! UltiSnips#LeavingInsertMode() abort
148-
exec g:_uspy "UltiSnips_Manager._leaving_insert_mode()"
148+
py3 UltiSnips_Manager._leaving_insert_mode()
149149
endfunction
150150

151151
function! UltiSnips#TrackChange() abort
152-
exec g:_uspy "UltiSnips_Manager._track_change()"
152+
py3 UltiSnips_Manager._track_change()
153153
endfunction
154154

155155
function! UltiSnips#RefreshSnippets() abort
156-
exec g:_uspy "UltiSnips_Manager._refresh_snippets()"
156+
py3 UltiSnips_Manager._refresh_snippets()
157157
endfunction
158158
" }}}

Diff for: autoload/UltiSnips/map_keys.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if exists("b:did_autoload_ultisnips_map_keys") || !exists("g:_uspy")
1+
if exists("b:did_autoload_ultisnips_map_keys")
22
finish
33
endif
44
let b:did_autoload_ultisnips_map_keys = 1

Diff for: doc/UltiSnips.txt

+5-24
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ UltiSnips *snippet* *snippets* *UltiSnips*
5858

5959
This plugin only works if 'compatible' is not set.
6060
{Vi does not have any of these features}
61-
{only available when |+python| or |+python3| have been enabled at compile time}
61+
{only available when |+python3| has been enabled at compile time}
6262

6363

6464
==============================================================================
@@ -89,22 +89,14 @@ http://vimcasts.org/episodes/ultisnips-visual-placeholder/
8989
1.1 Requirements *UltiSnips-requirements*
9090
----------------
9191

92-
This plugin works with Vim version 7.4 or later. It only works if the
93-
'compatible' setting is not set.
92+
This plugin works with Vim version 7.4 or later with Python 3 support enabled.
93+
It only works if the 'compatible' setting is not set.
9494

95-
This plugin is tested against Python 2.7 and 3.6 in Vim 7.4 and 8. All other
96-
combinations are unsupported, but might work.
97-
98-
The Python 2.x or Python 3.x interface must be available. In other words, Vim
99-
must be compiled with either the |+python| feature or the |+python3| feature.
95+
The Python 3.x interface must be available. In other words, Vim
96+
must be compiled with the |+python3| feature.
10097
The following commands show how to test if you have python compiled in Vim.
10198
They print '1' if the python version is compiled in, '0' if not.
10299

103-
Test if Vim is compiled with python version 2.x: >
104-
:echo has("python")
105-
The python version Vim is linked against can be found with: >
106-
:py import sys; print(sys.version)
107-
108100
Test if Vim is compiled with python version 3.x: >
109101
:echo has("python3")
110102
The python version Vim is linked against can be found with: >
@@ -113,17 +105,6 @@ The python version Vim is linked against can be found with: >
113105
Note that Vim is maybe not using your system-wide installed python version, so
114106
make sure to check the Python version inside of Vim.
115107

116-
UltiSnips attempts to auto-detect which python version is compiled into Vim.
117-
Unfortunately, in some versions of Vim this detection does not work.
118-
In that case you have to explicitly tell UltiSnips which version to use using
119-
the 'UltiSnipsUsePythonVersion' global variable.
120-
121-
To use python version 2.x: >
122-
let g:UltiSnipsUsePythonVersion = 2
123-
124-
To use python version 3.x: >
125-
let g:UltiSnipsUsePythonVersion = 3
126-
127108

128109
1.2 Acknowledgments *UltiSnips-acknowledgments*
129110
-------------------

Diff for: docker/build_vim.sh

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ set -o verbose
55

66
cd /src/vim
77

8-
if [[ $PYTHON_VERSION =~ ^2\. ]]; then
9-
PYTHON_BUILD_CONFIG="--enable-pythoninterp"
10-
else
11-
PYTHON_BUILD_CONFIG="--enable-python3interp"
12-
fi
8+
PYTHON_BUILD_CONFIG="--enable-python3interp"
139

1410
export CFLAGS="$(python-config --cflags)"
1511
echo $CFLAGS
1612
./configure \
13+
--disable-gpm \
1714
--disable-nls \
1815
--disable-sysmouse \
19-
--disable-gpm \
2016
--enable-gui=no \
2117
--enable-multibyte \
18+
--enable-python3interp \
2219
--with-features=huge \
2320
--with-tlib=ncurses \
2421
--without-x \
25-
$PYTHON_BUILD_CONFIG || cat $(find . -name 'config.log')
22+
|| cat $(find . -name 'config.log')
2623
make install

Diff for: mypy.ini

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
python_version = 3.7
55
warn_return_any = True
66
warn_unused_configs = True
7+
mypy_path=pythonx/UltiSnips
78

89
[mypy-vim]
910
ignore_missing_imports = True

Diff for: plugin/UltiSnips.vim

-30
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,6 @@ if version < 704
1010
finish
1111
endif
1212

13-
if !exists("g:UltiSnipsUsePythonVersion")
14-
let g:_uspy=":py3 "
15-
if !has("python3")
16-
if !has("python")
17-
if !exists("g:UltiSnipsNoPythonWarning")
18-
echohl WarningMsg
19-
echom "UltiSnips requires py >= 2.7 or py3"
20-
echohl None
21-
endif
22-
unlet g:_uspy
23-
finish
24-
endif
25-
let g:_uspy=":py "
26-
endif
27-
else
28-
" Use user-provided value, but check if it's available.
29-
" This uses `has()`, because e.g. `exists(":python3")` is always 2.
30-
if g:UltiSnipsUsePythonVersion == 2 && has('python')
31-
let g:_uspy=":python "
32-
elseif g:UltiSnipsUsePythonVersion == 3 && has('python3')
33-
let g:_uspy=":python3 "
34-
endif
35-
if !exists('g:_uspy')
36-
echohl WarningMsg
37-
echom "UltiSnips: the Python version from g:UltiSnipsUsePythonVersion (".g:UltiSnipsUsePythonVersion.") is not available."
38-
echohl None
39-
finish
40-
endif
41-
endif
42-
4313
" The Commands we define.
4414
command! -bang -nargs=? -complete=customlist,UltiSnips#FileTypeComplete UltiSnipsEdit
4515
\ :call UltiSnips#Edit(<q-bang>, <q-args>)

Diff for: pylintrc

+1-8
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ disable=
4848
too-many-locals,
4949
too-many-public-methods,
5050
too-many-return-statements,
51-
too-many-statements,
52-
useless-object-inheritance,
51+
too-many-statements
5352

5453

5554

@@ -145,12 +144,6 @@ max-module-lines=1000
145144
indent-string=' '
146145

147146

148-
[MISCELLANEOUS]
149-
150-
# List of note tags to take in consideration, separated by a comma.
151-
notes=TODO
152-
153-
154147
[SIMILARITIES]
155148

156149
# Minimum lines number of a similarity.

Diff for: pythonx/UltiSnips/buffer_proxy.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import vim
44
from UltiSnips import vim_helper
5-
from UltiSnips.compatibility import as_unicode, as_vimencoding
65
from UltiSnips.position import Position
76
from UltiSnips.diff import diff
87

@@ -96,11 +95,11 @@ def __setitem__(self, key, value):
9695
changes and applies them to the current snippet stack.
9796
"""
9897
if isinstance(key, slice):
99-
value = [as_vimencoding(line) for line in value]
98+
value = [line for line in value]
10099
changes = list(self._get_diff(key.start, key.stop, value))
101100
self._buffer[key.start : key.stop] = [line.strip("\n") for line in value]
102101
else:
103-
value = as_vimencoding(value)
102+
value = value
104103
changes = list(self._get_line_diff(key, self._buffer[key], value))
105104
self._buffer[key] = value
106105

@@ -122,10 +121,7 @@ def __getitem__(self, key):
122121
"""
123122
Just passing call to the vim.current.window.buffer.__getitem__.
124123
"""
125-
if isinstance(key, slice):
126-
return [as_unicode(l) for l in self._buffer[key.start : key.stop]]
127-
else:
128-
return as_unicode(self._buffer[key])
124+
return self._buffer[key]
129125

130126
def __getslice__(self, i, j):
131127
"""
@@ -147,7 +143,7 @@ def append(self, line, line_number=-1):
147143
line_number = len(self)
148144
if not isinstance(line, list):
149145
line = [line]
150-
self[line_number:line_number] = [as_vimencoding(l) for l in line]
146+
self[line_number:line_number] = [l for l in line]
151147

152148
def __delitem__(self, key):
153149
if isinstance(key, slice):

0 commit comments

Comments
 (0)