entry_points.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. # This script is used for validating installed entrypoints. Note that it fails on Python 3.7
  3. import sys
  4. from importlib.metadata import PackageNotFoundError, distribution
  5. EXPECTED_EPS = {'sqlalchemy.dialects:clickhousedb',
  6. 'sqlalchemy.dialects:clickhousedb.connect'}
  7. def validate_entrypoints():
  8. expected_eps = EXPECTED_EPS.copy()
  9. try:
  10. dist = distribution('clickhouse-connect')
  11. except PackageNotFoundError:
  12. print ('\nClickHouse Connect package not found in this Python installation')
  13. return -1
  14. print()
  15. for entry_point in dist.entry_points:
  16. name = f'{entry_point.group}:{entry_point.name}'
  17. print(f' {name}={entry_point.value}')
  18. try:
  19. expected_eps.remove(name)
  20. except KeyError:
  21. print (f'\nUnexpected entry point {name} found')
  22. return -1
  23. if expected_eps:
  24. print()
  25. for name in expected_eps:
  26. print (f'Did not find expected ep {name}')
  27. return -1
  28. print ('\nEntrypoints correctly installed')
  29. return 0
  30. if __name__ == '__main__':
  31. sys.exit(validate_entrypoints())