且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

python项目中的javascript依赖项

更新时间:2022-06-12 22:20:40


我的问题是:处理此类
异构依赖项的***实践是什么在Python中?

My question is: what is the best practice of dealing with such heterogenous dependencies in Python?

在Node依赖的情况下,我将包含一个 package.json $ c目录中的$ c>文件,该文件指定所需的节点依赖性。对于其他语言/程序包管理器,我还将使用指定依赖项的常规方式(例如,为Ruby依赖项添加Gemfile)。

In the case of Node dependencies, I would include a package.json file in the directory which specifies the Node dependencies needed. For other languages/package managers, I would also use whatever the conventional way of specifying dependencies is (e.g. add a Gemfile for Ruby dependencies).

另一个常见的示例是Python / Flask附带使用 Bower 软件包管理器来获取静态前端依赖项。在这种情况下,依赖项在 bower.json 文件中指定,通常被拉入Flask的 static 的Bower文件夹中。 >目录。

Another common example of this that comes up with Python/Flask is using the Bower package manager for static frontend dependencies. In that case, the dependencies are specified in the bower.json file and are usually pulled into a bower folder in Flask's static directory.


我可以将我需要的所有JavaScript资源放入我的发行版
中,但是也许有更好的方法

I can just put all the javascript sources I need into my distribution itself, but maybe there's a better way to do it?

一旦您有了 package.json 在指定的依赖项之后,您可以通过运行 npm install 来获取并安装所有所需的Node依赖项,在我看来,这比将javascript源包含在项目中是一个更优雅的解决方案。

Once you've got the package.json with the dependencies specified, you can fetch and install all the Node dependencies needed by running npm install which, in my opinion, is a more elegant solution than including the javascript sources with the project.

现在您已经拥有多个软件包管理器(例如,您可能使用 pip 作为Python依赖项。除了 npm 用于节点依赖项之外),您可能还想制作一个Makefile或一些部署/构建脚本来使用它们全部来获取/安装(例如,如果我使用Travis CI,我将更新 .travis.yml 调用 npm install 以及 pip install -r )。

Now that you've got multiple package managers (e.g. maybe you're using pip for the Python dependencies in addition to npm for the Node dependencies), you might want to make a Makefile or some deployment/build script to fetch/install using all of them (for example, if I were using Travis CI, I would update my .travis.yml to call npm install in addition to pip install -r).