-
Notifications
You must be signed in to change notification settings - Fork 568
Expand file tree
/
Copy pathsetup.py
More file actions
72 lines (57 loc) · 1.83 KB
/
setup.py
File metadata and controls
72 lines (57 loc) · 1.83 KB
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
# -----------------------------------------------------------------------------
# Copyright (C) 2013 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# -----------------------------------------------------------------------------
import os
import shlex
import sys
from subprocess import check_call
from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
def sh(cmd):
"""Run a command, echoing what command is to be run"""
print("Running command %s" % " ".join(map(shlex.quote, cmd)), file=sys.stderr)
check_call(cmd)
def preflight():
print("Building LESS", file=sys.stderr)
sh(["invoke", "git-info"])
sh(["npm", "install"])
sh(["invoke", "bower"])
sh(["invoke", "less"])
def invoke_first(cmd):
class InvokeFirst(cmd):
def run(self):
preflight()
return cmd.run(self)
return InvokeFirst
def walk_subpkg(name):
data_files = []
package_dir = "nbviewer"
for parent, dirs, files in os.walk(os.path.join(package_dir, name)):
sub_dir = os.sep.join(
parent.split(os.sep)[1:]
) # remove package_dir from the path
for f in files:
data_files.append(os.path.join(sub_dir, f))
return data_files
pkg_data = {
"nbviewer": (
["frontpage.json"]
+ walk_subpkg("static")
+ walk_subpkg("templates")
+ walk_subpkg("providers")
)
}
cmdclass = {}
# run invoke prior to develop/sdist
cmdclass["develop"] = invoke_first(develop)
cmdclass["build_py"] = invoke_first(build_py)
cmdclass["sdist"] = invoke_first(sdist)
setup(
package_data=pkg_data,
cmdclass=cmdclass,
)