Skip to content

Commit

Permalink
Require Python 3
Browse files Browse the repository at this point in the history
Neovim has only supported 3 for a while, and the next release of
pynvim will require at least 3.7: neovim/pynvim@ac03f5c
  • Loading branch information
rdipardo committed Jul 14, 2023
1 parent ac1ddd3 commit 9c314f7
Show file tree
Hide file tree
Showing 26 changed files with 73 additions and 116 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
python-version: '3.11'
- name: Restore cache
uses: actions/cache@v3.2.6
uses: actions/cache@v3.3.1
with:
path: '~/.cache/pip'
key: ${{ runner.os }}-pip-${{ hashFiles('.vintrc.yml') }}
Expand All @@ -33,29 +33,29 @@ jobs:
strategy:
matrix:
vim-version: [7.4.1689, 8.2.4049, 9.0.0304]
python-version: ['2.7.18', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'ubuntu']
python-version: ['3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'ubuntu']
env:
LOG: python-${{ matrix.python-version }}-bench.log
steps:
- uses: actions/checkout@v3
- name: Set up python
if: ${{ !startswith(matrix.python-version, 'ubuntu') }}
if: ${{ matrix.python-version != 'ubuntu' }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install latest pip
if: ${{ !(startsWith(matrix.python-version, '2.7') || startsWith(matrix.python-version, '3.5')) }}
if: ${{ !startsWith(matrix.python-version, '3.5') }}
run: |
pip install --upgrade pip
- name: Install pip < 21.0
if: ${{ (startsWith(matrix.python-version, '2.7') || startsWith(matrix.python-version, '3.5')) }}
if: ${{ startsWith(matrix.python-version, '3.5') }}
run: |
pip install --upgrade 'pip < 21.0'
- name: Restore pip cache
uses: actions/cache@v3.2.6
uses: actions/cache@v3.3.1
with:
path: '~/.cache/pip'
key: ${{ matrix.python-version }}-pip-${{ hashFiles('**/test/requirements.txt') }}
Expand All @@ -73,7 +73,7 @@ jobs:
fetch-depth: 1

- name: Install neovim (current stable)
if: ${{ !(startsWith(matrix.python-version, '2.7') || startsWith(matrix.python-version, '3.5') || startsWith(matrix.python-version, '3.6')) }}
if: ${{ !(startsWith(matrix.python-version, '3.5') || startsWith(matrix.python-version, '3.6')) }}
uses: rhysd/action-setup-vim@v1
id: neovim-stable
with:
Expand All @@ -95,28 +95,29 @@ jobs:
# > from collections import Callable
run: pytest -v -W ignore::DeprecationWarning

- name: Test plugin on vim with Python 3
if: ${{ startswith(matrix.python-version, 'ubuntu') }}
- name: Test plugin on Ubuntu vim
if: ${{ matrix.python-version == 'ubuntu' }}
run: |
sudo apt-get -qq update
sudo apt-get -qqy install vim
vim --startuptime vim_bench.log -ENsu test/vimrc -c '+Vader! test/vader/**/*.vader' > /dev/null
.github/scripts/collect_start_times vim vim-${{ matrix.vim-version }}-$LOG
- name: Test plugin on vim with Python 2
if: ${{ startsWith(matrix.python-version, '2.7') }}
- name: Test plugin on vim ${{ matrix.vim-version }}
if: ${{ (startsWith(matrix.python-version, '3.5') || startsWith(matrix.python-version, '3.6')) }}
run: |
git clone --branch v${{ matrix.vim-version }} https://github.com/vim/vim.git vim-src
pushd vim-src
./configure --prefix=/usr/local --with-features=normal \
--enable-pythoninterp=dynamic \
--with-python-config-dir=$(find $Python_ROOT_DIR -iname Makefile | xargs dirname)
git grep -l '# undef _POSIX_THREADS' | xargs -I% sed -i '/# undef _POSIX_THREADS/d' %
CFLAGS=-D_POSIX_THREADS ./configure --prefix=/usr/local --with-features=normal \
--enable-python3interp=dynamic \
--with-python3-config-dir=$(find $Python_ROOT_DIR -iname Makefile | xargs dirname)
make && sudo make install && popd
/usr/local/bin/vim --startuptime vim_bench.log -ENsu test/vimrc -c '+Vader! test/vader/pyx/*' > /dev/null
/usr/local/bin/vim --startuptime vim_bench.log -ENsu test/vimrc -c '+Vader! test/vader/*' > /dev/null
.github/scripts/collect_start_times vim vim-${{ matrix.vim-version }}-$LOG
- name: Test plugin on current stable neovim
if: ${{ !(startsWith(matrix.python-version, '2.7') || startsWith(matrix.python-version, '3.5') || startsWith(matrix.python-version, '3.6')) }}
if: ${{ !(startsWith(matrix.python-version, '3.5') || startsWith(matrix.python-version, '3.6')) }}
run: |
"${{ steps.neovim-stable.outputs.executable }}" --startuptime nvim_bench.log -ENsu test/vimrc -c '+Vader! test/vader/**/*.vader' > /dev/null
Expand All @@ -126,7 +127,6 @@ jobs:
"${{ steps.neovim.outputs.executable }}" --startuptime nvim_bench.log -ENsu test/vimrc -c '+Vader! test/vader/**/*.vader' > /dev/null
- name: Check neovim startup times
if: ${{ !startsWith(matrix.python-version, '2.7') }}
run: |
.github/scripts/collect_start_times nvim neovim-${{ matrix.nvim-version }}-$LOG
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.pytest_cache/
test/src/
vader.vim/
!test/src/.gitkeep
11 changes: 4 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ copyright line will contain your OS user and host names.
Features
========

* Python bindings compatible with python 2.7.x or 3.4+, depending on your
* Python bindings compatible with python 3.7+, depending on your
platform and (neo)vim version, of course

:NOTE: Python 3.10 requires `neovim 0.6.0`_ or newer.
Expand Down Expand Up @@ -146,23 +146,20 @@ Options
Requirements
============

* Vim compiled with any one of the *+python[3]* or *+python[3]/dyn* options.
See if you're supported by entering ``vim --version | grep +python`` at your
* Vim compiled with any one of the *+python3* or *+python3/dyn* options.
See if you're supported by entering ``vim --version | grep +python3`` at your
terminal, or start ``vim`` and enter the ``:version`` command

* Neovim with the `pynvim`_ module in your ``$PYTHONPATH``. Start ``nvim``
and enter ``:help provider-python`` for more information

.. _pynvim: https://github.com/neovim/pynvim
.. _requests: https://pypi.org/project/requests

Installation
============

If `requests`_ and (optionally) `pynvim`_ are not already in your ``$PYTHONPATH``,
install them::
If `pynvim`_ is not already in your ``$PYTHONPATH``, install it::

pip install --user -U requests
pip install --user -U pynvim


Expand Down
2 changes: 1 addition & 1 deletion autoload/cpywrite.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if get(g:, 'autoloaded_cpywrite') | finish | endif
let g:autoloaded_cpywrite = 1

if has('python3') || has('python')
if has('python3')
if empty(get(s:, 'cpywrite_python_cmd', ''))
let s:cpywrite_python_cmd = (has('python3') ? 'py3' : 'py') . 'file'
endif
Expand Down
3 changes: 1 addition & 2 deletions autoload/cpywrite/error.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func! cpywrite#error#NoPython() abort
else
echohl WarningMsg |
echom
\ 'Sorry: vim-cpywrite requires one of the following features:
\ +python, +python3, +python/dyn, or +python3/dyn.
\ 'Sorry: vim-cpywrite requires +python3 or +python3/dyn.
\ Enter ":help python" for more information.'
\ | echohl None
endif
Expand Down
7 changes: 1 addition & 6 deletions doc/cpywrite.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,14 @@ your OS user and host names.
=============================================================================
REQUIREMENTS *cpywrite-requirements*

* Vim compiled with any one of the `+python`, `+python3`, `+python/dyn` or
`+python3/dyn` options
* Vim compiled with the |+python3| or |+python3/dyn| option

* Neovim with the `pynvim` module in your $PYTHONPATH:

https://github.com/neovim/pynvim

Enter |:help| |provider-python| in your command prompt for more information.

* The `requests` module in your $PYTHONPATH:

https://pypi.org/project/requests

=============================================================================
ATTRIBUTES *cpywrite-attributes*

Expand Down
2 changes: 1 addition & 1 deletion plugin/cpywrite/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import vim
from re import match, sub
for path in vim.eval('globpath(&rtp,"rplugin/pythonx",1)').split('\n'):
for path in vim.eval('globpath(&rtp,"rplugin/python3",1)').split('\n'):
sys.path.append(path)
from cpywrite.generator import Generator, _get_source_author

Expand Down
2 changes: 1 addition & 1 deletion plugin/cpywrite/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import vim
from re import match, IGNORECASE
for path in vim.eval('globpath(&rtp, "rplugin/pythonx", 1)').split('\n'):
for path in vim.eval('globpath(&rtp, "rplugin/python3", 1)').split('\n'):
sys.path.append(path)
from cpywrite import licenses

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"""
Module entry point, when invoked at the command line
"""
from __future__ import print_function
import sys
import tempfile
from os import path
from argparse import ArgumentParser, ArgumentError
from .generator import Generator, extensions
from cpywrite.generator import Generator, extensions

def main():
"""Prepend a license header to a new or existing source file"""
Expand Down Expand Up @@ -56,24 +55,24 @@ def main():
args.no_anon)
if license_text:
if not path.exists(generator.out_file):
with open(generator.out_file, 'w') as src:
with open(generator.out_file, 'w', encoding='utf-8') as src:
src.truncate(8)

print("Created new %s file: %s"
% (generator.lang, generator.out_file))
else:
with open(generator.out_file + '.bak', 'w') as bak:
with open(generator.out_file, 'rt') as source:
with open(generator.out_file + '.bak', 'w', encoding='utf-8') as bak:
with open(generator.out_file, 'rt', encoding='utf-8') as source:
source_file = source.read()
bak.write(source_file)

_, tmp_source = tempfile.mkstemp(text=True)

with open(tmp_source, 'w') as tmp:
with open(tmp_source, 'w', encoding='utf-8') as tmp:
tmp.write("%s%s" % (license_text, source_file))

with open(tmp_source, 'rt') as new_content:
with open(generator.out_file, 'w') as source:
with open(tmp_source, 'rt', encoding='utf-8') as new_content:
with open(generator.out_file, 'w', encoding='utf-8') as source:
source.write(new_content.read())

else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
Module providing a file writer
"""
from __future__ import print_function, unicode_literals
import re
import sys
from datetime import datetime
Expand All @@ -17,7 +16,7 @@
__all__ = ['Generator', 'extensions']


class Generator(object): # pylint: disable=R0205
class Generator():
"""A source file generator"""
def __init__(self, filename='new.py', vim_filetype='python', rights='Apache-2.0'):
self.set_file_props(filename, vim_filetype, rights)
Expand Down
File renamed without changes.
Loading

0 comments on commit 9c314f7

Please sign in to comment.