requirements_test.py 1.2 KB

123456789101112131415161718192021222324
  1. import configparser
  2. # There's two sets of requirements relevant for python. The first set in requirements.txt is installed
  3. # during the Docker build and is used for linting, building, and uploading the PGV python package to PyPI.
  4. #
  5. # The other set is in the install_requires section of setup.cfg. This is what's needed to use the package.
  6. #
  7. # We use pip_install from @rules_python to install these requirements in order to test the package. Unfortunately:
  8. # - pip_install can't handle setup.cfg directly, it wants a file containing a simple list
  9. # - as a bazel repository_rule, pip_install won't accept generated files as input so we can't autogen
  10. # this simpler file out of setup.cfg as part of bazel build.
  11. #
  12. # So instead here we just check that requirements.in matches what's in install_requires of setup.cfg.
  13. with open('python/requirements.in', 'r') as reqs:
  14. lines = reqs.readlines()
  15. requirements_dot_in_set = {line.strip() for line in lines if line.strip() and not line.startswith("#")}
  16. config = configparser.ConfigParser()
  17. config.read('python/setup.cfg')
  18. setup_dot_cfg_set = {line for line in config['options']['install_requires'].split() if not line.startswith("#")}
  19. assert requirements_dot_in_set == setup_dot_cfg_set