-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup_helper_docdist.py
71 lines (51 loc) · 2.23 KB
/
setup_helper_docdist.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
# -*- coding: utf-8 -*-
# Copyright (c) 2014, Sergio Callegari
# All rights reserved.
# This file is part of PyDSM.
# PyDSM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# PyDSM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with PyDSM. If not, see <http://www.gnu.org/licenses/>.
"""docdist
Implements a Distutils 'docdist' subcommand (create zipfile with html
documentation).
"""
from __future__ import print_function
import os
from distutils import dir_util
from distutils.cmd import Command
__all__ = ["docdist"]
class docdist(Command):
description = "Create zip file containing standalone html docs"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
cmd = self.get_finalized_command('build')
self.build_dir = os.path.join(cmd.build_base, 'docdist')
self.dist_dir = "dist"
self.format = "zip"
def run(self):
# call build sphinx to build docs
self.run_command("build_sphinx")
cmd = self.get_finalized_command("build_sphinx")
source_dir = cmd.builder_target_dir
# copy to directory with appropriate name
dist = self.distribution
arc_name = "%s-doc-html-%s" % (dist.get_name(), dist.get_version())
tmp_dir = os.path.join(self.build_dir, arc_name)
if os.path.exists(tmp_dir):
dir_util.remove_tree(tmp_dir, dry_run=self.dry_run)
self.copy_tree(source_dir, tmp_dir, preserve_symlinks=True)
dir_util.remove_tree(os.path.join(tmp_dir, '_sources'))
# make archive from dir
arc_base = os.path.join(self.dist_dir, arc_name)
self.arc_filename = self.make_archive(arc_base, self.format,
self.build_dir)
dir_util.remove_tree(tmp_dir, dry_run=self.dry_run)