Skip to content

Commit

Permalink
Adding a Dockerfile and helper scripts for tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
diraol authored and Diego Rabatone Oliveira committed Apr 21, 2020
1 parent 0fa798d commit a00bb97
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
.dockerignore
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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:<VER> -f Dockerfile --build-arg PYTHON=<VER> .
# 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"]
6 changes: 6 additions & 0 deletions build_docker_images.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ Please, also provide more contextual information such as:
* `git status` (under your _python-mode_ directory)
* `tree <python-mode-directory>` or something similar (such as `ls -lR`)

## 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>`

* 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.
Expand Down
39 changes: 39 additions & 0 deletions tests/utils/build_vim.sh
Original file line number Diff line number Diff line change
@@ -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}
7 changes: 7 additions & 0 deletions tests/utils/reset_update_repo.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a00bb97

Please sign in to comment.