Skip to content

Latest commit

 

History

History
82 lines (66 loc) · 3.73 KB

README.md

File metadata and controls

82 lines (66 loc) · 3.73 KB

CI - build CI - coverage MyPy checked PyPI - Version PyPI - Status PyPI - Python Version License

Requirements.txt Wayback Machine 🚂🕒️

Note: This script is not developed nor endorsed by the Python Packaging Authority (PyPA) or other official Python body.

$ requirements_wayback_machine -r requirements.txt -d 2021-02-03

# requirements_wayback_machine: reference date 2021-02-03
# requirements_wayback_machine: torch<=1.7.1
torch
# requirements_wayback_machine: torchvision<=0.8.2
torchvision
# requirements_wayback_machine: imageio<=2.9.0
imageio

Installing correct dependencies for an older Python project can be tricky, since pip install -r requirements.txt can easily install a package version that is too recent and incompatible with the old project. This can happen even if the requirements.txt file specifies an exact version (eg. torch==1.7.1), since Python packages often only specify minimum versions of their dependencies (which does not prevent a new major dependency version to be installed).

One solution to this problem is exact specification of all transitive dependencies as provided by pip freeze or Pipenv/Poetry lockfiles. If you don't have a lockfile, this is where Requirements.txt Wayback Machine comes in to tell you what was the last available version of each dependency by given date. Presumably at some time in the past, pip install grabbed the correct versions, so giving an approximate date when the project was working will help you pin the correct versions.

Tip: If you're still having trouble after adding constraints for maximum versions for all entries in your requirements.txt, try listing all transitive dependencies with pip freeze and running Requirements.txt Wayback Machine again on this larger requirements.txt (a suggestion by u/hai_wim on Reddit). Note that you will need to remove the == exact constraints that pip freeze adds before doing this (the Wayback Machine is trying to satisfy the existing constraints, so using == doesn't really make sense, it would find no suitable version if the == version is too new).

Installation

$ pip install requirements-wayback-machine

Usage

$ requirements_wayback_machine -r <path_to_requirements.txt> -d <YYYY-MM-DD>

For more information and options, run requirements_wayback_machine -h.

Example:

$ cat requirements.txt
torch
torchvision
imageio

$ requirements_wayback_machine -r requirements.txt -d 2021-02-03
# requirements_wayback_machine: reference date 2021-02-03
# requirements_wayback_machine: torch<=1.7.1
torch
# requirements_wayback_machine: torchvision<=0.8.2
torchvision
# requirements_wayback_machine: imageio<=2.9.0
imageio

License

MIT - see LICENSE.txt.