-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
150 lines (132 loc) · 5.8 KB
/
fabfile.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
"""
Fabric's own fabfile.
"""
from __future__ import with_statement
import inspect
from fabric.api import *
from fabric.contrib.project import rsync_project
import fabric.version
from fabric.main import internals # For doc introspection stuff
import os.path
def test():
"""
Run all unit tests
"""
# Need show_stderr=True because the interesting output of nosetests is
# actually sent to stderr, not stdout.
print(local('nosetests -sv', capture=False))
def update_doc_signatures():
"""
Update API autodocs with correct signatures for wrapped functions.
"""
for name, d in internals.iteritems():
item = d['callable']
module_name = d['module_name']
if hasattr(item, 'wrapped'):
wrapped = item.wrapped
if callable(wrapped): # Just in case...
args = inspect.formatargspec(*inspect.getargspec(wrapped))
name = wrapped.__name__
funcspec = " .. autofunction:: " + name
argspec = funcspec + args + '\n'
# Only update docs that actually exist
path = 'docs/api/%s.rst' % module_name
if os.path.exists(path):
# Read in lines
with open(path) as fd:
lines = fd.readlines()
# Update argument specification if it's outdated
if argspec not in lines:
# If previous line containing name + ( exists, nuke it
previous_index = None
for i, line in enumerate(lines):
if (funcspec + '(') in line:
del lines[i]
previous_index = i
break
# Regardless, append ours now that we're sure any old
# version is gone.
# Replace pre-existing line if possible
if previous_index is not None:
lines.insert(previous_index, argspec)
# Otherwise, just append to the end
else:
lines.append(argspec)
# Ensure item is excluded from being automatically found,
# otherwise it will show up twice.
# First, see if an exclude-members line exists (and also
# look for the :members: line, which must exist)
exclude_index = None
members_index = None
exclude_prefix = " :exclude-members: "
for i, line in enumerate(lines):
if line.startswith(exclude_prefix):
exclude_index = i
if line.startswith(" :members:"):
members_index = i
# Sanity check
if members_index is None:
abort("%s lacks a members line, something's fishy!" % path)
# No line found: make one after the members line
if exclude_index is None:
exclude = exclude_prefix + name + '\n'
lines.insert(members_index + 1, exclude)
# Also need to make sure a blank line is between these
# args and the body, else Sphinx blows up.
lines.insert(members_index + 2, '\n')
# Line found: append if not already in line
elif name not in lines[exclude_index]:
line = lines[exclude_index]
line = line.rstrip()
line += u", %s\n" % name
lines[exclude_index] = line
# Now that we've tweaked the lines, write back to file.
with open(path, 'w') as fd:
fd.writelines(lines)
def build_docs():
"""
Generate the Sphinx documentation.
"""
print(local('cd docs && make clean html', capture=False))
update_doc_signatures()
@hosts('jforcier@fabfile.org')
def push_docs():
"""
Build and push the Sphinx docs to docs.fabfile.org
"""
build_docs()
rsync_project('/var/www/docs.fabfile/', 'docs/_build/html/', delete=True)
def tag():
"""
Tag a new release of the software
"""
with warnings_only():
# Get current version string
version = fabric.version.get_version()
# Does that tag already exist?
exists = local("git tag | grep %s" % version)
if exists:
# If no work has been done since, what's the point?
if not local("git log %s.." % version):
abort("No work done since last tag!")
# If work *has* been done since, we need to make a new tag. To the
# editor for version update!
raw_input("Work has been done since last tag, version update is needed. Hit Enter to load version info in your editor: ")
local("$EDITOR fabric/version.py", capture=False)
# Reload version module to get new version
reload(fabric.version)
# If the tag doesn't exist, the user has already updated version info
# and we can just move on.
else:
print("Version has already been updated, no need to edit...")
# Get version strings
verbose_version = fabric.version.get_version(verbose=True)
short_version = fabric.version.get_version()
# Commit the version update
local("git add fabric/version.py")
local("git commit -m \"Cut %s\"" % verbose_version)
# And tag it
local("git tag -m \"Fabric %s\" %s" % (
verbose_version,
short_version
))