⚡ Sangsakala Proxy 🏠 Home
Skip to content

Commit 6814a46

Browse files
committed
Adding a Dockerfile and helper scripts for tests
Now we can propperly test python-mode in an environment with a very well defined python version and a vim built/compiled for this specific version as well. The best way is to use the `build_docker_images.sh` file in order to create the docker image with all python versions you desire. Also, in order to run the container you just have to do: docker run --rm -it python-mode:<version> Related to python-mode#977
1 parent 08dbb8c commit 6814a46

8 files changed

Lines changed: 230 additions & 0 deletions

File tree

‎.dockerignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Dockerfile
2+
.dockerignore

‎Dockerfile‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# VERSION 1.0.0
2+
# AUTHOR: Diego Rabatone Oliveira (@diraol)
3+
# DESCRIPTION: Image used to test python-mode
4+
# BUILD: Use the build_docker_images.sh file
5+
# docker build -t python-mode:<VER> -f Dockerfile --build-arg PYTHON=<VER> .
6+
# SOURCE: https://github.com/python-mode/python-mode
7+
ARG PYTHON
8+
FROM python:$PYTHON
9+
10+
# Passing arg inside the build stage
11+
ARG PYTHON
12+
13+
# Never prompts the user for choices on installation/configuration of packages
14+
ENV DEBIAN_FRONTEND noninteractive
15+
ENV TERM linux
16+
17+
# https://docs.python.org/3.6/using/cmdline.html#envvar-PYTHONUNBUFFERED
18+
# https://github.com/sclorg/s2i-python-container/issues/157
19+
ENV PYTHONUNBUFFERED 1
20+
21+
# Clonning and building VIM for the specific python version
22+
COPY ./tests/utils/build_vim.sh /opt/build_vim.sh
23+
RUN set -ex \
24+
&& cd /opt \
25+
&& chmod +x build_vim.sh \
26+
&& git clone https://github.com/vim/vim.git \
27+
&& ./build_vim.sh ${PYTHON} \
28+
&& rm -rf vim build_vim.sh
29+
30+
ENV PYTHON_MODE_HOME /root/.vim/pack/foo/start/python-mode/
31+
ENV VIM_RC /root/.vimrc
32+
ENV PYMODE_RC /root/.pymoderc
33+
ENV TEST_FILE /root/test.py
34+
35+
COPY . ${PYTHON_MODE_HOME}
36+
RUN set -ex \
37+
&& cd ${PYTHON_MODE_HOME} \
38+
&& find . -type f -name '*.pyc' -delete \
39+
&& find . -type d -name '__pycache__' -delete \
40+
&& ln -s ${PYTHON_MODE_HOME}tests/utils/test.py ${TEST_FILE} \
41+
&& ln -s ${PYTHON_MODE_HOME}tests/utils/pymoderc ${PYMODE_RC} \
42+
&& ln -s ${PYTHON_MODE_HOME}tests/utils/vimrc ${VIM_RC} \
43+
&& touch /root/.vimrc.before /root/.vimrc.after
44+
45+
RUN set -ex && vim -e -s -c ':exec ":helptags ALL" | exec ":qall!"'
46+
47+
WORKDIR /root
48+
ENTRYPOINT ["/bin/bash"]

‎build_docker_images.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
for VER in 2.7 3.5 3.6 3.7 3.7.1
4+
do
5+
docker build -t python-mode:${VER} --build-arg PYTHON=${VER} -f Dockerfile .
6+
done

‎readme.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ Please, also provide more contextual information such as:
169169
* `:PymodePython import sys; print(sys.version_info)` output.
170170
* and if you are using virtualenvs and/or conda, also state that, please.
171171

172+
## Docker environment
173+
Now you can try python-mode within a docker container, with a python-version
174+
from your choice and a vim built for that python version.
175+
176+
To build the docker images you should use the script `build_docker_images.sh`
177+
that is located on the root of this repo.
178+
179+
To run the container for a specific version, after building it, you can do:
180+
181+
`docker run --rm -it python-mode:<PYTHON_VERSION>`
182+
183+
* PYTHON\_VERSION can be 2.7, 3.7, etc.
184+
185+
If you do not want the container to be removed after you exit it, just remove
186+
the `--rm` from the command above.
187+
172188
# Frequent problems
173189

