lint-requirements 1001 B

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