Skip to content

Commit 22aed09

Browse files
committed
Add full docker based test setup
1 parent 90e4f6d commit 22aed09

File tree

7 files changed

+478
-2
lines changed

7 files changed

+478
-2
lines changed

Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
ARG PYTHON_VERSION_SHORT
2+
ARG PYTHON_VERSION
3+
ARG REPO_OWNER=python-mode
4+
FROM ghcr.io/${REPO_OWNER}/python-mode-base:${PYTHON_VERSION_SHORT}-latest
5+
6+
ENV PYTHON_VERSION=${PYTHON_VERSION}
7+
ENV PYTHONUNBUFFERED=1
8+
ENV PYMODE_DIR="/workspace/python-mode"
9+
10+
# Set up working directory
11+
WORKDIR /workspace
12+
13+
# Copy the python-mode plugin
14+
COPY . /workspace/python-mode
15+
16+
# Set up python-mode in the test environment
17+
RUN mkdir -p /root/.vim/pack/foo/start/ && \
18+
ln -s ${PYMODE_DIR} /root/.vim/pack/foo/start/python-mode && \
19+
cp ${PYMODE_DIR}/tests/utils/pymoderc /root/.pymoderc && \
20+
cp ${PYMODE_DIR}/tests/utils/vimrc /root/.vimrc && \
21+
touch /root/.vimrc.before /root/.vimrc.after
22+
23+
# Initialize git submodules
24+
WORKDIR /workspace/python-mode
25+
26+
# Create a script to run tests
27+
RUN echo '#!/bin/bash\n\
28+
# export PYENV_ROOT="/opt/pyenv"\n\
29+
# export PATH="${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}"\n\
30+
eval "$(pyenv init -)"\n\
31+
eval "$(pyenv init --path)"\n\
32+
# Use specified Python version\n\
33+
pyenv shell ${PYTHON_VERSION}\n\
34+
cd /workspace/python-mode\n\
35+
echo "Using Python: $(python --version)"\n\
36+
bash ./tests/test.sh\n\
37+
rm -f tests/.swo tests/.swp 2>&1 >/dev/null \n\
38+
' > /usr/local/bin/run-tests && \
39+
chmod +x /usr/local/bin/run-tests
40+
41+
# Default command
42+
CMD ["/usr/local/bin/run-tests"]

