⚡ Sangsakala Proxy 🏠 Home
Skip to content

Commit f01f763

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 #977
1 parent 4ea05b6 commit f01f763

6 files changed

Lines changed: 118 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
@@ -188,6 +188,22 @@ Please, also provide more contextual information such as:
188188
* `git status` (under your _python-mode_ directory)
189189
* `tree <python-mode-directory>` or something similar (such as `ls -lR`)
190190

191+
## Docker environment
192+
Now you can try python-mode within a docker container, with a python-version
193+
from your choice and a vim built for that python version.
194+
195+
To build the docker images you should use the script `build_docker_images.sh`
196+
that is located on the root of this repo.
197+
198+
To run the container for a specific version, after building it, you can do:
199+
200+
`docker run --rm -it python-mode:<PYTHON_VERSION>`
201+
202+
* PYTHON\_VERSION can be 2.7, 3.7, etc.
203+
204+
If you do not want the container to be removed after you exit it, just remove
205+
the `--rm` from the command above.
206+
191207
# Frequent problems
192208

193209
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/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

0 commit comments

Comments
 (0)