174190
Read this section before opening an issue on the tracker.

‎tests/utils/build_vim.sh‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
set -e
3+
SPACER="#####################################################################"
4+
5+
PYTHON=$1
6+
echo "Python version: ${PYTHON}"
7+
8+
cd /opt/vim
9+
10+
args=( )
11+
# args+=( --with-features=huge )
12+
args+=( --enable-multibyte )
13+
args+=( --enable-cscope )
14+
15+
PYTHON_CONFIG_DIR=$(find /usr -type d -name 'config*' | grep python | grep -v dist-packages)
16+
17+
if [[ ${PYTHON} =~ ^2 ]]; then
18+
args+=( --enable-pythoninterp=yes )
19+
args+=( --with-python-config-dir=${PYTHON_CONFIG_DIR} )
20+
else
21+
args+=( --enable-python3interp=yes )
22+
args+=( --with-python3-config-dir=${PYTHON_CONFIG_DIR} )
23+
fi
24+
25+
args+=( --prefix=/usr/local )
26+
27+
echo ${SPACER}
28+
echo Starting build with args: ${args[@]}
29+
echo ${SPACER}
30+
31+
./configure ${args[@]}
32+
33+
make
34+
35+
make install
36+
37+
echo ${SPACER}
38+
echo vim installed with config args: ${args[@]}
39+
echo ${SPACER}

