forked from ryan-roemer/sphinx-bootstrap-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
140 lines (104 loc) · 3.31 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
"""Fabric file."""
import base64
import os
import json
import urllib2
from contextlib import contextmanager
from fabric.api import local, lcd, abort
from fabric.decorators import task
from sphinx_bootstrap_theme import __version__
DL_DIR = "demo/source/_static/downloads"
BUILD_DIRS = (
"dist",
"build",
"demo/build",
"sphinx_bootstrap_theme.egg-info",
)
SDIST_RST_FILES = (
"README.rst",
"HISTORY.rst",
)
SDIST_TXT_FILES = [os.path.splitext(x)[0] + ".txt" for x in SDIST_RST_FILES]
###############################################################################
# Misc.
###############################################################################
@task
def clean():
"""Clean build files."""
for build_dir in list(BUILD_DIRS):
local("rm -rf %s" % build_dir)
@task
def demo():
"""Build demo files."""
with lcd("demo"):
local("make html")
@task
def demo_server(port="8000"):
"""Serve demo from localhost.
@param port Port to run server on.
"""
with lcd("demo/build/html"):
local("python -m SimpleHTTPServer %s" % port)
###############################################################################
# PyPI
###############################################################################
@contextmanager
def _dist_wrapper():
"""Add temporary distribution build files (and then clean up)."""
try:
# Copy select *.rst files to *.txt for build.
for rst_file, txt_file in zip(SDIST_RST_FILES, SDIST_TXT_FILES):
local("cp %s %s" % (rst_file, txt_file))
# Perform action.
yield
finally:
# Clean up temp *.txt files.
for rst_file in SDIST_TXT_FILES:
local("rm -f %s" % rst_file, capture=False)
@task
def sdist():
"""Package into distribution."""
with _dist_wrapper():
local("python setup.py sdist", capture=False)
@task
def pypi_register():
"""Register and prep user for PyPi upload.
.. note:: May need to weak ~/.pypirc file per issue:
http://stackoverflow.com/questions/1569315
"""
with _dist_wrapper():
local("python setup.py register", capture=False)
@task
def pypi_upload():
"""Upload package."""
with _dist_wrapper():
local("python setup.py sdist upload", capture=False)
###############################################################################
# Downloads
###############################################################################
def get_rev(tag=True):
"""Get build revision.
@param tag Use git tag instead of hash?
"""
rev_cmd = "git describe --always --tag" if tag in (True, "True") else \
"git rev-parse HEAD"
return local(rev_cmd, capture=True).strip()
@task
def zip_bundle(tag=True):
"""Create zip file upload bundles.
@param tag Use git tag instead of hash?
"""
#rev = get_rev(tag)
rev = __version__
print("Cleaning old build files.")
clean()
local("mkdir -p build")
print("Bundling new files.")
with lcd("sphinx_bootstrap_theme/bootstrap"):
local("zip -r ../../build/bootstrap.zip .")
dest = os.path.abspath(os.path.join(DL_DIR, rev))
with lcd("build"):
local("mkdir -p %s" % dest)
local("cp bootstrap.zip %s" % dest)
print("Verifying contents.")
local("unzip -l bootstrap.zip")