Skip to content

Commit 7c35d33

Browse files
committed
sty: cleanup tools folder
1 parent 53f07ad commit 7c35d33

File tree

10 files changed

+194
-152
lines changed

10 files changed

+194
-152
lines changed

tools/apigen.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ class ApiDocWriter(object):
3636
# only separating first two levels
3737
rst_section_levels = ['*', '=', '-', '~', '^']
3838

39-
def __init__(self,
40-
package_name,
41-
rst_extension='.rst',
42-
package_skip_patterns=None,
43-
module_skip_patterns=None,
44-
):
39+
def __init__(
40+
self,
41+
package_name,
42+
rst_extension='.rst',
43+
package_skip_patterns=None,
44+
module_skip_patterns=None,
45+
):
4546
''' Initialize package for parsing
4647
4748
Parameters
@@ -298,8 +299,7 @@ def _survives_exclude(self, matchstr, match_type):
298299
elif match_type == 'package':
299300
patterns = self.package_skip_patterns
300301
else:
301-
raise ValueError('Cannot interpret match type "%s"'
302-
% match_type)
302+
raise ValueError('Cannot interpret match type "%s"' % match_type)
303303
# Match to URI without package name
304304
L = len(self.package_name)
305305
if matchstr[:L] == self.package_name:
@@ -343,21 +343,20 @@ def discover_modules(self):
343343
# raw directory parsing
344344
for dirpath, dirnames, filenames in os.walk(self.root_path):
345345
# Check directory names for packages
346-
root_uri = self._path2uri(os.path.join(self.root_path,
347-
dirpath))
346+
root_uri = self._path2uri(os.path.join(self.root_path, dirpath))
348347
for dirname in dirnames[:]: # copy list - we modify inplace
349348
package_uri = '.'.join((root_uri, dirname))
350-
if (self._uri2path(package_uri) and
351-
self._survives_exclude(package_uri, 'package')):
349+
if (self._uri2path(package_uri)
350+
and self._survives_exclude(package_uri, 'package')):
352351
modules.append(package_uri)
353352
else:
354353
dirnames.remove(dirname)
355354
# Check filenames for modules
356355
for filename in filenames:
357356
module_name = filename[:-3]
358357
module_uri = '.'.join((root_uri, module_name))
359-
if (self._uri2path(module_uri) and
360-
self._survives_exclude(module_uri, 'module')):
358+
if (self._uri2path(module_uri)
359+
and self._survives_exclude(module_uri, 'module')):
361360
modules.append(module_uri)
362361
# print sorted(modules) #dbg
363362
return sorted(modules)
@@ -370,8 +369,7 @@ def write_modules_api(self, modules, outdir):
370369
if not api_str:
371370
continue
372371
# write out to file
373-
outfile = os.path.join(outdir,
374-
m + self.rst_extension)
372+
outfile = os.path.join(outdir, m + self.rst_extension)
375373
fileobj = open(outfile, 'wt')
376374
fileobj.write(api_str)
377375
fileobj.close()

tools/build_interface_docs.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
outdir = os.path.join('interfaces', 'generated')
1919
docwriter = InterfaceHelpWriter(package)
2020
# Packages that should not be included in generated API docs.
21-
docwriter.package_skip_patterns += ['\.external$',
22-
'\.fixes$',
23-
'\.utils$',
24-
'\.pipeline',
25-
'\.testing',
26-
'\.caching',
27-
'\.scripts',
28-
]
21+
docwriter.package_skip_patterns += [
22+
'\.external$',
23+
'\.fixes$',
24+
'\.utils$',
25+
'\.pipeline',
26+
'\.testing',
27+
'\.caching',
28+
'\.scripts',
29+
]
2930
# Modules that should not be included in generated API docs.
3031
docwriter.module_skip_patterns += [
3132
'\.version$',
@@ -41,20 +42,21 @@
4142
'\.testing',
4243
'\.scripts',
4344
]
44-
docwriter.class_skip_patterns += ['AFNICommand',
45-
'ANTS',
46-
'FSLCommand',
47-
'FS',
48-
'Info',
49-
'^SPM',
50-
'Tester',
51-
'Spec$',
52-
'Numpy'
53-
# NipypeTester raises an
54-
# exception when instantiated in
55-
# InterfaceHelpWriter.generate_api_doc
56-
'NipypeTester',
57-
]
45+
docwriter.class_skip_patterns += [
46+
'AFNICommand',
47+
'ANTS',
48+
'FSLCommand',
49+
'FS',
50+
'Info',
51+
'^SPM',
52+
'Tester',
53+
'Spec$',
54+
'Numpy'
55+
# NipypeTester raises an
56+
# exception when instantiated in
57+
# InterfaceHelpWriter.generate_api_doc
58+
'NipypeTester',
59+
]
5860
docwriter.write_api_docs(outdir)
5961
docwriter.write_index(outdir, 'gen', relative_to='interfaces')
6062
print('%d files written' % len(docwriter.written_modules))

tools/build_modref_templates.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
outdir = os.path.join('api', 'generated')
2020
docwriter = ApiDocWriter(package)
2121
# Packages that should not be included in generated API docs.
22-
docwriter.package_skip_patterns += ['\.external$',
23-
'\.utils$',
24-
'\.interfaces\.',
25-
'\.workflows$',
26-
'\.pipeline\.plugins$',
27-
'\.testing$',
28-
'\.fixes$',
29-
'\.algorithms$',
30-
'\.scripts$',
31-
]
22+
docwriter.package_skip_patterns += [
23+
'\.external$',
24+
'\.utils$',
25+
'\.interfaces\.',
26+
'\.workflows$',
27+
'\.pipeline\.plugins$',
28+
'\.testing$',
29+
'\.fixes$',
30+
'\.algorithms$',
31+
'\.scripts$',
32+
]
3233
# Modules that should not be included in generated API docs.
3334
docwriter.module_skip_patterns += [
3435
'\.version$',

tools/ex2rst

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# copyright and license terms.
1111
#
1212
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
13-
1413
"""Helper to automagically generate ReST versions of examples"""
1514
from __future__ import (print_function, division, unicode_literals,
1615
absolute_import)
@@ -38,18 +37,20 @@ def auto_image(line):
3837

3938
# Match means it's an image spec, we rewrite it with extra tags
4039
ini_space = m.group(1)
41-
lines = [line,
42-
ini_space + ' :width: 500\n',
43-
#ini_space + ' :height: 350\n'
44-
]
40+
lines = [
41+
line,
42+
ini_space + ' :width: 500\n',
43+
#ini_space + ' :height: 350\n'
44+
]
4545
fspec = m.group(2)
4646
if fspec.endswith('.*'):
4747
fspec = fspec.replace('.*', '.png')
4848
fspec = fspec.replace('fig/', '../_images/')
49-
lines.append(ini_space + (' :target: %s\n' % fspec) )
49+
lines.append(ini_space + (' :target: %s\n' % fspec))
5050
lines.append('\n')
5151
return ''.join(lines)
5252

53+
5354
def exfile2rst(filename):
5455
"""Open a Python script and convert it into an ReST string.
5556
"""
@@ -114,7 +115,7 @@ def exfile2rst(filename):
114115
indocs = True
115116
code2doc = True
116117
# rescue what is left on the line
117-
proc_line = cleanline[3:] # strip """
118+
proc_line = cleanline[3:] # strip """
118119
else:
119120
# we are already in the docs
120121
# handle doc end
@@ -191,14 +192,13 @@ def exfile2rstfile(filename, opts):
191192
This same script is also included in the %s source distribution under the
192193
:file:`examples` directory.
193194
194-
""" % (filename, opts.project)
195+
""" % (filename, opts.project)
195196

196197
dfile.write(msg)
197198

198199
dfile.close()
199200

200201

201-
202202
def main():
203203
parser = OptionParser( \
204204
usage="%prog [options] <filename|directory> [...]", \
@@ -224,30 +224,53 @@ first (module-level) docstring instead.
224224
""" ) #'
225225

226226
# define options
227-
parser.add_option('--verbose', action='store_true', dest='verbose',
228-
default=False, help='print status messages')
229-
parser.add_option('-x', '--exclude', action='append', dest='excluded',
230-
help="""\
227+
parser.add_option(
228+
'--verbose',
229+
action='store_true',
230+
dest='verbose',
231+
default=False,
232+
help='print status messages')
233+
parser.add_option(
234+
'-x',
235+
'--exclude',
236+
action='append',
237+
dest='excluded',
238+
help="""\
231239
Use this option to exclude single files from the to be parsed files. This is
232240
especially useful to exclude files when parsing complete directories. This
233241
option can be specified multiple times.
234242
""")
235-
parser.add_option('-o', '--outdir', action='store', dest='outdir',
236-
type='string', default=None, help="""\
243+
parser.add_option(
244+
'-o',
245+
'--outdir',
246+
action='store',
247+
dest='outdir',
248+
type='string',
249+
default=None,
250+
help="""\
237251
Target directory to write the ReST output to. This is a required option.
238252
""")
239-
parser.add_option('--no-sourceref', action='store_false', default=True,
240-
dest='sourceref', help="""\
253+
parser.add_option(
254+
'--no-sourceref',
255+
action='store_false',
256+
default=True,
257+
dest='sourceref',
258+
help="""\
241259
If specified, the source reference section will be suppressed.
242260
""")
243-
parser.add_option('--project', type='string', action='store', default='',
244-
dest='project', help="""\
261+
parser.add_option(
262+
'--project',
263+
type='string',
264+
action='store',
265+
default='',
266+
dest='project',
267+
help="""\
245268
Name of the project that contains the examples. This name is used in the
246269
'seealso' source references. Default: ''
247270
""")
248271

249272
# parse options
250-
(opts, args) = parser.parse_args() # read sys.argv[1:] by default
273+
(opts, args) = parser.parse_args() # read sys.argv[1:] by default
251274

252275
# check for required options
253276
if opts.outdir is None:

tools/github.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ def get_local_branch():
2828
"""Determine current branch
2929
"""
3030
if is_git_repo():
31-
o, _ = Popen('git branch | grep "\* "', shell=True, stdout=PIPE,
32-
cwd=os.path.dirname(nipype.__file__)).communicate()
31+
o, _ = Popen(
32+
'git branch | grep "\* "',
33+
shell=True,
34+
stdout=PIPE,
35+
cwd=os.path.dirname(nipype.__file__)).communicate()
3336
return o.strip()[2:]
3437
else:
3538
return None
@@ -51,8 +54,12 @@ def create_hash_map():
5154
import pwd
5255
login_name = pwd.getpwuid(os.geteuid())[0]
5356
conn = http.client.HTTPSConnection("api.github.com")
54-
conn.request("GET", "/repos/nipy/nipype",
55-
headers={'Authorization': 'Basic %s' % base64(login_name)})
57+
conn.request(
58+
"GET",
59+
"/repos/nipy/nipype",
60+
headers={
61+
'Authorization': 'Basic %s' % base64(login_name)
62+
})
5663
try:
5764
conn.request("GET", "/repos/nipy/nipype/git/trees/master?recursive=1")
5865
except:

0 commit comments

Comments
 (0)