Skip to content

Commit 4a5f99c

Browse files
authored
Merge pull request #83 from vidartf/setupbase
Use setupbase from jupyter-packaging
2 parents 412f533 + e2a7509 commit 4a5f99c

File tree

4 files changed

+424
-104
lines changed

4 files changed

+424
-104
lines changed

LICENSE

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,41 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
2525
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2626
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2727
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
-------------------------------------------------------------------------------
30+
31+
The setupbase.py file is from the jupyter-packaging project:
32+
https://github.com/jupyter/jupyter-packaging/blob/0bb5d34eee0da3d2b53760ab1371dc0ee9af9b8d/jupyter_packaging/setupbase.py
33+
34+
The license is (from https://github.com/jupyter/jupyter-packaging/blob/0bb5d34eee0da3d2b53760ab1371dc0ee9af9b8d/LICENSE):
35+
36+
BSD 3-Clause License
37+
38+
Copyright (c) 2017, Project Jupyter
39+
All rights reserved.
40+
41+
Redistribution and use in source and binary forms, with or without
42+
modification, are permitted provided that the following conditions are met:
43+
44+
* Redistributions of source code must retain the above copyright notice, this
45+
list of conditions and the following disclaimer.
46+
47+
* Redistributions in binary form must reproduce the above copyright notice,
48+
this list of conditions and the following disclaimer in the documentation
49+
and/or other materials provided with the distribution.
50+
51+
* Neither the name of the copyright holder nor the names of its
52+
contributors may be used to endorse or promote products derived from
53+
this software without specific prior written permission.
54+
55+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
56+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
58+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
59+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
61+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
62+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
63+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65+

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "https://github.com/jovyan/pythreejs.git"
1111
},
1212
"scripts": {
13-
"prepublish": "webpack",
13+
"build": "webpack",
1414
"test": "echo \"Error: no test specified\" && exit 1"
1515
},
1616
"devDependencies": {

setup.py

Lines changed: 15 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
# -*- coding: utf-8 -*-
22

33
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
95
import os
106
import sys
11-
import platform
127

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+
)
1612

17-
npm_path = os.pathsep.join([
18-
os.path.join(node_root, 'node_modules', '.bin'),
19-
os.environ.get('PATH', os.defpath),
20-
])
2113

2214
from distutils import log
2315
log.set_verbosity(log.DEBUG)
@@ -26,97 +18,22 @@
2618

2719
LONG_DESCRIPTION = 'A Python/ThreeJS bridge utilizing the Jupyter widget infrastructure.'
2820

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
3821

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]))
5423

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 += '\nnpm 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)
11524

11625
version_ns = {}
11726
with open(os.path.join(here, 'pythreejs', '_version.py')) as f:
11827
exec(f.read(), {}, version_ns)
11928

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+
12037
setup_args = {
12138
'name': 'pythreejs',
12239
'version': version_ns['__version__'],
@@ -134,12 +51,7 @@ def run(self):
13451
'install_requires': ['ipywidgets>=7.0.0a9', 'traittypes'],
13552
'packages': find_packages(),
13653
'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,
14355
'author': 'PyThreejs Development Team',
14456
'author_email': '[email protected]',
14557
'url': 'https://github.com/jovyan/pythreejs',

0 commit comments

Comments
 (0)