check_minimal_install.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """
  2. This script ensures that some dependencies are _not_ installed in the
  3. current python environment.
  4. This is to ensure that tests with minimal dependencies are not tainted
  5. by too many installed packages.
  6. """
  7. from typing import List
  8. # These are taken from `setup.py` for ray[default]
  9. DEFAULT_BLACKLIST = [
  10. "aiohttp",
  11. "aiohttp_cors",
  12. "colorful",
  13. "py-spy",
  14. "gpustat",
  15. "opencensus",
  16. "prometheus_client",
  17. "smart_open",
  18. "torch",
  19. "tensorflow",
  20. "jax",
  21. ]
  22. def assert_packages_not_installed(blacklist: List[str]):
  23. try:
  24. from pip._internal.operations import freeze
  25. except ImportError: # pip < 10.0
  26. from pip.operations import freeze
  27. installed_packages = [p.split("==")[0].split(" @ ")[0] for p in freeze.freeze()]
  28. assert not any(p in installed_packages for p in blacklist), (
  29. f"Found blacklisted packages in installed python packages: "
  30. f"{[p for p in blacklist if p in installed_packages]}. "
  31. f"Minimal dependency tests could be tainted by this. "
  32. f"Check the install logs and primary dependencies if any of these "
  33. f"packages were installed as part of another install step."
  34. )
  35. print(
  36. f"Confirmed that blacklisted packages are not installed in "
  37. f"current Python environment: {blacklist}"
  38. )
  39. if __name__ == "__main__":
  40. assert_packages_not_installed(DEFAULT_BLACKLIST)