2017-03-12 31 views
5

Test etmek istediğim bir python web istemcisi uyguladım.Setup.py npm modülünü nasıl kurarım?

Sunucu npm kayıt defterinde barındırılmaktadır. İşlevsel testlerimi yapmadan önce sunucu yerel olarak düğümle çalıştırılıyor.

npm modülünü setup.py komutumdan nasıl düzgün yükleyebilirim? İşte

benim şimdiki çözüm bu post den ilham:

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}, 

cevap

5
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) 

VEYA

riskler
from distutils.command.build import build 

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

nihayet:

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

Ayrıca bak here

1

Sen Burada sadece, sen kaldırabilir yapar basit bir fonksiyonudur, çok yakın "--global" seçeneği yüklemek istediğiniz olduğu geçerli proje için paket sadece akılda komut kabuğu tutmak = güvenliğini sunabilir Gerçek

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