README-Docker.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Docker Test Environment for python-mode
2+
3+
This directory contains Docker configuration to run python-mode tests in a containerized environment that matches the GitHub Actions CI environment.
4+
5+
## Prerequisites
6+
7+
- Docker
8+
- Docker Compose
9+
10+
## Quick Start
11+
12+
### Run Tests
13+
14+
To run all tests in Docker (default version 3.13.0):
15+
16+
```bash
17+
# Using the convenience script
18+
./scripts/run-tests-docker.sh
19+
20+
# Or manually with docker-compose
21+
docker compose run --rm python-mode-tests
22+
```
23+
24+
### Interactive Development
25+
26+
To start an interactive shell for development:
27+
28+
```bash
29+
docker compose run --rm python-mode-dev
30+
```
31+
32+
## What's Included
33+
34+
The Docker environment includes:
35+
36+
- **Ubuntu 24.04** base image
37+
- **pyenv** for Python version management
38+
- **Multiple Python versions**: 3.10.13, 3.11.9, 3.12.4, 3.13.0
39+
- **Python 3.13.0** as default
40+
- **Vim built from source** with Python support for each Python version
41+
- All required system dependencies:
42+
- GUI libraries (GTK, X11, etc.)
43+
- Lua 5.2
44+
- Perl
45+
- Build tools
46+
- Python build dependencies
47+
- **python-mode plugin** properly installed and configured
48+
- **Git submodules** initialized
49+
- **Test environment** matching the CI setup
50+
51+
## Environment Details
52+
53+
The container replicates the GitHub Actions environment:
54+
55+
- Vim is built with `--enable-python3interp=yes` for each Python version
56+
- pyenv is installed at `/opt/pyenv`
57+
- Python versions are managed by pyenv:
58+
- 3.10.13
59+
- 3.11.9
60+
- 3.12.4
61+
- 3.13.0 (default)
62+
- Each Python version has its own Vim binary: `vim-3.10.13`, `vim-3.11.9`, etc.
63+
- Python config directory is automatically detected using `python-config --configdir`
64+
- python-mode is installed in `/root/.vim/pack/foo/start/python-mode`
65+
- Test configuration files are copied to the appropriate locations
66+
- All required environment variables are set
67+
68+
## Test Execution
69+
70+
Tests are run using the same `tests/test.sh` script as in CI:
71+
72+
1. **test_autopep8.sh** - Tests automatic code formatting
73+
2. **test_autocommands.sh** - Tests Vim autocommands
74+
3. **test_folding.sh** - Tests code folding functionality
75+
4. **test_textobject.sh** - Tests text object operations
76+
77+
## Testing with Different Python Versions
78+
79+
You can test python-mode with different Python versions:
80+
81+
```bash
82+
# Test with Python 3.11.9
83+
./scripts/run-tests-docker.sh 3.11
84+
85+
# Test with Python 3.12.4
86+
./scripts/run-tests-docker.sh 3.12
87+
88+
# Test with Python 3.13.0
89+
./scripts/run-tests-docker.sh 3.13
90+
```
91+
92+
Available Python versions: 3.10.13, 3.11.9, 3.12.4, 3.13.0
93+
94+
Note: Use the major.minor format (e.g., 3.11) when specifying versions.
95+
96+
## Troubleshooting
97+
98+
### Python Config Directory Issues
99+
100+
The Dockerfile uses `python-config --configdir` to automatically detect the correct Python config directory. If you encounter issues:
101+
102+
1. Check that pyenv is properly initialized
103+
2. Verify that the requested Python version is available
104+
3. Ensure all environment variables are set correctly
105+
106+
### Build Failures
107+
108+
If the Docker build fails:
109+
110+
1. Check that all required packages are available in Ubuntu 24.04
111+
2. Verify that pyenv can download and install Python versions
112+
3. Ensure the Vim source code is accessible
113+
4. Check that pyenv is properly initialized in the shell
114+
115+
### Test Failures
116+
117+
If tests fail in Docker but pass locally:
118+
119+
1. Check that the Vim build includes Python support for the correct version
120+
2. Verify that all git submodules are properly initialized
121+
3. Ensure the test environment variables are correctly set
122+
4. Confirm that the correct Python version is active
123+
5. Verify that pyenv is properly initialized
124+
125+
## Adding More Python Versions
126+
127+
To add support for additional Python versions:
128+
129+
1. Add the new version to the `pyenv install` commands in the Dockerfile.base
130+
2. Update the test scripts to include the new version
131+
4. Test that the new version works with the python-mode plugin
132+
5. Update this documentation with the new version information

doc/pymode.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Python-mode contains all you need to develop python applications in Vim.
5454

5555
Features: *pymode-features*
5656

57-
- Support Python version 2.6+ and 3.2+
57+
- Support Python version 3.10.13, 3.11.9, 3.12.4, 3.13.0
5858
- Syntax highlighting
5959
- Virtualenv support
6060
- Run python code (``<leader>r``)
@@ -161,6 +161,11 @@ python-features of **pymode** will be disabled.
161161
Set value to `python3` if you are working with python3 projects. You could use
162162
|exrc|
163163

164+
+ Currently supported Python versions: 3.10.13, 3.11.9, 3.12.4, 3.13.0
165+
+
166+
+ For testing with different Python versions, see the Docker testing environment
167+
+ described in the Development section.
168+
164169
-------------------------------------------------------------------------------
165170
2.2 Python indentation ~
166171
*pymode-indent*
@@ -862,6 +867,22 @@ newly added file (2). This latter file should invoke vim which in turn sources
862867
file (3). File (3) may then read (4) as a first part of its assertion
863868
structure and then execute the remaning of the instructions/assertions.
864869

