lint_requirements.py 981 B

12345678910111213141516171819202122232425262728
  1. import packaging.requirements
  2. def main() -> None:
  3. """
  4. We cannot have non-specifier requirements if we want to publish to PyPI
  5. due to security concerns. This check ensures we don't have/add any URL/VCS
  6. dependencies in the base requirements file.
  7. """
  8. with open("requirements-frozen.txt") as reqs_file:
  9. for lineno, line in enumerate(reqs_file, start=1):
  10. line = line.strip()
  11. line, _, _ = line.partition("#")
  12. if not line:
  13. continue
  14. try:
  15. packaging.requirements.Requirement(line)
  16. except packaging.requirements.InvalidRequirement:
  17. raise SystemExit(
  18. f"You cannot use dependencies that are not on PyPI directly.\n"
  19. f"See PEP440: https://www.python.org/dev/peps/pep-0440/#direct-references\n\n"
  20. f"{reqs_file.name}:{lineno}: {line}"
  21. )
  22. if __name__ == "__main__":
  23. main()