Skip to content

Commit 4d7bfe2

Browse files
committed
Merge branch 'release/0.6.16'
2 parents 32d586b + f917991 commit 4d7bfe2

File tree

17 files changed

+593
-226
lines changed

17 files changed

+593
-226
lines changed

Changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
## 2013-04-26 0.6.16
5+
--------------------
6+
* Improvement folding (thanks @alvinfrancis);
7+
8+
## 2013-04-01 0.6.15
9+
--------------------
10+
* Bugfix release
11+
412
## 2013-03-16 0.6.14
513
--------------------
614
* Update `PEP8` to version 1.4.5;

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Then rebuild **helptags** in vim::
9696
Troubleshooting
9797
===============
9898

99-
If your python-mode dont work, type command: ::
99+
If your python-mode dont work, open any python file and type command: ::
100100

101101
:call pymode#troubleshooting#Test()
102102

autoload/pymode.vim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,24 @@ fun! pymode#QuickfixOpen(onlyRecognized, holdCursor, maxHeight, minHeight, jumpE
5050
endfunction "}}}
5151

5252

53-
fun! pymode#PlaceSigns() "{{{
53+
fun! pymode#PlaceSigns(bnum) "{{{
5454
" DESC: Place error signs
5555
"
5656
if has('signs')
57-
sign unplace *
57+
call pymode#Default('b:pymode_signs', [])
58+
59+
for item in b:pymode_signs
60+
execute printf('sign unplace %d buffer=%d', item.lnum, item.bufnr)
61+
endfor
62+
let b:pymode_signs = []
5863

5964
if !pymode#Default("g:pymode_lint_signs_always_visible", 0) || g:pymode_lint_signs_always_visible
6065
call RopeShowSignsRulerIfNeeded()
6166
endif
6267

6368
for item in filter(getqflist(), 'v:val.bufnr != ""')
64-
execute printf('silent! sign place 1 line=%d name=%s buffer=%d', item.lnum, item.type, item.bufnr)
69+
call add(b:pymode_signs, item)
70+
execute printf('sign place %d line=%d name=%s buffer=%d', item.lnum, item.lnum, "Pymode".item.type, item.bufnr)
6571
endfor
6672

6773
endif

autoload/pymode/folding.vim

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33

