2222"""
2323
2424import json
25+ import os
2526import sys
2627
2728from path import Path
29+ from pkg_resources import get_distribution
2830import whichcraft
2931import zetup
3032
31- # __version__ module is created by setuptools_scm during setup
32- from .__version__ import version as __version__
33-
3433from .error import NodeCommandError
3534
36- __all__ = (
37- 'install' , 'uninstall' , 'which' , 'Popen' , 'call' ,
38- 'NodeCommandError' )
35+ # HACK: Fix inconsistently hard-coded whichcraft.__version__
36+ whichcraft .__version__ = get_distribution ('whichcraft' ).version
37+
38+ zetup .toplevel (__name__ , [
39+ 'NodeCommandError' ,
40+ 'Popen' ,
41+ 'call' ,
42+ 'install' ,
43+ 'uninstall' ,
44+ 'which' ,
45+ ])
3946
4047
41- #: The absolute path to the local node_modules/ sub-directory used for
42- # installing Node.js packages under the python environment root
48+ #: The absolute path to the local ``node_modules/`` sub-directory.
49+ #
50+ # Which is located under the current Python environment root, and which is
51+ # used for installing Node.js packages into
4352NODE_MODULES_DIR = (Path (sys .prefix ) / 'node_modules' ).mkdir_p ()
4453
4554# create a dummy package.json in python environment root for making npm
5665
5766def install (package ):
5867 """
59- Install given Node.js `package` into ``node_modules/`` of current Python
60- environment
68+ Install given Node.js `package`.
69+
70+ Into ``node_modules/`` of current Python environment
6171 """
6272 command = ['npm' , 'install' , package ]
6373 with Path (sys .prefix ):
6474 status = zetup .call (command )
6575 if status :
66- raise RuntimeError ("Command {!r} failed with status {}"
67- .format (command , status ))
76+ raise NodeCommandError (command , status , os .getcwd ())
6877
6978
7079def uninstall (package ):
7180 """
72- Uninstall given Node.js `package` from ``node_modules/`` of current Python
73- environment
81+ Uninstall given Node.js `package`.
82+
83+ From ``node_modules/`` of current Python environment
7484 """
7585 command = ['npm' , 'uninstall' , package ]
7686 with Path (sys .prefix ):
7787 status = zetup .call (command )
7888 if status : # pragma: no cover
79- raise RuntimeError ("Command {!r} failed with status {}"
80- .format (command , status ))
89+ raise NodeCommandError (command , status , os .getcwd ())
8190
8291
8392def which (executable ):
8493 """
85- Find `executable` in ``node_modules/.bin/`` of current Python environment
94+ Find `executable` in ``node_modules/.bin/`` of current Python environment.
8695
8796 :return: Absolute ``path.Path`` instance or ``None``
8897 """
@@ -93,9 +102,13 @@ def which(executable):
93102
94103def Popen (executable , args = None , ** kwargs ):
95104 """
96- Create a subprocess for given Node.js `executable` with given sequence
97- of `args` strings and optional `kwargs` for ``zetup.Popen``, including all
98- options for ``subprocess.Popen``
105+ Create a subprocess for given Node.js `executable`.
106+
107+ :param args:
108+ Optional sequence of command argument strings
109+ :param options:
110+ General options for ``zetup.call``, including all options for
111+ ``subprocess.call``
99112 """
100113 import nodely .bin
101114
@@ -105,9 +118,13 @@ def Popen(executable, args=None, **kwargs):
105118
106119def call (executable , args = None , ** kwargs ):
107120 """
108- Call given Node.js `executable` with given sequence of `args` strings and
109- optional `kwargs` for ``zetup.call``, including all options for
110- ``subprocess.call``
121+ Call given Node.js `executable`.
122+
123+ :param args:
124+ Optional sequence of command argument strings
125+ :param kwargs:
126+ General options for ``zetup.call``, including all options for
127+ ``subprocess.call``
111128 """
112129 import nodely .bin
113130
0 commit comments