diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e3b59b1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.vader linguist-language=Vim diff --git a/.github/ISSUE_TEMPLATE/new-issue.md b/.github/ISSUE_TEMPLATE/new-issue.md index 9081501..3fd2663 100644 --- a/.github/ISSUE_TEMPLATE/new-issue.md +++ b/.github/ISSUE_TEMPLATE/new-issue.md @@ -10,7 +10,7 @@ assignees: '' *Please provide the following with your description of the issue:* - [ ] Platform information (e.g. Ubuntu Linux 16.04): - [ ] Python version: -- [ ] plugin version (enter `:echo g:cpywrite#version` at the vim command window): +- [ ] Plugin version (`vim -V1 -i NONE -ENsu ~/.vimrc -c ':echo g:cpywrite#version' +q`): *If applicable, include one of the following:* - [ ] Output of `pip list | grep requests`: diff --git a/.github/img/vim_8.2.2549.gif b/.github/img/vim_8.2.2549.gif deleted file mode 100644 index 7a869d2..0000000 Binary files a/.github/img/vim_8.2.2549.gif and /dev/null differ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aa8fa7..d193451 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,7 +96,12 @@ jobs: version: ${{ matrix.nvim-version }} - name: Run python tests - run: pytest -v + # > platform linux -- Python 3.7.3, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3 + # > ... + # > /usr/lib/python3/dist-packages/socks.py:58: DeprecationWarning: Using or importing the ABCs from 'collections' + # > instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working + # > from collections import Callable + run: pytest -v -W ignore::DeprecationWarning - name: Test plugin on vim run: | diff --git a/CHANGELOG.rst b/CHANGELOG.rst index aa2ba29..75fab69 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,22 @@ CHANGELOG :depth: 1 :backlinks: top +0.3.4 +====== +**(2021-04-04)** + +Fixed +----- +- prevent copyright year regex from accidentally matching older versions of the + Mozilla Public License +- don't throw an exception if the full name of a license doesn't start with *The* +- don't print angle brackets when ``user.email`` is empty + +Changed +------- +- try to detect the user's interpreter program when modifying a shell script +- remove example GIF from plugin assets and use a hyperlink instead + 0.3.3 ====== **(2021-03-08)** @@ -14,7 +30,7 @@ Fixed ----- - (temporarily) request *ALL* full text licenses from the `previous release versions`_ (with the exception of the `Unlicense`_ and `BSD-1-Clause`_ as before). A future - release will probably start using a different repository when theses versions + release will probably start using a different repository when these versions fall too far behind the officially recognized templates - minor refactoring of some redundant code @@ -32,7 +48,7 @@ Fixed `BSD-1-Clause`_ - minor pruning of some unreachable code (overlooked in `last release`_) -.. _last release: https://github.com/rdipardo/vim-cpywrite/releases/tag/v0.3.1 +.. _last release: https://github.com/rdipardo/vim-cpywrite/blob/master/CHANGELOG.rst#031 Added ----- diff --git a/README.rst b/README.rst index 4ec0c18..d4f29a6 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ vim-cpywrite Generate copyright headers for any open source license -.. figure:: .github/img/vim_8.2.2549.gif +.. figure:: https://raw.githubusercontent.com/rdipardo/vim-cpywrite/media/rel/vim_8.2.2549.gif :alt: vim-win-x64-demo :align: center :width: 900 diff --git a/plugin/cpywrite.vim b/plugin/cpywrite.vim index 46bf751..dbece1a 100644 --- a/plugin/cpywrite.vim +++ b/plugin/cpywrite.vim @@ -9,7 +9,7 @@ if get(g:, 'loaded_cpywrite') | finish | endif let g:loaded_cpywrite = 1 -let g:cpywrite#version = '0.3.3' +let g:cpywrite#version = '0.3.4' if empty(get(g:, 'cpywrite#default_license', '')) let g:cpywrite#default_license = 'GPL-3.0-or-later' diff --git a/rplugin/pythonx/cpywrite/__init__.py b/rplugin/pythonx/cpywrite/__init__.py index 996418a..aa3877d 100644 --- a/rplugin/pythonx/cpywrite/__init__.py +++ b/rplugin/pythonx/cpywrite/__init__.py @@ -20,7 +20,7 @@ ~~~~~~~~~ """ -__version__ = '0.3.3' +__version__ = '0.3.4' __authors__ = ['Robert Di Pardo'] __url__ = 'https://github.com/rdipardo/vim-cpywrite' __license__ = 'MIT' diff --git a/rplugin/pythonx/cpywrite/generator.py b/rplugin/pythonx/cpywrite/generator.py index baaa503..fbb2c29 100644 --- a/rplugin/pythonx/cpywrite/generator.py +++ b/rplugin/pythonx/cpywrite/generator.py @@ -56,7 +56,7 @@ def _close_block_comment(dest): print('\n?>', file=dest) def _apply_format(text, pattern, author, email, year): - authorship = year + ' ' + author + ' <' + email + '>' + authorship = year + ' ' + author # watch out for 20^th-century year template of the older GPLs text = \ @@ -70,12 +70,13 @@ def _apply_format(text, pattern, author, email, year): re.sub(r'(%s).+(\w+Permission)' % self.tokens[1], '%sPermission' % self.tokens[1], text)) # wrap text if raw header has no break after author's email - if self.rights.spdx_code.startswith('ECL'): - run_on_text = re.search(r'(%s).+((%s)|\<(%s)\>)\w' \ + elif self.rights.spdx_code.startswith('ECL'): + run_on_text = re.search(r'(%s).+((%s)|(%s))\w' \ % (self.tokens[1], author, re.escape(email)), text) + if run_on_text: one_liner = \ 'Copyright (c) ' + authorship + ' Distributed under the' @@ -88,6 +89,10 @@ def _apply_format(text, pattern, author, email, year): self.tokens[1], run_on_text.group()[-1]), text) + else: + text = re.sub(r'(%s)' % re.escape(authorship), + authorship + email, + text) return text @@ -95,14 +100,15 @@ def _apply_format(text, pattern, author, email, year): out = StringIO() year = str(datetime.now())[:4] author, email = _get_source_author() + contact = ' <' + email + '>' if email else '' copying = \ - 'Copyright (c) ' + year + ' ' + author + ' <' + email + '>' + 'Copyright (c) ' + year + ' ' + author + contact terms = \ self.rights.header \ if not full_text \ else self.rights.license_text author_date = \ - re.compile(r"(?!.*(http).*)[\<\[\s][YEARX]+[\>\]\s].+[\>\]]", + re.compile(r"(?!.*(http).*)[\<\[\s]((YEAR)|[YX]+)[\>\]\s].+[\>\]]", re.IGNORECASE) if self.lang_key in _SCRIPT_HEADERS: @@ -128,12 +134,12 @@ def _clean_tokens(tkn, line): # probably a GFDL or older GPL with an oddball authorship # template author_date = \ - re.compile(r"(?!.*(http).*)[\<\[\s][YEARX]+[\>\]\s].+[\>\]\.]", + re.compile(r"(?!.*(http).*)[\<\[\s]((YEAR)|[YX]+)[\>\]\s].+[\>\]\.]", re.IGNORECASE) - terms = _apply_format(terms, author_date, author, email, year) + terms = _apply_format(terms, author_date, author, contact, year) - if not re.findall(r'(<%s>)' % re.escape(email), + if not re.findall(r'(%s)' % author, terms, re.MULTILINE) \ and not in_pub_domain(self.rights.spdx_code): @@ -373,7 +379,10 @@ def _get_source_author(): """ _SCRIPT_HEADERS = { - 'shell script': '#!/usr/bin/env bash', + 'shell script': '#!/usr/bin/env %s' + % re.sub(r'^\$\w+', + 'bash', + path.expandvars('$SHELL').split('/')[-1]), 'perl': '#!/usr/bin/env perl', 'php': '