prepare_old_deps.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env bash
  2. # this script is run by GitHub Actions in a plain `focal` container; it
  3. # - installs the minimal system requirements, and poetry;
  4. # - patches the project definition file to refer to old versions only;
  5. # - creates a venv with these old versions using poetry; and finally
  6. # - invokes `trial` to run the tests with old deps.
  7. set -ex
  8. # Prevent virtualenv from auto-updating pip to an incompatible version
  9. export VIRTUALENV_NO_DOWNLOAD=1
  10. # TODO: in the future, we could use an implementation of
  11. # https://github.com/python-poetry/poetry/issues/3527
  12. # https://github.com/pypa/pip/issues/8085
  13. # to select the lowest possible versions, rather than resorting to this sed script.
  14. # Patch the project definitions in-place:
  15. # - Replace all lower and tilde bounds with exact bounds
  16. # - Replace all caret bounds---but not the one that defines the supported Python version!
  17. # - Delete all lines referring to psycopg2 --- so no testing of postgres support.
  18. # - Use pyopenssl 17.0, which is the oldest version that works with
  19. # a `cryptography` compiled against OpenSSL 1.1.
  20. # - Omit systemd: we're not logging to journal here.
  21. sed -i \
  22. -e "s/[~>]=/==/g" \
  23. -e '/^python = "^/!s/\^/==/g' \
  24. -e "/psycopg2/d" \
  25. -e 's/pyOpenSSL = "==16.0.0"/pyOpenSSL = "==17.0.0"/' \
  26. -e '/systemd/d' \
  27. pyproject.toml
  28. # Use poetry to do the installation. This ensures that the versions are all mutually
  29. # compatible (as far the package metadata declares, anyway); pip's package resolver
  30. # is more lax.
  31. #
  32. # Rather than `poetry install --no-dev`, we drop all dev dependencies and the dev-docs
  33. # group from the toml file. This means we don't have to ensure compatibility between
  34. # old deps and dev tools.
  35. pip install toml wheel
  36. REMOVE_DEV_DEPENDENCIES="
  37. import toml
  38. with open('pyproject.toml', 'r') as f:
  39. data = toml.loads(f.read())
  40. del data['tool']['poetry']['dev-dependencies']
  41. del data['tool']['poetry']['group']['dev-docs']
  42. with open('pyproject.toml', 'w') as f:
  43. toml.dump(data, f)
  44. "
  45. python3 -c "$REMOVE_DEV_DEPENDENCIES"
  46. pip install poetry==1.3.2
  47. poetry lock
  48. echo "::group::Patched pyproject.toml"
  49. cat pyproject.toml
  50. echo "::endgroup::"
  51. echo "::group::Lockfile after patch"
  52. cat poetry.lock
  53. echo "::endgroup::"