在命令行(如npm)中使用别名运行python命令

时间:2018-06-21 21:36:44

标签: python node.js npm

在节点中,您可以定义package.json。然后定义一个script块,如下所示:

"scripts": {
    "start": "concurrently -k -r -s first \"yarn test:watch\" \"yarn open:src\" \"yarn lint:watch\"",
  },

因此,在根目录中,我可以执行yarn start来运行concurrently -k -r -s first \"yarn test:watch\" \"yarn open:src\" \"yarn lint:watch\"

与Python 3等效吗?如果我想要一个名为python test的脚本来运行python -m unittest discover -v

2 个答案:

答案 0 :(得分:1)

嗯,这是一种解决方法,但是显然,如果您安装了npm,就可以使用它。我在python应用程序的根目录中创建了一个文件package.json

{
"name": "fff-connectors",
"version": "1.0.0",
"description": "fff project to UC Davis",
"directories": {
    "test": "tests"
},
"scripts": {
    "install": "pip install -r requirements.txt",
    "test": "python -m unittest discover -v"
},
"keywords": [],
"author": "Leo Qiu",
"license": "ISC"
}

然后,我可以仅使用npm installyarn install安装所有依赖项,并使用yarn testnpm test运行测试脚本。

您还可以执行preinstallpostinstall挂钩。例如,您可能需要删除文件或创建文件夹结构。

另一个好处是,此设置允许您使用任何concurrently之类的npm库,因此可以一起运行多个文件,等等。

答案 1 :(得分:1)

为什么不直接使用 pipenv?它是 python 的 npm,您可以在 [scripts] 上添加一个与 npm 非常相似的 Pipfile

查看其他问题以了解更多信息:pipenv stack overflow question