lint_requirements.py 968 B

123456789101112131415161718192021222324252627
  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. if not line or line.startswith(("--", "#")):
  12. continue
  13. try:
  14. packaging.requirements.Requirement(line)
  15. except packaging.requirements.InvalidRequirement:
  16. raise SystemExit(
  17. f"You cannot use dependencies that are not on PyPI directly.\n"
  18. f"See PEP440: https://www.python.org/dev/peps/pep-0440/#direct-references\n\n"
  19. f"{reqs_file.name}:{lineno}: {line}"
  20. )
  21. if __name__ == "__main__":
  22. main()