12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/env python3
- # Copyright Materialize, Inc. and contributors. All rights reserved.
- #
- # Use of this software is governed by the Business Source License
- # included in the LICENSE file at the root of this repository.
- #
- # As of the Change Date specified in that file, in accordance with
- # the Business Source License, use of this software will be governed
- # by the Apache License, Version 2.0.
- #
- # ci-python-imports - List all files transitively imported by a mzcompose
- # composition. This is a separate script instead of a module to prevent
- # polluting namespaces and inherting a polluted namespace.
- import os
- import sys
- import argparse
- from materialize import MZ_ROOT
- def main() -> int:
- parser = argparse.ArgumentParser(
- prog="ci-python-imports",
- formatter_class=argparse.RawDescriptionHelpFormatter,
- description="""
- ci-python-imports - List all files transitively imported by a mzcompose
- composition. This is a separate script instead of a module to prevent polluting
- namespaces and inherting a polluted namespace.""",
- )
- parser.add_argument("path", type=str, help="path to composition")
- args = parser.parse_args()
- sys.path.insert(1, args.path)
- import mzcompose
- for key, module in sys.modules.items():
- if not key.startswith("materialize."):
- continue
- if module.__file__ is not None:
- print(os.path.relpath(module.__file__, MZ_ROOT))
- # Ignore all not explicitly imported files of the module
- # else:
- # for path in module.__path__:
- # for file in os.listdir(path):
- # if file.endswith(".py"):
- # print(os.path.relpath(os.path.join(path, file), MZ_ROOT))
- if __name__ == "__main__":
- sys.exit(main())
|