How to setup.py install the npm module?

I have implemented a python web client that I would like to test.

The server is hosted in the npm registry. The server starts locally with node before running my functional tests.

How to properly install the npm module from my setup.py script?

Here is my current solution inspired by this post:

class CustomInstallCommand(install): def run(self): arguments = [ 'npm', 'install', '--prefix', 'test/functional', 'promisify' ] subprocess.call(arguments, shell=True) install.run(self) setup( cmdclass={'install': CustomInstallCommand}, 
+5
source share
2 answers
 from setuptools.command.build_py import build_py class NPMInstall(build_py): def run(self): self.run_command('npm install --prefix test/functional promisify') build_py.run(self) 

OR

 from distutils.command.build import build class NPMInstall(build): def run(self): self.run_command("npm install --prefix test/functional promisify") build.run(self) 

finally:

 setuptools.setup( cmdclass={ 'npm_install': NPMInstall }, # Usual setup() args. # ... ) 

Also look here

+5
source

You are very close, here is a simple function that does just that, you can remove the "--global" option - you want to install the package only for the current project, remember that the shell = True command could have existing security risks

 import subprocess def npm_install(args=["npm","--global", "install", "search-index"]) subprocess.Popen(args, shell=True) 
+1
source

Source: https://habr.com/ru/post/1265338/


All Articles