Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript dependencies in python project

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

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.

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

like image 878
Ilya V. Schurov Avatar asked May 25 '17 16:05

Ilya V. Schurov


People also ask

How do I get the dependencies for a project in Python?

In this case, you have two options: Use the pipdeptree utility to gather a list of all dependencies, create a requirements. txt file listing all the dependencies, and then download them with the pip download command. Get the list of dependencies for a package from the setup.py file.

What are javascript dependencies?

A dependency is some third-party code that your application depends on. Just like a child depends on its parent, your application depends on other people's code. A piece of code becomes a true dependency when your own application cannot function without it.

Can Python modules have dependencies?

Dependency Hell Dependency conflicts occur when different Python packages have the same dependency, but depend on different and incompatible versions of that shared package. Because only a single version of a dependency is permitted in any project's environment, finding a compatible solution can be difficult.

Why does Nodejs need Python?

Node. js is built with GYP — cross-platform built tool written in Python. Also some other build steps are implemented in Python. So Python is required for building node from source.


1 Answers

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

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

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.

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

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.

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

like image 62
Christopher Su Avatar answered Oct 12 '22 23:10

Christopher Su