33"""
44import os
55import re
6+ import subprocess
67import setuptools
8+ import setuptools .command .build_py
9+ import setuptools .command .develop
10+ import setuptools .command .install
711
812
913NAME = "forest"
@@ -27,11 +31,57 @@ def load(fname):
2731 return result
2832
2933
34+ def build_js (command_subclass ):
35+ """Decorator to call npm install and npm run build"""
36+ subclass_run = command_subclass .run
37+ def run (self ):
38+ self .run_command ("build_js" )
39+ subclass_run (self )
40+ command_subclass .run = run
41+ return command_subclass
42+
43+
44+ @build_js
45+ class InstallCommand (setuptools .command .install .install ):
46+ """Python and JS code"""
47+
48+
49+ @build_js
50+ class DevelopCommand (setuptools .command .develop .develop ):
51+ """Python and JS code"""
52+
53+
54+ @build_js
55+ class BuildPyCommand (setuptools .command .build_py .build_py ):
56+ """Python and JS code"""
57+
58+
59+ class BuildJSCommand (setuptools .command .build_py .build_py ):
60+ """Use nodejs and npm commands to browserify forest.js
61+
62+ .. note:: Assume current working directory is package ROOT
63+ """
64+ def run (self ):
65+ cwd = os .getcwd ()
66+ os .chdir ("forest/js" )
67+ if not os .path .exists ("node_modules" ):
68+ subprocess .check_call (["npm" , "install" ])
69+ subprocess .check_call (["npm" , "run" , "build" ])
70+ os .chdir (cwd )
71+ super ().run ()
72+
73+
3074setuptools .setup (
3175 name = NAME ,
3276 version = find_version (),
3377 author = "Andrew Ryan" ,
347879+ cmdclass = {
80+ "install" : InstallCommand ,
81+ "develop" : DevelopCommand ,
82+ "build_py" : BuildPyCommand ,
83+ "build_js" : BuildJSCommand ,
84+ },
3585 description = "Forecast visualisation and survey tool" ,
3686 packages = setuptools .find_packages (),
3787 package_data = {
0 commit comments