870+
6. Testing Environment: The project uses Docker for consistent testing across
871+
different Python versions. See `README-Docker.md` for detailed information about
872+
the Docker testing environment.
873+
874+
7. CI/CD: The project uses GitHub Actions for continuous integration, building
875+
Docker images for each supported Python version and running tests automatically.
876+
877+
8. Supported Python Versions: The project currently supports Python 3.10.13,
878+
3.11.9, 3.12.4, and 3.13.0. All tests are run against these versions in the
879+
CI environment.
880+
881+
9. Docker Testing: To run tests locally with Docker:
882+
- Use `./scripts/run-tests-docker.sh` to run tests with the default Python version
883+
- Use `./scripts/run-tests-docker.sh 3.11` to test with Python 3.11.9
884+
- Use `./scripts/test-all-python-versions.sh` to test with all supported versions
885+
865886
===============================================================================
866887
8. Credits ~
867888
*pymode-credits*

docker-compose.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
services:
2+
python-mode-tests:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
args:
7+
- PYTHON_VERSION_SHORT
8+
- PYTHON_VERSION
9+
volumes:
10+
# Mount the current directory to allow for development and testing
11+
- .:/workspace/python-mode
12+
environment:
13+
- PYTHON_CONFIGURE_OPTS=--enable-shared
14+
- PYMODE_DIR=/workspace/python-mode
15+
- PYENV_ROOT=/opt/pyenv
16+
- PATH=/usr/local/bin:/opt/pyenv/bin:/opt/pyenv/shims:$PATH
17+
# Optional: Set PYTHON_VERSION to test with a specific Python version
18+
# - PYTHON_VERSION=3.11.9
19+
# Run tests by default
20+
command: ["/usr/local/bin/run-tests"]
21+
22+
# Alternative service for interactive development
23+
python-mode-dev:
24+
build:
25+
context: .
26+
dockerfile: Dockerfile
27+
args:
28+
- PYTHON_VERSION_SHORT
29+
- PYTHON_VERSION
30+
volumes:
31+
- .:/workspace/python-mode
32+
environment:
33+
- PYTHON_CONFIGURE_OPTS=--enable-shared
34+
- PYMODE_DIR=/workspace/python-mode
35+
- PYENV_ROOT=/opt/pyenv
36+
- PATH=/usr/local/bin:/opt/pyenv/bin:/opt/pyenv/shims:$PATH
37+
# Optional: Set PYTHON_VERSION to test with a specific Python version
38+
# - PYTHON_VERSION=3.11.9
39+
# Start an interactive shell for development
40+
command: ["/bin/bash"]
41+
stdin_open: true
42+
tty: true

readme.md

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Why Python-mode?
5656

5757
The plugin contains all you need to develop python applications in Vim.
5858

59-
* Support Python and 3.6+
59+
* Support Python 3.10.13, 3.11.9, 3.12.4, 3.13.0
6060
* Syntax highlighting
6161
* Virtualenv support
6262
* Run python code (`<leader>r`)
@@ -143,6 +143,41 @@ Then rebuild **helptags** in vim:
143143
**filetype-plugin** (`:help filetype-plugin-on`) and **filetype-indent**
144144
(`:help filetype-indent-on`) must be enabled to use python-mode.
145145

146+
# Docker Testing Environment
147+
148+
For consistent testing across different Python versions, python-mode provides a
149+
Docker-based testing environment. This is especially useful for contributors
150+
and developers who want to test the plugin with different Python versions.
151+
152+
## Quick Start
153+
154+
```bash
155+
# Run tests with default Python version (3.13.0)
156+
./scripts/run-tests-docker.sh
157+
158+
# Run tests with specific Python version
159+
./scripts/run-tests-docker.sh 3.11
160+
161+
# Run tests with all supported Python versions
162+
./scripts/test-all-python-versions.sh
163+
```
164+
165+
## Supported Python Versions
166+
167+
The Docker environment supports the following Python versions:
168+
- 3.10.13
169+
- 3.11.9
170+
- 3.12.4
171+
- 3.13.0 (default)
172+
173+
For detailed information about the Docker testing environment, see
174+
[README-Docker.md](README-Docker.md).
175+
176+
## Prerequisites
177+
178+
- Docker
179+
- Docker Compose
180+
146181
# Troubleshooting/Debugging
147182

