forked from sunpy/sunpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
132 lines (112 loc) · 3.5 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
"""
SunPy: Python for Solar Physics
The SunPy project is an effort to create an open-source software library for
solar physics using the Python programming language.
"""
#pylint: disable=W0404,W0621
import os
import imp
import shutil
from paver.easy import *
from paver.setuputils import setup
# This is not pretty, but necessary
install = imp.load_source(
'setup', os.path.join(os.path.dirname(__file__), 'setup.py')).install
#
# Options
#
options(
deploy = Bunch(
htmldir = path(os.path.join('doc', 'html')),
host = 'sipwork.org',
hostpath = 'www/sunpy/doc'
),
sphinx = Bunch(docroot='doc/source', builddir="_build"),
upload_docs = Bunch(upload_dir=os.path.join('doc', 'html')),
pylint = Bunch(quiet=False)
)
#
# Packaging
#
install(setup)
@task
@needs('prepare_docs', 'setuptools.command.sdist')
def sdist():
"""Generated HTML docs and builds a tarball."""
shutil.rmtree(os.path.join('doc', 'html'))
@task
@needs('sdist', 'setuptools.command.upload')
def upload():
"""Generated HTML docs and builds a tarball."""
shutil.rmtree(os.path.join('doc', 'html'))
@task
@needs('prepare_docs', 'setuptools.command.bdist_wininst')
def bdist():
"""Generated HTML docs and builds a windows binary."""
shutil.rmtree(os.path.join('doc', 'html'))
#
# Documentation
#
@task
@needs('paver.doctools.html')
def prepare_docs():
"""Prepares the SunPy HTML documentation for packaging"""
sourcedir = os.path.join('doc', 'source', '_build', 'html')
destdir = os.path.join('doc', 'html')
if os.path.exists(destdir):
shutil.rmtree(destdir)
shutil.move(sourcedir, destdir)
@task
@needs('prepare_docs', 'upload_docs')
@cmdopts([('username=', 'u', 'Username')])
def deploy(options):
"""Update the docs on sunpy.org"""
if "username" not in options:
options.username = raw_input("Username: ")
sh("rsync -avz --delete -e ssh %s/ %s@%s:%s/" % (options.htmldir,
options.username, options.host, options.hostpath))
#
# PyLint
#
@task
@cmdopts([('quiet', 'q', 'Run PyLint in quiet mode')])
def pylint(options):
"""Checks the code using PyLint"""
from pylint import lint
rcfile = os.path.join('tools', 'pylint', 'pylintrc')
arguments = ['--rcfile=%s' % rcfile]
if options.quiet:
arguments.extend(["-rn"])
arguments.extend(["sunpy"])
lint.Run(arguments)
#
# Cleanup
#
@task
@needs('paver.doctools.doc_clean')
def clean():
"""Cleans up build files"""
from glob import glob
dirs = ([os.path.join('doc', 'html'),
os.path.join('doc', 'source', '_build'), 'build', 'dist',
'sunpy.egg-info'] +
glob(os.path.join('doc', 'source', 'reference', 'generated')) +
glob(os.path.join('doc', 'source', 'reference', '*', 'generated')))
for dir_ in dirs:
if os.path.exists(dir_):
shutil.rmtree(dir_)
for file_ in glob('distribute-*') + ['MANIFEST']:
if os.path.exists(file_):
os.remove(file_)
def clean_cache(directory):
"""Remove .pyc files and __pycache__ directories"""
for x in os.listdir(directory):
filepath = os.path.join(directory, x)
if os.path.isfile(filepath) and filepath.endswith('.pyc'):
os.remove(filepath)
elif os.path.isdir(filepath):
if filepath.endswith("__pycache__"):
shutil.rmtree(filepath)
else:
clean_cache(filepath)
clean_cache('.')