forked from eyurtsev/FlowCytometryTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
130 lines (102 loc) · 3.35 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
import base64
import os
import json
import urllib2
from contextlib import contextmanager
from fabric.api import local, lcd, abort, settings
from fabric.decorators import task
from FlowCytometryTools import __version__
DL_DIR = "doc/source/_static/downloads"
BUILD_DIRS = (
"dist",
"doc/build",
"doc/source/API",
"build",
"FlowCytometryTools.egg-info",
)
SDIST_RST_FILES = (
"README.rst",
)
SDIST_TXT_FILES = [os.path.splitext(x)[0] + ".txt" for x in SDIST_RST_FILES]
BASE_PATH = os.path.abspath(os.path.dirname(__file__))
###############################################################################
# Misc.
###############################################################################
@task
def clean():
"""Clean build files."""
with lcd(BASE_PATH):
for build_dir in list(BUILD_DIRS):
local("rm -rf %s" % build_dir)
@task
def html():
"""Make html files."""
with lcd(os.path.join(BASE_PATH, 'doc')):
local("make html")
local("touch build/html/.nojekyll")
@task
def upload_doc():
with lcd(BASE_PATH):
local('git branch -D gh-pages')
local('git checkout -b gh-pages')
local('git add -f doc/build/html')
local('git commit -m "version {}"'.format(__version__))
local('git push origin `git subtree split --prefix doc/build/html`:gh-pages --force')
@task
def serve(port="8000"):
"""
Serve website from localhost.
@param port Port to run server on.
"""
with lcd(BASE_PATH):
with lcd("doc/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(server='pypitest'):
"""Register and prep user for PyPi upload.
.. note:: May need to weak ~/.pypirc file per issue:
http://stackoverflow.com/questions/1569315
"""
base_command = 'python setup.py register'
if server == 'pypitest':
command = base_command + ' -r https://testpypi.python.org/pypi'
else:
command = base_command
_execute_setup_command(command)
@task
def upload_to_pypi():
_execute_setup_command('python setup.py sdist upload')
@task
def upload_to_test_pypi():
_execute_setup_command('python setup.py sdist upload -r https://testpypi.python.org/pypi')
@task
def install_from_pypi():
_execute_setup_command('pip install FlowCytometryTools')
@task
def install_from_test_pypi():
_execute_setup_command('pip install -i https://testpypi.python.org/pypi FlowCytometryTools')
def _execute_setup_command(command):
with lcd(BASE_PATH):
with _dist_wrapper():
local(command, capture=False)