ci-python-imports 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # ci-python-imports - List all files transitively imported by a mzcompose
  12. # composition. This is a separate script instead of a module to prevent
  13. # polluting namespaces and inherting a polluted namespace.
  14. import os
  15. import sys
  16. import argparse
  17. from materialize import MZ_ROOT
  18. def main() -> int:
  19. parser = argparse.ArgumentParser(
  20. prog="ci-python-imports",
  21. formatter_class=argparse.RawDescriptionHelpFormatter,
  22. description="""
  23. ci-python-imports - List all files transitively imported by a mzcompose
  24. composition. This is a separate script instead of a module to prevent polluting
  25. namespaces and inherting a polluted namespace.""",
  26. )
  27. parser.add_argument("path", type=str, help="path to composition")
  28. args = parser.parse_args()
  29. sys.path.insert(1, args.path)
  30. import mzcompose
  31. for key, module in sys.modules.items():
  32. if not key.startswith("materialize."):
  33. continue
  34. if module.__file__ is not None:
  35. print(os.path.relpath(module.__file__, MZ_ROOT))
  36. # Ignore all not explicitly imported files of the module
  37. # else:
  38. # for path in module.__path__:
  39. # for file in os.listdir(path):
  40. # if file.endswith(".py"):
  41. # print(os.path.relpath(os.path.join(path, file), MZ_ROOT))
  42. if __name__ == "__main__":
  43. sys.exit(main())