user3748880
user3748880

Reputation:

Maintaining different requirements files for virtualenv and pip

I know that I can use pip freeze to assist in creating a list of my requirements for my virtual environment, but I'm having a bit of difficulty managing all of my different packages.

I want to keep some packages separate for development and production, and it is unwieldy to have production and development requirement files since I am using so many packages (many of which are common to each other.) How can I more efficiently keep my production and development packages separate?

Upvotes: 3

Views: 1233

Answers (2)

JoshieSimmons
JoshieSimmons

Reputation: 2791

Not difficult at all.

Let's say you have one requirements file for production: production.txt and one for development: development.txt. Create a third file, shared.txt, that has all of the dependencies in common. Then, in each respective requirements file, list the dependencies exclusive to your desired environment. At the head of development.txt and production.txt, link to your shared.txt using -r shared.txt. Each file will now load the common dependencies before loading exclusive dependencies.

Example:

shared.txt

SharedExamplePackage1
SharedExamplePackage2
SharedExamplePackage3
SharedExamplePackage4
SharedExamplePackage5

development.txt

-r shared.txt
DevExamplePackage1
DevExamplePackage2

production.txt

-r shared.txt
ProductionExamplePackage1
ProductionExamplePackage2
ProductionExamplePackage3

Upvotes: 7

Simeon Visser
Simeon Visser

Reputation: 122366

You can include one requirements file into another by using:

-r more_requirements.txt

For example, the dev-requirements.txt file can contain the production requirements plus the additional development packages:

-r requirements.txt
mock
tox

(and so on)

Upvotes: 5

Related Questions