-
Notifications
You must be signed in to change notification settings - Fork 4
/
pavement.py
166 lines (137 loc) · 4.18 KB
/
pavement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from builtins import range
# -*- coding: utf-8 -*-
#
# (c) 2016 Boundless, http://boundlessgeo.com
# This code is licensed under the GPL 2.0 license.
#
import os
import fnmatch
import zipfile
import shutil
from paver.easy import *
# this pulls in the sphinx target
from paver.doctools import html
options(
plugin = Bunch(
name = 'coretests',
source_dir = path('coretests'),
package_dir = path('.'),
tests = ['test', 'tests'],
excludes = [
'*.pyc',
".git"
]
),
sphinx = Bunch(
docroot = 'doc',
sourcedir = 'source',
builddir = 'build'
)
)
@task
def setup(options):
pass
@task
def install(options):
'''install plugin to qgis'''
plugin_name = options.plugin.name
src = path(__file__).dirname() / plugin_name
if os.name == 'nt':
dst = path('~/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins').expanduser() / plugin_name
else:
dst = path('~/.local/share/QGIS/QGIS3/profiles/default/python/plugins').expanduser() / plugin_name
src = src.abspath()
dst = dst.abspath()
if not hasattr(os, 'symlink'):
dst.rmtree()
src.copytree(dst)
elif not dst.exists():
src.symlink(dst)
@task
@cmdopts([
('tests', 't', 'Package tests with plugin'),
])
def package(options):
'''create package for plugin'''
package_file = options.plugin.package_dir / ('%s.zip' % options.plugin.name)
with zipfile.ZipFile(package_file, "w", zipfile.ZIP_DEFLATED) as zip:
make_zip(zip, options)
def make_zip(zip, options):
excludes = set(options.plugin.excludes)
src_dir = options.plugin.source_dir
exclude = lambda p: any([fnmatch.fnmatch(p, e) for e in excludes])
def filter_excludes(files):
if not files: return []
# to prevent descending into dirs, modify the list in place
for i in range(len(files) - 1, -1, -1):
f = files[i]
if exclude(f):
files.remove(f)
return files
for root, dirs, files in os.walk(src_dir):
for f in filter_excludes(files):
relpath = os.path.relpath(root, '.')
zip.write(path(root) / f, path(relpath) / f)
filter_excludes(dirs)
@task
def install_devtools():
"""Install development tools"""
try:
import pip
except:
error('FATAL: Unable to import pip, please install it first!')
sys.exit(1)
pip.main(['install', '-r', 'requirements-dev.txt'])
@task
@consume_args
def pep8(args):
"""Check code for PEP8 violations"""
try:
import pep8
except:
error('pep8 not found! Run "paver install_devtools".')
sys.exit(1)
# Errors to ignore
ignore = ['E203', 'E121', 'E122', 'E123', 'E124', 'E125', 'E126', 'E127',
'E128', 'E402']
styleguide = pep8.StyleGuide(ignore=ignore,
exclude=['*/extlibs/*', '*/ext-src/*'],
repeat=True, max_line_length=79,
parse_argv=args)
styleguide.input_dir(options.plugin.source_dir)
info('===== PEP8 SUMMARY =====')
styleguide.options.report.print_statistics()
@task
@consume_args
def autopep8(args):
"""Format code according to PEP8
"""
try:
import autopep8
except:
error('autopep8 not found! Run "paver install_devtools".')
sys.exit(1)
if any(x not in args for x in ['-i', '--in-place']):
args.append('-i')
args.append('--ignore=E261,E265,E402,E501')
args.insert(0, 'dummy')
cmd_args = autopep8.parse_args(args)
excludes = ('extlibs', 'ext-src')
for p in options.plugin.source_dir.walk():
if any(exclude in p for exclude in excludes):
continue
if p.fnmatch('*.py'):
autopep8.fix_file(p, options=cmd_args)
@task
@consume_args
def pylint(args):
"""Check code for errors and coding standard violations"""
try:
from pylint import lint
except:
error('pylint not found! Run "paver install_devtools".')
sys.exit(1)
if not 'rcfile' in args:
args.append('--rcfile=pylintrc')
args.append(options.plugin.source_dir)
lint.Run(args)