test_old_deps.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # Prevent tzdata from asking for user input
  8. export DEBIAN_FRONTEND=noninteractive
  9. set -ex
  10. apt-get update
  11. apt-get install -y \
  12. python3 python3-dev python3-pip python3-venv pipx \
  13. libxml2-dev libxslt-dev xmlsec1 zlib1g-dev libjpeg-dev libwebp-dev
  14. export LANG="C.UTF-8"
  15. # Prevent virtualenv from auto-updating pip to an incompatible version
  16. export VIRTUALENV_NO_DOWNLOAD=1
  17. # TODO: in the future, we could use an implementation of
  18. # https://github.com/python-poetry/poetry/issues/3527
  19. # https://github.com/pypa/pip/issues/8085
  20. # to select the lowest possible versions, rather than resorting to this sed script.
  21. # Patch the project definitions in-place:
  22. # - Replace all lower and tilde bounds with exact bounds
  23. # - Replace all caret bounds---but not the one that defines the supported Python version!
  24. # - Delete all lines referring to psycopg2 --- so no testing of postgres support.
  25. # - Use pyopenssl 17.0, which is the oldest version that works with
  26. # a `cryptography` compiled against OpenSSL 1.1.
  27. # - Omit systemd: we're not logging to journal here.
  28. # TODO: also replace caret bounds, see https://python-poetry.org/docs/dependency-specification/#version-constraints
  29. # We don't use these yet, but IIRC they are the default bound used when you `poetry add`.
  30. # The sed expression 's/\^/==/g' ought to do the trick. But it would also change
  31. # `python = "^3.7"` to `python = "==3.7", which would mean we fail because olddeps
  32. # runs on 3.8 (#12343).
  33. sed -i \
  34. -e "s/[~>]=/==/g" \
  35. -e '/^python = "^/!s/\^/==/g' \
  36. -e "/psycopg2/d" \
  37. -e 's/pyOpenSSL = "==16.0.0"/pyOpenSSL = "==17.0.0"/' \
  38. -e '/systemd/d' \
  39. pyproject.toml
  40. # Use poetry to do the installation. This ensures that the versions are all mutually
  41. # compatible (as far the package metadata declares, anyway); pip's package resolver
  42. # is more lax.
  43. #
  44. # Rather than `poetry install --no-dev`, we drop all dev dependencies from the
  45. # toml file. This means we don't have to ensure compatibility between old deps and
  46. # dev tools.
  47. pip install --user toml
  48. REMOVE_DEV_DEPENDENCIES="
  49. import toml
  50. with open('pyproject.toml', 'r') as f:
  51. data = toml.loads(f.read())
  52. del data['tool']['poetry']['dev-dependencies']
  53. with open('pyproject.toml', 'w') as f:
  54. toml.dump(data, f)
  55. "
  56. python3 -c "$REMOVE_DEV_DEPENDENCIES"
  57. pipx install poetry==1.1.12
  58. ~/.local/bin/poetry lock
  59. echo "::group::Patched pyproject.toml"
  60. cat pyproject.toml
  61. echo "::endgroup::"
  62. echo "::group::Lockfile after patch"
  63. cat poetry.lock
  64. echo "::endgroup::"
  65. ~/.local/bin/poetry install -E "all test"
  66. ~/.local/bin/poetry run trial --jobs=2 tests