88NODE_ENV = 'node_env'
99
1010
11- class NodeEnv (object ):
12- def __init__ (self , py_env ):
13- self .py_env = py_env
14- self .env_prefix = '. {0}/bin/activate &&' .format (NODE_ENV )
15-
16- def run (self , cmd , ** kwargs ):
17- return self .py_env .run (' ' .join ([self .env_prefix , cmd ]), ** kwargs )
11+ class NodeEnv (python .PythonEnv ):
12+ @property
13+ def env_prefix (self ):
14+ base = super (NodeEnv , self ).env_prefix
15+ return ' ' .join ([base , '. {0}/bin/activate &&' .format (NODE_ENV )])
1816
1917
2018@contextlib .contextmanager
21- def in_env (py_env ):
22- yield NodeEnv (py_env )
19+ def in_env ():
20+ yield NodeEnv ()
2321
2422
2523def install_environment ():
2624 assert local .path ('package.json' ).exists ()
2725
28- if local .path ('node_env' ).exists ():
26+ if local .path (NODE_ENV ).exists ():
2927 return
3028
3129 local ['virtualenv' ][python .PY_ENV ]()
3230
3331 with python .in_env () as python_env :
3432 python_env .run ('pip install nodeenv' )
35- python_env .run ('nodeenv --jobs 4 {0}' .format (NODE_ENV ))
3633
37- with in_env (python_env ) as node_env :
34+ try :
35+ # Try and use the system level node executable first
36+ python_env .run ('nodeenv -n system {0}' .format (NODE_ENV ))
37+ except Exception :
38+ # TODO: log exception here
39+ # cleanup
40+ local .path (NODE_ENV ).remove ()
41+ python_env .run ('nodeenv --jobs 4 {0}' .format (NODE_ENV ))
42+
43+ with in_env () as node_env :
3844 node_env .run ('npm install -g' )
3945
4046
4147def run_hook (hook , file_args ):
42- with python .in_env () as py_env :
43- with in_env (py_env ) as node_env :
44- return helpers .run_hook (node_env , hook , file_args )
48+ with in_env () as node_env :
49+ return helpers .run_hook (node_env , hook , file_args )
0 commit comments