|
| 1 | +Pinning Requirements |
| 2 | +==================== |
| 3 | + |
| 4 | +Introduction |
| 5 | +------------ |
| 6 | + |
| 7 | +By design this project only defines dependencies in one place, i.e. in |
| 8 | +the ``requires`` table in ``pyproject.toml``. |
| 9 | + |
| 10 | +In the ``requires`` table it is possible to pin versions of some dependencies |
| 11 | +as needed. For library projects it is best to leave pinning to a minimum so |
| 12 | +that your library can be used by the widest range of applications. |
| 13 | + |
| 14 | +When CI builds the project it will use the latest compatible set of |
| 15 | +dependencies available (after applying your pins and any dependencies' pins). |
| 16 | + |
| 17 | +This approach means that there is a possibility that a future build may |
| 18 | +break because an updated release of a dependency has made a breaking change. |
| 19 | + |
| 20 | +The correct way to fix such an issue is to work out the minimum pinning in |
| 21 | +``requires`` that will resolve the problem. However this can be quite hard to |
| 22 | +do and may be time consuming when simply trying to release a minor update. |
| 23 | + |
| 24 | +For this reason we provide a mechanism for locking all dependencies to |
| 25 | +the same version as a previous successful release. This is a quick fix that |
| 26 | +should guarantee a successful CI build. |
| 27 | + |
| 28 | +Finding the lock files |
| 29 | +---------------------- |
| 30 | + |
| 31 | +Every release of the project will have a set of requirements files published |
| 32 | +as release assets. |
| 33 | + |
| 34 | +For example take a look at the release page for python3-pip-skeleton-cli here: |
| 35 | +https://github.com/DiamondLightSource/python3-pip-skeleton-cli/releases/tag/3.3.0 |
| 36 | + |
| 37 | +There is a list of requirements*.txt files showing as assets on the release. |
| 38 | + |
| 39 | +There is one file for each time the CI installed the project into a virtual |
| 40 | +environment. There are multiple of these as the CI creates a number of |
| 41 | +different environments. |
| 42 | + |
| 43 | +The files are created using ``pip freeze`` and will contain a full list |
| 44 | +of the dependencies and sub-dependencies with pinned versions. |
| 45 | + |
| 46 | +You can download any of these files by clicking on them. It is best to use |
| 47 | +the one that ran with the lowest Python version as this is more likely to |
| 48 | +be compatible with all the versions of Python in the test matrix. |
| 49 | +i.e. ``requirements-test-ubuntu-latest-3.8.txt`` in this example. |
| 50 | + |
| 51 | +Applying the lock file |
| 52 | +---------------------- |
| 53 | + |
| 54 | +To apply a lockfile: |
| 55 | + |
| 56 | +- copy the requirements file you have downloaded to the root of your |
| 57 | + repository |
| 58 | +- rename it to requirements.txt |
| 59 | +- commit it into the repo |
| 60 | +- push the changes |
| 61 | + |
| 62 | +The CI looks for a requirements.txt in the root and will pass it to pip |
| 63 | +when installing each of the test environments. pip will then install exactly |
| 64 | +the same set of packages as the previous release. |
| 65 | + |
| 66 | +Removing dependency locking from CI |
| 67 | +----------------------------------- |
| 68 | + |
| 69 | +Once the reasons for locking the build have been resolved it is a good idea |
| 70 | +to go back to an unlocked build. This is because you get an early indication |
| 71 | +of any incoming problems. |
| 72 | + |
| 73 | +To restore unlocked builds in CI simply remove requirements.txt from the root |
| 74 | +of the repo and push. |
0 commit comments