Skip to content

Commit

Permalink
Get CI working completely
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Feb 13, 2023
1 parent 93299cf commit a9bb4de
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
vim-version:
job-type:
- '--vim-80-only'
- '--vim-90-only'
- '--neovim-06-only'
- '--neovim-08-only'
- '--python-only'
- '--linters-only'
steps:
- uses: actions/checkout@v2
- name: Run tests
run: ./run-tests -v ${{ matrix.vim-version }}
run: ./run-tests -v ${{ matrix.job-type }}
39 changes: 33 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
FROM testbed/vim:24

RUN install_vim -tag v8.0.0027 -build \
-tag v9.0.0297 -build \
-tag neovim:v0.6.0 -build \
-tag neovim:v0.8.0 -build

# Add packages we need.
#
# We need most packages for installing Python.
# We need nodejs for pyright.
ENV PACKAGES="\
bash \
curl \
git \
build-base \
patch \
zlib-dev \
libffi-dev \
linux-headers \
readline-dev \
openssl \
nodejs \
openssl-dev \
sqlite-dev \
bzip2-dev \
python3 \
py3-pip \
grep \
Expand All @@ -16,8 +27,24 @@ ENV PACKAGES="\
RUN apk --update add $PACKAGES && \
rm -rf /var/cache/apk/* /tmp/* /var/tmp/*

RUN pip install vim-vint==0.3.21
# Install tools for Python testing.
ENV PATH /root/.pyenv/shims:/root/.pyenv/bin:$PATH
# We need --ignore-installed to ignore the `packaging` package version.
RUN pip install --ignore-installed tox==4.4.5
RUN curl https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash \
&& eval "$(pyenv init -)" \
&& eval "$(pyenv virtualenv-init -)" \
&& pyenv install 3.7 \
&& pyenv install 3.10 \
&& ln -s /root/.pyenv/versions/3.7.*/bin/python3.7 /root/.pyenv/bin/python3.7 \
&& ln -s /root/.pyenv/versions/3.10.*/bin/python3.10 /root/.pyenv/bin/python3.10

# Install tools for Vim testing.
RUN install_vim -tag v8.0.0027 -build \
-tag v9.0.0297 -build \
-tag neovim:v0.8.0 -build
# Install vint with Python 3.10 to avoid `packaging` issues.
RUN python3.10 -m pip install vim-vint==0.3.21
RUN git clone https://github.com/junegunn/vader.vim vader && \
cd vader && git checkout c6243dd81c98350df4dec608fa972df98fa2a3af

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ OpenAI for blazingly fast text and code generation.

## 🌟 Features

* Compatible with Vim 8.0+
* Compatible with Vim 8.0+ and Neovim 0.8+
* Support for multiple machine learning models
* Generates text easily (`:Neural write a story`)
* The only dependency is Python
* The only dependency is Python 3.7+
* Supported on Linux, Mac OSX, and Windows

https://user-images.githubusercontent.com/38880939/209406364-d1ae162a-9fb3-4e15-8dbb-4890a4db1f5d.mov
Expand Down
2 changes: 1 addition & 1 deletion doc/neural-development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Make sure all required Python versions for testing are installed.
Neural tests against Python 3.7 and Python 3.10.

Run the following: >
python -m pip install --user tox
python -m pip install --user tox==4.4.5
python -m tox
<

