mirror of
https://github.com/raimon49/requirements.txt.vim.git
synced 2025-12-06 18:14:26 +08:00
Merge pull request #15 from ericbn/master
Set makeprg if pip-compile is available
This commit is contained in:
11
after/ftplugin/requirements.vim
Normal file
11
after/ftplugin/requirements.vim
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
if executable('pip-compile')
|
||||||
|
let s:filename = expand("%:p")
|
||||||
|
if fnamemodify(s:filename, ":t") ==# 'requirements.in'
|
||||||
|
" this is the default filename for pip-compile
|
||||||
|
setlocal makeprg=pip-compile
|
||||||
|
elseif fnamemodify(s:filename, ":e") ==# 'in'
|
||||||
|
\ && Requirements_matched_filename(s:filename)
|
||||||
|
setlocal makeprg=pip-compile\ %
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
" vim: et sw=4 ts=4 sts=4:
|
||||||
@@ -34,15 +34,16 @@ function! s:isRequirementsFile()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! Requirements_matched_filename(filename)
|
function! Requirements_matched_filename(filename)
|
||||||
if a:filename =~# '\v.*require(ment)?s\.(txt|in)$'
|
if fnamemodify(a:filename, ":t") =~# '\vrequire(ment)?s.*\.(txt|in)$'
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if a:filename =~# '\vrequire(ment)?s/.*\.(txt|in)$'
|
if fnamemodify(fnamemodify(a:filename, ":h"), ":t") =~# '\v^require(ment)?s$'
|
||||||
|
\ && fnamemodify(a:filename, ":e") =~# '\v^(txt|in)$'
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if a:filename =~# '\vconstraints\.(txt|in)$'
|
if fnamemodify(a:filename, ":t") =~# '\v^constraints\.(txt|in)$'
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,16 @@ runtime! plugin/requirements.vim
|
|||||||
describe 'enable: Requirements_matched_filename()'
|
describe 'enable: Requirements_matched_filename()'
|
||||||
it 'to enable file type detection: basic filename'
|
it 'to enable file type detection: basic filename'
|
||||||
Expect Requirements_matched_filename('requirements.txt') to_be_true
|
Expect Requirements_matched_filename('requirements.txt') to_be_true
|
||||||
|
Expect Requirements_matched_filename('requirements-dev.txt') to_be_true
|
||||||
|
Expect Requirements_matched_filename('dev-requirements.txt') to_be_true
|
||||||
Expect Requirements_matched_filename('requires.txt') to_be_true
|
Expect Requirements_matched_filename('requires.txt') to_be_true
|
||||||
Expect Requirements_matched_filename('constraints.txt') to_be_true
|
Expect Requirements_matched_filename('constraints.txt') to_be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'to enable file type detection: pip-tools filename'
|
it 'to enable file type detection: pip-tools filename'
|
||||||
Expect Requirements_matched_filename('requirements.in') to_be_true
|
Expect Requirements_matched_filename('requirements.in') to_be_true
|
||||||
|
Expect Requirements_matched_filename('requirements-dev.in') to_be_true
|
||||||
|
Expect Requirements_matched_filename('dev-requirements.in') to_be_true
|
||||||
Expect Requirements_matched_filename('requires.in') to_be_true
|
Expect Requirements_matched_filename('requires.in') to_be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,6 +34,8 @@ describe 'disable: Requirements_matched_filename()'
|
|||||||
|
|
||||||
it 'to disable: file type detection: directory structure'
|
it 'to disable: file type detection: directory structure'
|
||||||
Expect Requirements_matched_filename('require/dev.txt') to_be_false
|
Expect Requirements_matched_filename('require/dev.txt') to_be_false
|
||||||
|
Expect Requirements_matched_filename('requirements-dev/dev.txt') to_be_false
|
||||||
|
Expect Requirements_matched_filename('dev-requirements/dev.txt') to_be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user