From 350557903fe3f7ea3c5060e8775e5276636facef Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Sun, 30 Dec 2018 00:02:45 -0200 Subject: [PATCH 1/2] 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: Related to #977 --- .dockerignore | 2 + Dockerfile | 48 +++++++++++++++++ build_docker_images.sh | 6 +++ readme.md | 17 ++++++ tests/utils/build_vim.sh | 39 ++++++++++++++ tests/utils/pymoderc | 90 ++++++++++++++++++++++++++++++++ tests/utils/reset_update_repo.sh | 7 +++ tests/utils/vimrc | 22 ++++++++ 8 files changed, 231 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 build_docker_images.sh create mode 100644 tests/utils/build_vim.sh create mode 100644 tests/utils/pymoderc create mode 100644 tests/utils/reset_update_repo.sh create mode 100644 tests/utils/vimrc diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..4a246ec6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9774e903 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +# VERSION 1.0.0 +# AUTHOR: Diego Rabatone Oliveira (@diraol) +# DESCRIPTION: Image used to test python-mode +# BUILD: Use the build_docker_images.sh file +# docker build -t python-mode: -f Dockerfile --build-arg PYTHON= . +# SOURCE: https://github.com/python-mode/python-mode +ARG PYTHON +FROM python:$PYTHON + +# Passing arg inside the build stage +ARG PYTHON + +# Never prompts the user for choices on installation/configuration of packages +ENV DEBIAN_FRONTEND noninteractive +ENV TERM linux + +# https://docs.python.org/3.6/using/cmdline.html#envvar-PYTHONUNBUFFERED +# https://github.com/sclorg/s2i-python-container/issues/157 +ENV PYTHONUNBUFFERED 1 + +# Clonning and building VIM for the specific python version +COPY ./tests/utils/build_vim.sh /opt/build_vim.sh +RUN set -ex \ + && cd /opt \ + && chmod +x build_vim.sh \ + && git clone https://github.com/vim/vim.git \ + && ./build_vim.sh ${PYTHON} \ + && rm -rf vim build_vim.sh + +ENV PYTHON_MODE_HOME /root/.vim/pack/foo/start/python-mode/ +ENV VIM_RC /root/.vimrc +ENV PYMODE_RC /root/.pymoderc +ENV TEST_FILE /root/test.py + +COPY . ${PYTHON_MODE_HOME} +RUN set -ex \ + && cd ${PYTHON_MODE_HOME} \ + && find . -type f -name '*.pyc' -delete \ + && find . -type d -name '__pycache__' -delete \ + && ln -s ${PYTHON_MODE_HOME}tests/utils/test.py ${TEST_FILE} \ + && ln -s ${PYTHON_MODE_HOME}tests/utils/pymoderc ${PYMODE_RC} \ + && ln -s ${PYTHON_MODE_HOME}tests/utils/vimrc ${VIM_RC} \ + && touch /root/.vimrc.before /root/.vimrc.after \ + +RUN set -ex && vim -e -s -c ':exec ":helptags ALL" | exec ":qall!"' + +WORKDIR /root +ENTRYPOINT ["/bin/bash"] diff --git a/build_docker_images.sh b/build_docker_images.sh new file mode 100755 index 00000000..961db554 --- /dev/null +++ b/build_docker_images.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +for VER in 2.7 3.5 3.6 3.7 3.7.1 +do + docker build -t python-mode:${VER} --build-arg PYTHON=${VER} -f Dockerfile . +done diff --git a/readme.md b/readme.md index 9b35daf7..55d91fac 100644 --- a/readme.md +++ b/readme.md @@ -141,6 +141,7 @@ If your question is not described there then you already know what to do Nevertheless just a refresher on how to submit bugs: **(From the FAQ)** + Clear all python cache/compiled files (`*.pyc` files and `__pycache__` directory and everything under it). In Linux/Unix/MacOS you can run: @@ -160,6 +161,22 @@ plugin seems broken. ***Do check for sensitive information in the file before submitting.*** +## Docker environment +Now you can try python-mode within a docker container, with a python-version +from your choice and a vim built for that python version. + +To build the docker images you should use the script `build_docker_images.sh` +that is located on the root of this repo. + +To run the container for a specific version, after building it, you can do: + +`docker run --rm -it python-mode:` + +* PYTHON\_VERSION can be 2.7, 3.7, etc. + +If you do not want the container to be removed after you exit it, just remove +the `--rm` from the command above. + # Frequent problems Read this section before opening an issue on the tracker. diff --git a/tests/utils/build_vim.sh b/tests/utils/build_vim.sh new file mode 100644 index 00000000..92ef282b --- /dev/null +++ b/tests/utils/build_vim.sh @@ -0,0 +1,39 @@ +#!/bin/bash +set -e +SPACER="#####################################################################" + +PYTHON=$1 +echo "Python version: ${PYTHON}" + +cd /opt/vim + +args=( ) +# args+=( --with-features=huge ) +args+=( --enable-multibyte ) +args+=( --enable-cscope ) + +PYTHON_CONFIG_DIR=$(find /usr -type d -name 'config*' | grep python | grep -v dist-packages) + +if [[ ${PYTHON} =~ ^2 ]]; then + args+=( --enable-pythoninterp=yes ) + args+=( --with-python-config-dir=${PYTHON_CONFIG_DIR} ) +else + args+=( --enable-python3interp=yes ) + args+=( --with-python3-config-dir=${PYTHON_CONFIG_DIR} ) +fi + +args+=( --prefix=/usr/local ) + +echo ${SPACER} +echo Starting build with args: ${args[@]} +echo ${SPACER} + +./configure ${args[@]} + +make + +make install + +echo ${SPACER} +echo vim installed with config args: ${args[@]} +echo ${SPACER} diff --git a/tests/utils/pymoderc b/tests/utils/pymoderc new file mode 100644 index 00000000..222c6ceb --- /dev/null +++ b/tests/utils/pymoderc @@ -0,0 +1,90 @@ +" These are all pymode configs. You can read about them using :help pymode +let g:pymode = 1 +let g:pymode_warnings = 1 +let g:pymode_paths = [] +let g:pymode_trim_whitespaces = 1 +let g:pymode_options = 1 +let g:pymode_options_max_line_length = 79 +let g:pymode_options_colorcolumn = 1 +let g:pymode_quickfix_minheight = 3 +let g:pymode_quickfix_maxheight = 6 +let g:pymode_indent = 1 +let g:pymode_folding = 0 +let g:pymode_motion = 1 +let g:pymode_doc = 1 +let g:pymode_doc_bind = 'K' +let g:pymode_virtualenv = 1 +let g:pymode_virtualenv_path = $VIRTUAL_ENV +let g:pymode_run = 1 +let g:pymode_run_bind = 'r' +let g:pymode_breakpoint = 1 +let g:pymode_breakpoint_bind = 'b' +let g:pymode_breakpoint_cmd = '' +let g:pymode_lint = 1 +let g:pymode_lint_on_write = 1 +let g:pymode_lint_unmodified = 0 +let g:pymode_lint_on_fly = 0 +let g:pymode_lint_message = 1 +let g:pymode_lint_checkers = ['pyflakes', 'pep8', 'mccabe'] +let g:pymode_lint_ignore = ["E501", "W",] +let g:pymode_lint_select = ["E501", "W0011", "W430"] +let g:pymode_lint_sort = [] +let g:pymode_lint_cwindow = 1 +let g:pymode_lint_signs = 1 +let g:pymode_lint_todo_symbol = 'WW' +let g:pymode_lint_comment_symbol = 'CC' +let g:pymode_lint_visual_symbol = 'RR' +let g:pymode_lint_error_symbol = 'EE' +let g:pymode_lint_info_symbol = 'II' +let g:pymode_lint_pyflakes_symbol = 'FF' +let g:pymode_lint_options_pep8 = + \ {'max_line_length': g:pymode_options_max_line_length} +let g:pymode_lint_options_pyflakes = { 'builtins': '_' } +let g:pymode_lint_options_mccabe = { 'complexity': 12 } +let g:pymode_lint_options_pep257 = {} +let g:pymode_lint_options_pylint = + \ {'max-line-length': g:pymode_options_max_line_length} +let g:pymode_rope = 1 +let g:pymode_rope_lookup_project = 0 +let g:pymode_rope_project_root = "" +let g:pymode_rope_ropefolder='.ropeproject' +let g:pymode_rope_show_doc_bind = 'd' +let g:pymode_rope_regenerate_on_write = 1 +let g:pymode_rope_completion = 1 +let g:pymode_rope_complete_on_dot = 1 +let g:pymode_rope_completion_bind = '' +let g:pymode_rope_autoimport = 0 +let g:pymode_rope_autoimport_modules = ['os', 'shutil', 'datetime'] +let g:pymode_rope_autoimport_import_after_complete = 0 +let g:pymode_rope_goto_definition_bind = 'g' +let g:pymode_rope_goto_definition_cmd = 'new' +let g:pymode_rope_rename_bind = 'rr' +let g:pymode_rope_rename_module_bind = 'r1r' +let g:pymode_rope_organize_imports_bind = 'ro' +let g:pymode_rope_autoimport_bind = 'ra' +let g:pymode_rope_module_to_package_bind = 'r1p' +let g:pymode_rope_extract_method_bind = 'rm' +let g:pymode_rope_extract_variable_bind = 'rl' +let g:pymode_rope_use_function_bind = 'ru' +let g:pymode_rope_move_bind = 'rv' +let g:pymode_rope_change_signature_bind = 'rs' +let g:pymode_syntax = 1 +let g:pymode_syntax_slow_sync = 1 +let g:pymode_syntax_all = 1 +let g:pymode_syntax_print_as_function = 0 +let g:pymode_syntax_highlight_async_await = g:pymode_syntax_all +let g:pymode_syntax_highlight_equal_operator = g:pymode_syntax_all +let g:pymode_syntax_highlight_stars_operator = g:pymode_syntax_all +let g:pymode_syntax_highlight_self = g:pymode_syntax_all +let g:pymode_syntax_indent_errors = g:pymode_syntax_all +let g:pymode_syntax_space_errors = g:pymode_syntax_all +let g:pymode_syntax_string_formatting = g:pymode_syntax_all +let g:pymode_syntax_string_format = g:pymode_syntax_all +let g:pymode_syntax_string_templates = g:pymode_syntax_all +let g:pymode_syntax_doctests = g:pymode_syntax_all +let g:pymode_syntax_builtin_objs = g:pymode_syntax_all +let g:pymode_syntax_builtin_types = g:pymode_syntax_all +let g:pymode_syntax_highlight_exceptions = g:pymode_syntax_all +let g:pymode_syntax_docstrings = g:pymode_syntax_all + +" vim:tw=79:ts=8:ft=help:norl: diff --git a/tests/utils/reset_update_repo.sh b/tests/utils/reset_update_repo.sh new file mode 100644 index 00000000..43622f2d --- /dev/null +++ b/tests/utils/reset_update_repo.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +git reset --hard HEAD +git checkout origin develop +git pull origin develop +git submodule sync --recursive +git submodule update --init --recursive diff --git a/tests/utils/vimrc b/tests/utils/vimrc new file mode 100644 index 00000000..6920a0bb --- /dev/null +++ b/tests/utils/vimrc @@ -0,0 +1,22 @@ +source /root/.vimrc.before +source /root/.pymoderc + +syntax on +filetype plugin indent on +set shortmess=at +set cmdheight=10 +set ft=python +set shell=bash +set rtp+=/root/.vim/pack/foo/start/python-mode +set term=xterm-256color +set wrap " visually wrap lines +set smartindent " smart indenting +set shiftwidth=4 " default to two spaces +set tabstop=4 " default to two spaces +set softtabstop=4 " default to two spaces +set shiftround " always round indentation to shiftwidth +set mouse= " disable mouse +set expandtab +set backspace=indent,eol,start + +source /root/.vimrc.after From 4e8ac633d73337c44eb7c33e92d3af12d8d8038e Mon Sep 17 00:00:00 2001 From: racterub Date: Sat, 12 Jan 2019 20:36:31 +0800 Subject: [PATCH 2/2] Using one-line command to get easier future maintenance --- Dockerfile | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9774e903..56eb201a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,12 +20,7 @@ ENV PYTHONUNBUFFERED 1 # Clonning and building VIM for the specific python version COPY ./tests/utils/build_vim.sh /opt/build_vim.sh -RUN set -ex \ - && cd /opt \ - && chmod +x build_vim.sh \ - && git clone https://github.com/vim/vim.git \ - && ./build_vim.sh ${PYTHON} \ - && rm -rf vim build_vim.sh +RUN set -ex && cd /opt && chmod +x build_vim.sh && git clone https://github.com/vim/vim.git && ./build_vim.sh ${PYTHON} && rm -rf vim build_vim.sh ENV PYTHON_MODE_HOME /root/.vim/pack/foo/start/python-mode/ ENV VIM_RC /root/.vimrc @@ -33,14 +28,7 @@ ENV PYMODE_RC /root/.pymoderc ENV TEST_FILE /root/test.py COPY . ${PYTHON_MODE_HOME} -RUN set -ex \ - && cd ${PYTHON_MODE_HOME} \ - && find . -type f -name '*.pyc' -delete \ - && find . -type d -name '__pycache__' -delete \ - && ln -s ${PYTHON_MODE_HOME}tests/utils/test.py ${TEST_FILE} \ - && ln -s ${PYTHON_MODE_HOME}tests/utils/pymoderc ${PYMODE_RC} \ - && ln -s ${PYTHON_MODE_HOME}tests/utils/vimrc ${VIM_RC} \ - && touch /root/.vimrc.before /root/.vimrc.after \ +RUN set -ex && cd ${PYTHON_MODE_HOME} && find . -type f -name '*.pyc' -delete && find . -type d -name '__pycache__' -delete && ln -s ${PYTHON_MODE_HOME}tests/utils/test.py ${TEST_FILE} && ln -s ${PYTHON_MODE_HOME}tests/utils/pymoderc ${PYMODE_RC} && ln -s ${PYTHON_MODE_HOME}tests/utils/vimrc ${VIM_RC} && touch /root/.vimrc.before /root/.vimrc.after RUN set -ex && vim -e -s -c ':exec ":helptags ALL" | exec ":qall!"'