forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
96 lines (78 loc) · 3 KB
/
setup.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
# coding: utf-8
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json
import os
import os.path as osp
import subprocess
import sys
from os.path import join as pjoin
from setuptools import setup
NAME = "jupyterlab"
HERE = osp.dirname(osp.abspath(__file__))
ensured_targets = [
"static/package.json",
"schemas/@jupyterlab/shortcuts-extension/shortcuts.json",
"themes/@jupyterlab/theme-light-extension/index.css",
]
ensured_targets = [osp.join(HERE, NAME, t) for t in ensured_targets]
data_files_spec = [
("share/jupyter/lab/static", f"{NAME}/static", "**"),
("share/jupyter/lab/schemas", f"{NAME}/schemas", "**"),
("share/jupyter/lab/themes", f"{NAME}/themes", "**"),
(
"etc/jupyter/jupyter_server_config.d",
"jupyter-config/jupyter_server_config.d",
f"{NAME}.json",
),
(
"etc/jupyter/jupyter_notebook_config.d",
"jupyter-config/jupyter_notebook_config.d",
f"{NAME}.json",
),
]
def post_dist():
from jupyter_packaging import get_version
from packaging.version import Version
target = pjoin(HERE, NAME, "static", "package.json")
with open(target) as fid:
version = json.load(fid)["jupyterlab"]["version"]
if Version(version) != Version(get_version(f"{NAME}/_version.py")):
raise ValueError("Version mismatch, please run `npm run prepare:python-release`")
try:
from jupyter_packaging import get_data_files, npm_builder, wrap_installers
npm = ["node", pjoin(HERE, NAME, "staging", "yarn.js")]
# In develop mode, just run yarn, unless this is an sdist.
if os.path.exists(os.path.join(HERE, "buildutils")):
builder = npm_builder(build_cmd=None, npm=npm, force=True)
def post_develop(*args, **kwargs):
builder(*args, **kwargs)
try:
import pre_commit
except ImportError:
print(
"Please install pre-commit and the associated hooks; using the following commands:"
)
print("pip install pre-commit")
print("python -m pre_commit install")
print("python -m pre_commit install --hook-type pre-push")
else:
try:
subprocess.run([sys.executable, "-m", "pre_commit", "install"])
subprocess.run(
[sys.executable, "-m", "pre_commit", "install", "--hook-type", "pre-push"]
)
except Exception:
# no-op
pass
cmdclass = wrap_installers(
post_develop=post_develop, post_dist=post_dist, ensured_targets=ensured_targets
)
else:
cmdclass = wrap_installers(post_dist=post_dist, ensured_targets=ensured_targets)
setup_args = dict(cmdclass=cmdclass, data_files=get_data_files(data_files_spec))
except ImportError:
setup_args = {}
if __name__ == "__main__":
setup(**setup_args)