Meilix-Generator is based upon Flask (a Python framework) which has several dependencies to fulfill before actually running the app properly. This article will guide you through the way I used it to automatically generate the requirement file for Meilix Generator app so that one doesn’t have to manually type all the requirements.
An app powered by Python always has several dependencies to fulfill to run the app successfully. The app root directory contains a file named as requirements.txt which contains the name of the dependency and their version. There are features ways to generate the requirement file for an app but the one which I will demonstrate is the best one. So I used this idea to generate the requirement file for webapp Meilix Generator.
Ways to get the requirement.txt
The internet has a featured way through which one has just to run a command to get a list of all the different dependencies within an app.
This way will generate a bunch of dependencies that we not even required.
Why do we really require to generate a requirement file?
Yes, one may even ask that we can even write the dependency in the requirements.txt file. Why do we need a command to generate it?
Since because it will take care of two important things:
1. It will ensure that all the dependencies have been included, from user input one may forget to find some of the dependency and to include that.
- It will also take care of the Python Package Version Pinning which is really important. People use to version pinning for Python requirements as “>=” style. It’s important to follow “==” style because If we want to install the program in one year in the future, the required packages should be pinned to assure that the API changes in the installed packages do not break the program. Please read here for more info.
The way mentioned below will ensure to provide both these features.
How I generated it for Meilix Generator?
Meilix Generator run on Flask that require a requirement.txt file to fulfill the dependencies. Let’s get straight to the way to generate it for the project.
First we will simply create a requirements.in file in which we will simply mention all the dependencies in a simple way:
Now we will use a command to latest packages:
#Note that if you would like to change the requirements, please edit the requirements.in file and run this command to update the dependencies
Then type this command to generate the requirements.txt file from requirements.in
#fix the versions that definitely work for an eternity.
This will generate a file something as:
Now you generated a perfect requirements.txt file with all the dependencies satisfied with proper python package pinning.
The meilix-generator repo which uses this: