python项目中的javascript依赖项 [英] javascript dependencies in python project
问题描述
我正在编写允许人们将数学书籍发布为网站的软件。它主要基于Python + Flask,但是为了处理方程式,我使用了MathJax。 MathJax可以在客户端或服务器端使用(通过 MathJax节点)。在后一种情况下,我必须使用 npm
在我的主Python脚本可以访问的某个位置安装MathJax-node,然后从脚本中调用它。在前一种情况下,我必须提供MathJax.js作为资产,可供客户端使用(当前,我使用Flask的 send_from_directory
函数)。
I'm writing software that allows one to publish mathematical books as websites. It is based mostly on Python + Flask, but to deal with equations I'm using MathJax. MathJax can be used either client-side or server-side (through MathJax-node). In the latter case I have to use npm
to install MathJax-node in some place accessible to my main Python script, then invoke it from the script. In the former case, I have to provide MathJax.js as an asset, available to client (currently I use Flask's send_from_directory
function).
我的问题是:在Python中处理此类异构依赖关系的最佳实践是什么?我的目标是至少在类unix的系统(Linux或MacOS)上使安装过程尽可能简单,只要 node
和 npm
已经可用。
My question is: what is the best practice of dealing with such heterogenous dependencies in Python? My goal is to make installation process as simple as possible at least on unix-like systems (Linux or MacOS), provided that node
and npm
are already available.
我可以将我需要的所有javascript资源放入我的发行版本身,但是也许有更好的方法吗? / p>
I can just put all the javascript sources I need into my distribution itself, but maybe there's a better way to do it?
推荐答案
我的问题是:处理此类
异构依赖项的最佳实践是什么在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
目录。
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
).
这篇关于python项目中的javascript依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!