[PYTHON] Split requirements.txt

Multiple Requirements File for each environment in one project, such as local development environment, development code combination environment, commercial environment, etc. I think there are cases where you want to use -file-format). In such a case, let's divide the file.

… Make a note of what you learned.

procedure

Create a directory for saving Requirements File

Create a directory to store the requirements files for each environment.

cd /project/root/directory
mkdir requirements

Make the previous file a common file

Let's put the requirements.txt that we used so far as a common file.

mv requirements.txt requirements/common.txt

Create a file for each environment

Examples of files for commercial environments. Create a requirements / prod.txt file with an editor such as vi. Import common.txt with the -r option.

requirements/prod.txt


# requirements for production
-r common.txt
#Below this is a list of packages dedicated to commercial environments

If you are in a development environment, you can create a file such as dev.txt.

requirements/dev.txt


# requirements for development
-r common.txt
#Below this is a list of packages that are only used in the development environment

Make an alternative to requirements.txt

Create an alias requirements.txt for platforms that directly reference requirements.txt such as heroku.

requirements.txt


# Mirrors prod
-r requirements/prod.txt

Final directory structure

.
├── requirements.txt
└── requirements
    ├── common.txt
    ├── dev.txt
    └── prod.txt

reference

Recommended Posts

Split requirements.txt
About requirements.txt