Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How setup.py install npm module?

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

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

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

Here is my current solution inspired from 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},
like image 963
Maxime Helen Avatar asked Mar 12 '17 02:03

Maxime Helen


People also ask

Can we use npm package in Python?

npm allows installing packages globally or local to a project. In pip , all packages are installed globally. To separate the local dependencies from system-wide packages, a virtual environment is created which contains all the dependencies local to the project and even a local Python distribution.

How install pip using setup py?

Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.


1 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

like image 64
pramod Avatar answered Sep 21 '22 11:09

pramod