1
1
# -*- coding: utf-8 -*-
2
2
3
3
from __future__ import print_function
4
- from setuptools import setup , find_packages , Command
5
- from setuptools .command .sdist import sdist
6
- from setuptools .command .build_py import build_py
7
- from setuptools .command .egg_info import egg_info
8
- from subprocess import check_call
4
+ from setuptools import setup , find_packages
9
5
import os
10
6
import sys
11
- import platform
12
7
13
- here = os .path .dirname (os .path .abspath (__file__ ))
14
- node_root = os .path .join (here , 'js' )
15
- is_repo = os .path .exists (os .path .join (here , '.git' ))
8
+ from setupbase import (
9
+ create_cmdclass ,
10
+ install_npm ,
11
+ )
16
12
17
- npm_path = os .pathsep .join ([
18
- os .path .join (node_root , 'node_modules' , '.bin' ),
19
- os .environ .get ('PATH' , os .defpath ),
20
- ])
21
13
22
14
from distutils import log
23
15
log .set_verbosity (log .DEBUG )
26
18
27
19
LONG_DESCRIPTION = 'A Python/ThreeJS bridge utilizing the Jupyter widget infrastructure.'
28
20
29
- def js_prerelease (command , strict = False ):
30
- """decorator for building minified js/css prior to another command"""
31
- class DecoratedCommand (command ):
32
- def run (self ):
33
- jsdeps = self .distribution .get_command_obj ('jsdeps' )
34
- if not is_repo and all (os .path .exists (t ) for t in jsdeps .targets ):
35
- # sdist, nothing to do
36
- command .run (self )
37
- return
38
21
39
- try :
40
- self .distribution .run_command ('jsdeps' )
41
- except Exception as e :
42
- missing = [t for t in jsdeps .targets if not os .path .exists (t )]
43
- if strict or missing :
44
- log .warn ('rebuilding js and css failed' )
45
- if missing :
46
- log .error ('missing files: %s' % missing )
47
- raise e
48
- else :
49
- log .warn ('rebuilding js and css failed (not a problem)' )
50
- log .warn (str (e ))
51
- command .run (self )
52
- update_package_data (self .distribution )
53
- return DecoratedCommand
22
+ here = os .path .abspath (os .path .dirname (sys .argv [0 ]))
54
23
55
- def update_package_data (distribution ):
56
- """update package_data to catch changes during setup"""
57
- build_py = distribution .get_command_obj ('build_py' )
58
- # distribution.package_data = find_package_data()
59
- # re-init build_py options which load package_data
60
- build_py .finalize_options ()
61
-
62
-
63
- class NPM (Command ):
64
- description = 'install package.json dependencies using npm'
65
-
66
- user_options = []
67
-
68
- node_modules = os .path .join (node_root , 'node_modules' )
69
-
70
- targets = [
71
- os .path .join (here , 'pythreejs' , 'static' , 'extension.js' ),
72
- os .path .join (here , 'pythreejs' , 'static' , 'index.js' )
73
- ]
74
-
75
- def initialize_options (self ):
76
- pass
77
-
78
- def finalize_options (self ):
79
- pass
80
-
81
- def has_npm (self ):
82
- try :
83
- check_call (['npm' , '--version' ])
84
- return True
85
- except :
86
- return False
87
-
88
- def should_run_npm_install (self ):
89
- package_json = os .path .join (node_root , 'package.json' )
90
- node_modules_exists = os .path .exists (self .node_modules )
91
- return self .has_npm ()
92
-
93
- def run (self ):
94
- has_npm = self .has_npm ()
95
- if not has_npm :
96
- log .error ("`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo" )
97
-
98
- env = os .environ .copy ()
99
- env ['PATH' ] = npm_path
100
-
101
- if self .should_run_npm_install ():
102
- log .info ("Installing build dependencies with npm. This may take a while..." )
103
- check_call (['npm' , 'install' ], cwd = node_root , stdout = sys .stdout , stderr = sys .stderr )
104
- os .utime (self .node_modules , None )
105
-
106
- for t in self .targets :
107
- if not os .path .exists (t ):
108
- msg = 'Missing file: %s' % t
109
- if not has_npm :
110
- msg += '\n npm is required to build a development version of widgetsnbextension'
111
- raise ValueError (msg )
112
-
113
- # update package data in case this created new files
114
- update_package_data (self .distribution )
115
24
116
25
version_ns = {}
117
26
with open (os .path .join (here , 'pythreejs' , '_version.py' )) as f :
118
27
exec (f .read (), {}, version_ns )
119
28
29
+
30
+ cmdclass = create_cmdclass (['js' ])
31
+ cmdclass ['js' ] = install_npm (
32
+ path = os .path .join (here , 'js' ),
33
+ build_dir = os .path .join (here , 'pythreejs' , 'static' ),
34
+ source_dir = os .path .join (here , 'js' ),
35
+ )
36
+
120
37
setup_args = {
121
38
'name' : 'pythreejs' ,
122
39
'version' : version_ns ['__version__' ],
@@ -134,12 +51,7 @@ def run(self):
134
51
'install_requires' : ['ipywidgets>=7.0.0a9' , 'traittypes' ],
135
52
'packages' : find_packages (),
136
53
'zip_safe' : False ,
137
- 'cmdclass' : {
138
- 'build_py' : js_prerelease (build_py ),
139
- 'egg_info' : js_prerelease (egg_info ),
140
- 'sdist' : js_prerelease (sdist , strict = True ),
141
- 'jsdeps' : NPM ,
142
- },
54
+ 'cmdclass' : cmdclass ,
143
55
'author' : 'PyThreejs Development Team' ,
144
56
'author_email' :
'[email protected] ' ,
145
57
'url' : 'https://github.com/jovyan/pythreejs' ,
0 commit comments