forked from joblib/joblib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupegg.py
executable file
·96 lines (73 loc) · 3.08 KB
/
setupegg.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
#!/usr/bin/env python
"""Wrapper to run setup.py using setuptools."""
import zipfile
import os
import sys
from setuptools import Command
from sphinx_pypi_upload import UploadDoc
###############################################################################
# Code to copy the sphinx-generated html docs in the distribution.
DOC_BUILD_DIR = os.path.join('build', 'sphinx', 'html')
def relative_path(filename):
""" Return the relative path to the file, assuming the file is
in the DOC_BUILD_DIR directory.
"""
length = len(os.path.abspath(DOC_BUILD_DIR)) + 1
return os.path.abspath(filename)[length:]
class ZipHelp(Command):
description = "zip the help created by the build_sphinx, " + \
"and put it in the source distribution. "
user_options = [
('None', None, 'this command has no options'),
]
def run(self):
if not os.path.exists(DOC_BUILD_DIR):
raise OSError('Doc directory does not exist.')
target_file = os.path.join('doc', 'documentation.zip')
# ZIP_DEFLATED actually compresses the archive. However, there
# will be a RuntimeError if zlib is not installed, so we check
# for it. ZIP_STORED produces an uncompressed zip, but does not
# require zlib.
try:
zf = zipfile.ZipFile(target_file, 'w',
compression=zipfile.ZIP_DEFLATED)
except RuntimeError:
zf = zipfile.ZipFile(target_file, 'w',
compression=zipfile.ZIP_STORED)
for root, dirs, files in os.walk(DOC_BUILD_DIR):
relative = relative_path(root)
if not relative.startswith('.doctrees'):
for f in files:
zf.write(os.path.join(root, f),
os.path.join(relative, f))
zf.close()
def initialize_options(self):
pass
def finalize_options(self):
pass
class GenerateHelp(Command):
description = " Generate the autosummary files "
user_options = [
('None', None, 'this command has no options'),
]
def run(self):
os.system( \
"%s doc/sphinxext/autosummary_generate.py " % sys.executable + \
"-o doc/generated/ doc/*.rst")
def initialize_options(self):
pass
def finalize_options(self):
pass
###############################################################################
# Call the setup.py script, injecting the setuptools-specific arguments.
extra_setuptools_args = dict(
tests_require=['nose', 'coverage'],
test_suite='nose.collector',
cmdclass={'zip_help': ZipHelp,
'generate_help': GenerateHelp,
'upload_help': UploadDoc},
zip_safe=False,
)
if __name__ == '__main__':
execfile('setup.py', dict(__name__='__main__',
extra_setuptools_args=extra_setuptools_args))