‎tests/utils/pymoderc‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
" These are all pymode configs. You can read about them using :help pymode
2+
let g:pymode = 1
3+
let g:pymode_warnings = 1
4+
let g:pymode_paths = []
5+
let g:pymode_trim_whitespaces = 1
6+
let g:pymode_options = 1
7+
let g:pymode_options_max_line_length = 79
8+
let g:pymode_options_colorcolumn = 1
9+
let g:pymode_quickfix_minheight = 3
10+
let g:pymode_quickfix_maxheight = 6
11+
let g:pymode_indent = 1
12+
let g:pymode_folding = 0
13+
let g:pymode_motion = 1
14+
let g:pymode_doc = 1
15+
let g:pymode_doc_bind = 'K'
16+
let g:pymode_virtualenv = 1
17+
let g:pymode_virtualenv_path = $VIRTUAL_ENV
18+
let g:pymode_run = 1
19+
let g:pymode_run_bind = '<leader>r'
20+
let g:pymode_breakpoint = 1
21+
let g:pymode_breakpoint_bind = '<leader>b'
22+
let g:pymode_breakpoint_cmd = ''
23+
let g:pymode_lint = 1
24+
let g:pymode_lint_on_write = 1
25+
let g:pymode_lint_unmodified = 0
26+
let g:pymode_lint_on_fly = 0
27+
let g:pymode_lint_message = 1
28+
let g:pymode_lint_checkers = ['pyflakes', 'pep8', 'mccabe']
29+
let g:pymode_lint_ignore = ["E501", "W",]
30+
let g:pymode_lint_select = ["E501", "W0011", "W430"]
31+
let g:pymode_lint_sort = []
32+
let g:pymode_lint_cwindow = 1
33+
let g:pymode_lint_signs = 1
34+
let g:pymode_lint_todo_symbol = 'WW'
35+
let g:pymode_lint_comment_symbol = 'CC'
36+
let g:pymode_lint_visual_symbol = 'RR'
37+
let g:pymode_lint_error_symbol = 'EE'
38+
let g:pymode_lint_info_symbol = 'II'
39+
let g:pymode_lint_pyflakes_symbol = 'FF'
40+
let g:pymode_lint_options_pep8 =
41+
\ {'max_line_length': g:pymode_options_max_line_length}
42+
let g:pymode_lint_options_pyflakes = { 'builtins': '_' }
43+
let g:pymode_lint_options_mccabe = { 'complexity': 12 }
44+
let g:pymode_lint_options_pep257 = {}
45+
let g:pymode_lint_options_pylint =
46+
\ {'max-line-length': g:pymode_options_max_line_length}
47+
let g:pymode_rope = 1
48+
let g:pymode_rope_lookup_project = 0
49+
let g:pymode_rope_project_root = ""
50+
let g:pymode_rope_ropefolder='.ropeproject'
51+
let g:pymode_rope_show_doc_bind = '<C-c>d'
52+
let g:pymode_rope_regenerate_on_write = 1
53+
let g:pymode_rope_completion = 1
54+
let g:pymode_rope_complete_on_dot = 1
55+
let g:pymode_rope_completion_bind = '<C-Space>'
56+
let g:pymode_rope_autoimport = 0
57+
let g:pymode_rope_autoimport_modules = ['os', 'shutil', 'datetime']
58+
let g:pymode_rope_autoimport_import_after_complete = 0
59+
let g:pymode_rope_goto_definition_bind = '<C-c>g'
60+
let g:pymode_rope_goto_definition_cmd = 'new'
61+
let g:pymode_rope_rename_bind = '<C-c>rr'
62+
let g:pymode_rope_rename_module_bind = '<C-c>r1r'
63+
let g:pymode_rope_organize_imports_bind = '<C-c>ro'
64+
let g:pymode_rope_autoimport_bind = '<C-c>ra'
65+
let g:pymode_rope_module_to_package_bind = '<C-c>r1p'
66+
let g:pymode_rope_extract_method_bind = '<C-c>rm'
67+
let g:pymode_rope_extract_variable_bind = '<C-c>rl'
68+
let g:pymode_rope_use_function_bind = '<C-c>ru'
69+
let g:pymode_rope_move_bind = '<C-c>rv'
70+
let g:pymode_rope_change_signature_bind = '<C-c>rs'
71+
let g:pymode_syntax = 1
72+
let g:pymode_syntax_slow_sync = 1
73+
let g:pymode_syntax_all = 1
74+
let g:pymode_syntax_print_as_function = 0
75+
let g:pymode_syntax_highlight_async_await = g:pymode_syntax_all
76+
let g:pymode_syntax_highlight_equal_operator = g:pymode_syntax_all
77+
let g:pymode_syntax_highlight_stars_operator = g:pymode_syntax_all
78+
let g:pymode_syntax_highlight_self = g:pymode_syntax_all
79+
let g:pymode_syntax_indent_errors = g:pymode_syntax_all
80+
let g:pymode_syntax_space_errors = g:pymode_syntax_all
81+
let g:pymode_syntax_string_formatting = g:pymode_syntax_all
82+
let g:pymode_syntax_string_format = g:pymode_syntax_all
83+
let g:pymode_syntax_string_templates = g:pymode_syntax_all
84+
let g:pymode_syntax_doctests = g:pymode_syntax_all
85+
let g:pymode_syntax_builtin_objs = g:pymode_syntax_all
86+
let g:pymode_syntax_builtin_types = g:pymode_syntax_all
87+
let g:pymode_syntax_highlight_exceptions = g:pymode_syntax_all
88+
let g:pymode_syntax_docstrings = g:pymode_syntax_all
89+
90+
" vim:tw=79:ts=8:ft=help:norl:

‎tests/utils/reset_update_repo.sh‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
git reset --hard HEAD
4+
git checkout origin develop
5+
git pull origin develop
6+
git submodule sync --recursive
7+
git submodule update --init --recursive

‎tests/utils/vimrc‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
source /root/.vimrc.before
2+
source /root/.pymoderc
3+
4+
syntax on
5+
filetype plugin indent on
6+
set shortmess=at
7+
set cmdheight=10
8+
set ft=python
9+
set shell=bash
10+
set rtp+=/root/.vim/pack/foo/start/python-mode
11+
set term=xterm-256color
12+
set wrap " visually wrap lines
13+
set smartindent " smart indenting
14+
set shiftwidth=4 " default to two spaces
15+
set tabstop=4 " default to two spaces
16+
set softtabstop=4 " default to two spaces
17+
set shiftround " always round indentation to shiftwidth
18+
set mouse= " disable mouse
19+
set expandtab
20+
set backspace=indent,eol,start
21+
22+
source /root/.vimrc.after

0 commit comments

Comments
 (0)