0

I would like to keep multiple requirements*.txt files up to date while working on a project. Some packages my project depends on are required at runtime, while others are required during development only. Since these packages may have their own dependencies as well, it is hard to tell which dependency should be in which requirements*.txt file.

If I would like to keep track of the runtime dependencies in requirements_prod.txt and of the development dependencies in requirements_dev.txt, how should I keep both files up to date and clean if I add packages during development? Running a mere pip freeze > requirements_prod.txt would list all installed dependencies, including those only needed for development. This would pollute either of the requirements_*.txt files.

Ideally, I would like to mark a package on installation as 'development' or 'runtime' and have it (and its own dependencies) written to the correct requirements_*.txt.

Edit:

@Brian: My question is slightly different from this question because I would like to have my requirements_*.txt files to stay side by side in the same branch, not in different branches. So my requirements_*.txt should always be in the same commits.

  • Does this answer your question? [How to customize a requirements.txt for multiple environments?](https://stackoverflow.com/questions/17803829/how-to-customize-a-requirements-txt-for-multiple-environments) – Brian61354270 Dec 01 '21 at 19:16
  • I think you may find [this](https://stackoverflow.com/q/43658870/4046632) useful – buran Dec 01 '21 at 19:16
  • 1
    Usually you only want to add _direct_ dependencies to your requirements file. There's no need to list the dependencies of your dependencies since pip will find those just fine on its own. As for how to mark packages as "development" or "runtime", well, that's exactly what `requirements_prod.txt` and `requirement_dev.txt` ought to be doing. Both of those files should be maintained manually, not generated via pip freeze. – Brian61354270 Dec 01 '21 at 19:24
  • use `pipenv` and save details for dev prod stage in pip.lock file – sahasrara62 Dec 01 '21 at 19:31

1 Answers1

1

Brian's answer clarifies things a lot for me:

Usually you only want to add direct dependencies to your requirements file. (...) Both of those files should be maintained manually

So instead of generating the requirements_*.txt file automatically using pip freeze, they should be maintained manually and only need to contain direct dependencies.