44
let s:blank_regex = '^\s*$'
5-
let s:def_regex = '^\s*\(class\|def\) \w\+'
5+
let s:def_regex = '^\s*\%(class\|def\) \w\+'
6+
let s:decorator_regex = '^\s*@'
7+
let s:doc_begin_regex = '^\s*\%("""\|''''''\)'
8+
let s:doc_end_regex = '\%("""\|''''''\)\s*$'
9+
let s:doc_line_regex = '^\s*\("""\|''''''\).\+\1\s*$'
610

711

812
fun! pymode#folding#text() " {{{
913
let fs = v:foldstart
10-
while getline(fs) =~ '^\s*@'
14+
while getline(fs) =~ '\%(^\s*@\)\|\%(^\s*\%("""\|''''''\)\s*$\)'
1115
let fs = nextnonblank(fs + 1)
1216
endwhile
1317
let line = getline(fs)
@@ -21,6 +25,7 @@ fun! pymode#folding#text() " {{{
2125
let line = substitute(line, '\t', onetab, 'g')
2226

2327
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
28+
let line = substitute(line, '\%("""\|''''''\)', '', '')
2429
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
2530
return line . '' . repeat(" ",fillcharcount) . foldedlinecount . '' . ' '
2631
endfunction "}}}
@@ -30,21 +35,32 @@ fun! pymode#folding#expr(lnum) "{{{
3035

3136
let line = getline(a:lnum)
3237
let indent = indent(a:lnum)
38+
let prev_line = getline(a:lnum - 1)
39+
40+
if line =~ s:def_regex || line =~ s:decorator_regex
41+
if prev_line =~ s:decorator_regex
42+
return '='
43+
else
44+
return ">".(indent / &shiftwidth + 1)
45+
endif
46+
endif
3347

34-
if line =~ s:def_regex
35-
return ">".(indent / &shiftwidth + 1)
48+
if line =~ s:doc_begin_regex
49+
\ && line !~ s:doc_line_regex
50+
\ && prev_line =~ s:def_regex
51+
return ">".(indent / &shiftwidth + 1)
3652
endif
3753

38-
if line =~ '^\s*@'
39-
return -1
54+
if line =~ s:doc_end_regex
55+
\ && line !~ s:doc_line_regex
56+
return "<".(indent / &shiftwidth + 1)
4057
endif
4158

4259
if line =~ s:blank_regex
43-
let prev_line = getline(a:lnum - 1)
4460
if prev_line =~ s:blank_regex
4561
return -1
4662
else
47-
return foldlevel(prevnonblank(a:lnum))
63+
return '='
4864
endif
4965
endif
5066

autoload/pymode/lint.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ fun! pymode#lint#Check() "{{{
2020
endfunction " }}}
2121

2222

23-
fun! pymode#lint#Parse()
23+
fun! pymode#lint#Parse(bnum)
2424
" DESC: Parse result of code checking.
2525
"
2626
call setqflist(g:qf_list, 'r')
2727

2828
if g:pymode_lint_signs
29-
call pymode#PlaceSigns()
29+
call pymode#PlaceSigns(a:bnum)
3030
endif
3131

3232
if g:pymode_lint_cwindow

doc/pymode.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(__) (__) (__) (_) (_)(_____)(_)\_) (_/\/\_)(_____)(____/(____) ~
77

88

9-
Version: 0.6.14
9+
Version: 0.6.16
1010

1111
==============================================================================
1212
CONTENTS *Python-mode-contents*
@@ -29,7 +29,7 @@ Python-mode is a vim plugin that allows you to use the pylint, rope, and pydoc
2929
libraries in vim to provide features like python code bug checking,
3030
refactoring, and some other useful things.
3131

32-
This plugin allow you create python code in vim very easily. There is no need
32+
This plugin allows you to create python code in vim very easily. There is no need
3333
to install the pylint or rope libraries on your system.
3434

3535

@@ -122,9 +122,9 @@ To enable any of the options below you should put the given line in your
122122
2.2. Modeline ~
123123
*PythonModeModeline*
124124

125-
Feature like VIM modeline `:help modeline`. Allow changing pymode options for
126-
edited file. Pymode modeline should always be the last line in the file and
127-
look like:
125+
The VIM modeline `:help modeline` feature allows you to change pymode
126+
options for the current file. Pymode modeline should always be the
127+
last line in the vimrc file and look like:
128128

129129
>
130130
# pymode:lint_ignore=E0202:doc=0:lint_write=0
@@ -142,7 +142,7 @@ Set linters and mccabe complexity.
142142
# pymode:lint_checker=pip,mccabe:lint_mccabe_complexity=10
143143
<
144144

145-
This changes will work only in current buffer.
145+
These changes will work only in the current buffer.
146146

147147
------------------------------------------------------------------------------
148148
*'pymode'*
@@ -156,7 +156,7 @@ If this option is set to 0 then the whole plugin is disabled
156156
Values: List of strings
157157
Default: [].
158158

159-
This option set additional python import paths
159+
This option sets additional python import paths
160160

161161
------------------------------------------------------------------------------
162162
*'pymode_doc'*
@@ -169,20 +169,20 @@ If this option is set to 0 then the doc script is disabled.
169169
*'pymode_doc_key'*
170170
Default: 'K'.
171171

172-
Set key for show python documentation.
172+
Set the key to show the show python documentation.
173173

174174
------------------------------------------------------------------------------
175175
*'pymode_run'*
176176
Values: 0 or 1.
177177
Default: 1.
178178

179-
If this option is set to 0 then run script is disabled.
179+
If this option is set to 0 then the run script is disabled.
180180

181181
------------------------------------------------------------------------------
182182
*'pymode_run_key'*
183183
Default: '<leader>r'.
184184

185-
Set key for run python code.
185+
Set the key for running python code.
186186

187187
------------------------------------------------------------------------------
188188
*'pymode_lint'*
@@ -279,7 +279,7 @@ Values: 0 or 1.
279279
Default: 0.
280280

281281
If this option is set to 0 then pylint will switch on the quickfix window when
282-
it opens. Doesn't work when |'pymode_lint_jump'| enabled.
282+
it opens. Doesn't work when |'pymode_lint_jump'| is enabled.
283283

284284
------------------------------------------------------------------------------
285285
*'pymode_lint_minheight'*
@@ -349,7 +349,7 @@ not be used.
349349
Values: 0 or 1.
350350
Default: 1.
351351

352-
If this option is set to 1, pymode will enable python indentation support
352+
If this option is set to 1, pymode will enable python indentation support.
353353

354354
------------------------------------------------------------------------------
355355
*'pymode_folding'*
@@ -452,8 +452,8 @@ iM Operation with inner function or method.
452452
Python-mode doesn't work
453453
------------------------
454454

455-
Run ":call pymode#troubleshooting#Test()" and fix the warning or send me the
456-
output.
455+
Open any python file and run ":call pymode#troubleshooting#Test()",
456+
fix the warning or send me the output.
457457

458458

459459
Rope completion is very slow
@@ -463,8 +463,8 @@ To work, rope_ creates a service directory: `.ropeproject`. If
463463
|'pymode_rope_guess_project'| is set on (as it is by default) and
464464
`.ropeproject` is not found in the current dir, rope will scan for
465465
`.ropeproject` in every dir in the parent path. If rope finds `.ropeproject`
466-
in parent dirs, rope sets project for all child dir and the scan may be slow
467-
for many dirs and files.
466+
in parent dirs, rope sets projectis for all child dirs and the scan may be
467+
slow for many dirs and files.
468468

469469
Solutions:
470470

@@ -479,7 +479,7 @@ Solutions:
479479
Pylint check is very slow
480480
-------------------------
481481

482-
In some projects pylint_ may check slowly, because it also scan imported
482+
In some projects pylint_ may check slowly, because it also scans imported
483483
modules if possible. Try using pyflakes: see |'pymode_lint_checker'|.
484484

485485
You may set |exrc| and |secure| in your |vimrc| to auto-set custom settings

ftplugin/python/init-pymode.vim

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if exists('did_init_pymode_vim')
33
endif
44
let did_init_pymode_vim = 1
55

6-
let g:pymode_version = "0.6.14"
6+
let g:pymode_version = "0.6.16"
77

88
com! PymodeVersion echomsg "Current python-mode version: " . g:pymode_version
99

@@ -111,11 +111,12 @@ if !pymode#Default("g:pymode_lint", 1) || g:pymode_lint
111111
if (!pymode#Default("g:pymode_lint_signs", 1) || g:pymode_lint_signs) && has('signs')
112112

113113
" DESC: Signs definition
114-
sign define W text=WW texthl=Todo
115-
sign define C text=CC texthl=Comment
116-
sign define R text=RR texthl=Visual
117-
sign define E text=EE texthl=Error
118-
sign define I text=II texthl=Info
114+
sign define PymodeW text=WW texthl=Todo
115+
sign define PymodeC text=CC texthl=Comment
116+
sign define PymodeR text=RR texthl=Visual
117+
sign define PymodeE text=EE texthl=Error
118+
sign define PymodeI text=II texthl=Info
119+
sign define PymodeF text=FF texthl=Info
119120

120121
if !pymode#Default("g:pymode_lint_signs_always_visible", 0) || g:pymode_lint_signs_always_visible
121122
" Show the sign's ruller if asked for, even it there's no error to show
@@ -127,7 +128,7 @@ if !pymode#Default("g:pymode_lint", 1) || g:pymode_lint
127128

128129
" DESC: Set default pylint configuration
129130
if !filereadable(g:pymode_lint_config)
130-
let g:pymode_lint_config = expand("<sfile>:p:h:h") . "/pylint.ini"
131+
let g:pymode_lint_config = expand("<sfile>:p:h:h:h") . "/pylint.ini"
131132
endif
132133

133134
py from pymode import queue

pylibs/pylama/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" pylama -- Python code audit. "
22

3-
version_info = (0, 2, 3)
3+
version_info = (0, 3, 0)
44

55
__version__ = version = '.'.join(map(str, version_info))
66
__project__ = __name__

pylibs/pylama/hook.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import sys
2+
from os import path as op, chmod
3+
from subprocess import Popen, PIPE
4+
from .main import logger
5+
6+
7+
try:
8+
from configparser import ConfigParser # nolint
9+
except ImportError: # Python 2
10+
from ConfigParser import ConfigParser
11+
12+
13+
def run(command):
14+
p = Popen(command.split(), stdout=PIPE, stderr=PIPE)
15+
(stdout, stderr) = p.communicate()
16+
return (p.returncode, [line.strip() for line in stdout.splitlines()],
17+
[line.strip() for line in stderr.splitlines()])
18+
19+
20+
def git_hook():
21+
from .main import check_files
22+
_, files_modified, _ = run("git diff-index --cached --name-only HEAD")
23+
logger.setLevel('WARN')
24+
check_files([f for f in map(str, files_modified) if f.endswith('.py')])
25+
26+
27+
def hg_hook(ui, repo, **kwargs):
28+
from .main import check_files
29+
seen = set()
30+
paths = []
31+
for rev in range(repo[kwargs['node']], len(repo)):
32+
for file_ in repo[rev].files():
33+
file_ = op.join(repo.root, file_)
34+
if file_ in seen or not op.exists(file_):
35+
continue
36+
seen.add(file_)
37+
if file_.endswith('.py'):
38+
paths.append(file_)
39+
logger.setLevel('WARN')
40+
check_files(paths)
41+
42+
43+
def install_git(path):
44+
hook = op.join(path, 'pre-commit')
45+
with open(hook, 'w+') as fd:
46+
fd.write("""#!/usr/bin/env python
47+
import sys
48+
from pylama.hook import git_hook
49+
50+
if __name__ == '__main__':
51+
sys.exit(git_hook())
52+
""")
53+
chmod(hook, 484)
54+
return True
55+
56+
57+
def install_hg(path):
58+
hook = op.join(path, 'hgrc')
59+
if not op.isfile(hook):
60+
open(hook, 'w+').close()
61+
62+
c = ConfigParser()
63+
c.readfp(open(path, 'r'))
64+
if not c.has_section('hooks'):
65+
c.add_section('hooks')
66+
67+
if not c.has_option('hooks', 'commit'):
68+
c.set('hooks', 'commit', 'python:pylama.hooks.hg_hook')
69+
70+
if not c.has_option('hooks', 'qrefresh'):
71+
c.set('hooks', 'qrefresh', 'python:pylama.hooks.hg_hook')
72+
73+
c.write(open(path, 'w+'))
74+
return True
75+
76+
77+
def install_hook(path):
78+
git = op.join(path, '.git', 'hooks')
79+
hg = op.join(path, '.hg')
80+
if op.exists(git):
81+
install_git(git) and logger.warn('Git hook has been installed.') # nolint
82+
83+
elif op.exists(hg):
84+
install_hg(git) and logger.warn('Mercurial hook has been installed.') # nolint
85+
86+
else:
87+
logger.error('VCS has not found. Check your path.')
88+
sys.exit(1)

0 commit comments

Comments
 (0)