148183
First read our short
@@ -188,6 +223,12 @@ Please, also provide more contextual information such as:
188223
* `git status` (under your _python-mode_ directory)
189224
* `tree <python-mode-directory>` or something similar (such as `ls -lR`)
190225

226+
If you're using the Docker testing environment, also provide:
227+
* The output of `docker --version` and `docker compose version`
228+
* The Python version used in Docker (if testing with a specific version)
229+
* Any Docker-related error messages
230+
* The output of `./scripts/run-tests-docker.sh --help` (if available)
231+
191232
# Frequent problems
192233

193234
Read this section before opening an issue on the tracker.
@@ -207,12 +248,50 @@ is a good reference on how to build vim from source.
207248
help you that much. Look for our branch with python2-support (old version,
208249
not maintained anymore) (`last-py2-support`).
209250

251+
## Python 3 Support
252+
253+
`python-mode` supports only Python 3. The project has completely removed Python 2
254+
support since version 0.11.0. Currently supported Python versions are:
255+
3.10.13, 3.11.9, 3.12.4, and 3.13.0.
256+
257+
If you need Python 2 support, you can use the legacy `last-py2-support` branch,
258+
but it is no longer maintained.
259+
260+
## Vim Python Support
261+
262+
Vim [has issues](https://github.com/vim/vim/issues/3585) when compiled with
263+
both Python 2 and Python 3 support. For best compatibility with python-mode,
264+
build Vim with only Python 3 support. See
265+
[this guide](https://github.com/ycm-core/YouCompleteMe/wiki/Building-Vim-from-source)
266+
for building Vim from source.
267+
210268
## Symlinks on Windows
211269

212270
Users on Windows OS might need to add `-c core.symlinks=true` switch to
213271
correctly clone / pull repository. Example: `git clone --recurse-submodules
214272
https://github.com/python-mode/python-mode -c core.symlinks=true`
215273

274+
## Docker Testing Issues
275+
276+
If you encounter issues with the Docker testing environment:
277+
278+
1. **Build Failures**: Ensure Docker and Docker Compose are properly installed
279+
and up to date. The Dockerfile requires Ubuntu 24.04 packages.
280+
281+
2. **Python Version Issues**: Verify that the requested Python version is
282+
supported (3.10.13, 3.11.9, 3.12.4, 3.13.0). Use the major.minor format
283+
(e.g., `3.11`) when specifying versions.
284+
285+
3. **Vim Build Issues**: The Docker environment builds Vim from source with
286+
Python support for each version. Ensure sufficient disk space and memory
287+
for the build process.
288+
289+
4. **Test Failures**: If tests fail in Docker but pass locally, check that
290+
all git submodules are properly initialized and the correct Python version
291+
is active.
292+
293+
For detailed troubleshooting, see [README-Docker.md](README-Docker.md).
294+
216295
## Error updating the plugin
217296

218297
If you are trying to update the plugin (using a plugin manager or manually) and
@@ -242,6 +321,19 @@ the issue tracker at:
242321
The contributing guidelines for this plugin are outlined at
243322
`:help pymode-development`.
244323

324+
Before contributing, please:
325+
326+
1. **Test with Docker**: Use the Docker testing environment to ensure your
327+
changes work across all supported Python versions (3.10.13, 3.11.9, 3.12.4, 3.13.0)
328+
329+
2. **Run Full Test Suite**: Use `./scripts/test-all-python-versions.sh` to test
330+
with all supported Python versions
331+
332+
3. **Check CI**: Ensure the GitHub Actions CI passes for your changes
333+
334+
4. **Follow Development Guidelines**: See `:help pymode-development` for detailed
335+
development guidelines
336+
245337
* Author: Kirill Klenov (<https://github.com/klen>)
246338
* Maintainers:
247339
* Felipe Vieira (<https://github.com/fmv1992>)

0 commit comments

Comments
 (0)