Expand Down
2 changes: 1 addition & 1 deletion neural_sources/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(
self.frequency_penalty = frequency_penalty



def get_openai_completion(config: Config, prompt: str) -> None:
headers = {
"Content-Type": "application/json",
Expand Down Expand Up @@ -140,5 +139,6 @@ def main() -> None:
else:
raise


if __name__ == "__main__": # pragma: no cover
main() # pragma: no cover
46 changes: 27 additions & 19 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ git_version=$(git describe --always --tags)
DOCKER_RUN_IMAGE="$image:$image_tag"
export DOCKER_RUN_IMAGE

tests='test/*.vader test/*/*.vader test/*/*/*.vader'
tests='test/vim/*.vader'
# These flags are forwarded to the script for running Vader tests.
verbose_flag=''
quiet_flag=''
run_neovim_06_tests=1
run_neovim_08_tests=1
run_vim_80_tests=1
run_vim_90_tests=1
run_linters=1
run_python=1

while [ $# -ne 0 ]; do
case $1 in
Expand All @@ -44,63 +44,65 @@ while [ $# -ne 0 ]; do
--build-image)
run_vim_80_tests=0
run_vim_90_tests=0
run_neovim_06_tests=0
run_neovim_08_tests=0
run_linters=0
run_python=0
shift
;;
--neovim-only)
run_vim_80_tests=0
run_vim_90_tests=0
run_linters=0
shift
;;
--neovim-06-only)
run_neovim_08_tests=0
run_vim_80_tests=0
run_vim_90_tests=0
run_linters=0
run_python=0
shift
;;
--neovim-08-only)
run_neovim_06_tests=0
run_vim_80_tests=0
run_vim_90_tests=0
run_linters=0
run_python=0
shift
;;
--vim-only)
run_neovim_06_tests=0
run_neovim_08_tests=0
run_linters=0
run_python=0
shift
;;
--vim-80-only)
run_neovim_06_tests=0
run_neovim_08_tests=0
run_vim_90_tests=0
run_linters=0
run_python=0
shift
;;
--vim-90-only)
run_neovim_06_tests=0
run_neovim_08_tests=0
run_vim_80_tests=0
run_linters=0
run_python=0
shift
;;
--python-only)
run_vim_80_tests=0
run_vim_90_tests=0
run_neovim_08_tests=0
run_linters=0
run_python=1
shift
;;
--linters-only)
run_vim_80_tests=0
run_vim_90_tests=0
run_neovim_06_tests=0
run_neovim_08_tests=0
run_python=0
shift
;;
--fast)
run_vim_80_tests=0
run_vim_90_tests=0
run_neovim_06_tests=0
run_neovim_08_tests=1
run_python=1
shift
;;
--help)
Expand All @@ -114,13 +116,13 @@ while [ $# -ne 0 ]; do
echo ' -q Hide output for successful tests'
echo ' --build-image Run docker image build only.'
echo ' --neovim-only Run tests only for NeoVim'
echo ' --neovim-06-only Run tests only for NeoVim 0.6'
echo ' --neovim-08-only Run tests only for NeoVim 0.8'
echo ' --vim-only Run tests only for Vim'
echo ' --vim-80-only Run tests only for Vim 8.2'
echo ' --vim-90-only Run tests only for Vim 9.0'
echo ' --linters-only Run only Vint and custom checks'
echo ' --fast Run only the fastest Vim and custom checks'
echo ' --python-only Run only Python checks'
echo ' --fast Run only the fastest Vim and the rest'
echo ' --help Show this help text'
echo ' -- Stop parsing options after this'
exit 0
Expand Down Expand Up @@ -229,7 +231,6 @@ trap cancel_tests INT TERM
for vim in $(docker run --rm "$DOCKER_RUN_IMAGE" ls /vim-build/bin | grep '^neovim\|^vim' ); do
if ( [[ $vim =~ ^vim-v8.0 ]] && ((run_vim_80_tests)) ) \
|| ( [[ $vim =~ ^vim-v9.0 ]] && ((run_vim_90_tests)) ) \
|| ( [[ $vim =~ ^neovim-v0.6 ]] && ((run_neovim_06_tests)) ) \
|| ( [[ $vim =~ ^neovim-v0.8 ]] && ((run_neovim_08_tests)) ); then
echo "Starting Vim: $vim..."
file_number=$((file_number+1))
Expand All @@ -239,6 +240,13 @@ for vim in $(docker run --rm "$DOCKER_RUN_IMAGE" ls /vim-build/bin | grep '^neov
fi
done

if ((run_python)); then
echo "Starting Python checks..."
file_number=$((file_number+1))
test/script/run-python > "$output_dir/$file_number" 2>&1 &
pid_list="$pid_list $!"
fi

if ((run_linters)); then
echo "Starting Vint..."
file_number=$((file_number+1))
Expand Down
4 changes: 3 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pyright==1.1.293
pytest-cov==4.0.0
pytest==7.2.1
ruff==0.0.237
flake8==5.0.4
flake8-isort==6.0.0
isort==5.11.5
4 changes: 3 additions & 1 deletion test/python/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def test_main_function_rate_other_error():
with pytest.raises(urllib.error.HTTPError):
openai.main()


def test_print_openai_results():
result_data = (
b'data: {"id": "cmpl-6jMlRJtbYTGrNwE6Lxy1Ns1EtD0is", "object": "text_completion", "created": 1676270285, "choices": [{"text": "\\n", "index": 0, "logprobs": null, "finish_reason": null}], "model": "text-davinci-003"}\n' # noqa
Expand All @@ -90,7 +91,7 @@ def test_print_openai_results():
b'\n'
b'data: {"id": "cmpl-6jMlRJtbYTGrNwE6Lxy1Ns1EtD0is", "object": "text_completion", "created": 1676270285, "choices": [{"text": "Hello", "index": 0, "logprobs": null, "finish_reason": null}], "model": "text-davinci-003"}\n' # noqa
b'data: {"id": "cmpl-6jMlRJtbYTGrNwE6Lxy1Ns1EtD0is", "object": "text_completion", "created": 1676270285, "choices": [{"text": "!", "index": 0, "logprobs": null, "finish_reason": null}], "model": "text-davinci-003"}\n' # noqa
b'\n'
b'\n'
b'data: {"id": "cmpl-6jMlRJtbYTGrNwE6Lxy1Ns1EtD0is", "object": "text_completion", "created": 1676270285, "choices": [{"text": "", "index": 0, "logprobs": null, "finish_reason": "stop"}], "model": "text-davinci-003"}\n' # noqa
b'\n'
b'data: [DONE]\n'
Expand Down Expand Up @@ -119,6 +120,7 @@ def test_print_openai_results():
mock.call(),
]


def test_main_function_bad_config():
with mock.patch.object(sys.stdin, 'readline') as readline_mock, \
mock.patch.object(openai, 'load_config') as load_config_mock:
Expand Down
20 changes: 14 additions & 6 deletions test/script/custom-linting-rules
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -u

# A flag for automatically fixing some errors.
FIX_ERRORS=0
RETURN_CODE=0
exit_code=0

function print_help() {
echo "Usage: test/script/custom-linting-rules [--fix] [DIRECTORY]" 1>&2
Expand Down Expand Up @@ -84,7 +84,7 @@ check_errors() {
fi
fi

RETURN_CODE=1
exit_code=1
echo "$REPLY $message"
done < <(grep -H -n "$regex" $include_arg $exclude_arg "$directory"/**/*.vim \
| grep -v 'no-custom-checks' \
Expand Down Expand Up @@ -157,10 +157,18 @@ check_errors '\(!=.\?\|isnot\) type(function([^)]\+))' "Use 'isnot v:t_func' ins
# Run a Python script to find lines that require padding around them. For
# users without Python installed, we'll skip these checks. GitHub Actions will
# run the script.
if command -v python > /dev/null; then
if ! test/script/block-padding-checker "$directory"/**/*.vim; then
RETURN_CODE=1
python=''

if command -v python3.10 > /dev/null; then
python=python3.10
elif command -v python > /dev/null; then
python=python
fi

if [ -n "$python" ]; then
if ! "$python" test/script/block-padding-checker "$directory"/**/*.vim; then
exit_code=1
fi
fi

exit $RETURN_CODE
exit $exit_code
19 changes: 19 additions & 0 deletions test/script/run-python
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -eu

exit_code=0

docker_flags=(--rm -v "$PWD:/testplugin" -w /testplugin "$DOCKER_RUN_IMAGE")

echo '========================================'
echo 'Running Python checks'
echo '========================================'
echo 'tox warnings/errors follow:'
echo

set -o pipefail
docker run -a stdout "${docker_flags[@]}" tox --workdir .tox-docker --skip-missing-interpreters=false || exit_code=$?
set +o pipefail

exit $exit_code
5 changes: 1 addition & 4 deletions test/script/run-vader-tests
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ tests="$2"
echo "$vim"

case $vim in
neovim-v0.2*)
headless=''
;;
# Neovim 0.6+ requires headless argument to load Vader tests.
neovim*)
headless='--headless'
Expand Down Expand Up @@ -149,7 +146,7 @@ while [ "$tries" -lt 5 ]; do
set -o pipefail
# shellcheck disable=SC2086
docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${docker_flags[@]}" \
"/vim-build/bin/$vim" -u test/vimrc ${headless} \
"/vim-build/bin/$vim" -u test/vim/vimrc ${headless} \
"+Vader! $tests" 2>&1 | filter-vader-output | color-vader-output || exit_code=$?
set +o pipefail

Expand Down
6 changes: 4 additions & 2 deletions test/script/run-vint
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ echo '========================================'
echo 'Vint warnings/errors follow:'
echo

vint='/root/.pyenv/versions/3.10.10/bin/vint'

set -o pipefail
docker run -a stdout "${docker_flags[@]}" vint -s . || exit_code=$?
docker run -a stdout "${docker_flags[@]}" "$vint" -s autoload plugin || exit_code=$?
set +o pipefail
echo

exit $exit_code
exit "$exit_code"
2 changes: 1 addition & 1 deletion test/smoke_test.vader → test/vim/smoke_test.vader
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Execute(Check that Neural scripts load at all):
AssertEqual v:t_string, type(neural#Escape(''))
AssertEqual v:t_dict, type(neural#datasource#openai#Get())
AssertEqual v:t_dict, type(neural#source#openai#Get())
18 changes: 18 additions & 0 deletions test/vim/vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
" vint: -ProhibitSetNoCompatible

" Load builtin plugins
" We need this because run_vim.sh sets -i NONE
if has('win32')
set runtimepath=$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,C:\vader,C:\testplugin
else
set runtimepath=/home/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,/testplugin,/vader
endif

if !has('win32')
set shell=/bin/sh
set shellcmdflag=-c
endif

set nocompatible
" The encoding must be explicitly set for tests for Windows.
execute 'set encoding=utf-8'
Loading

0 comments on commit a9bb4de

Please sign in to comment.