bindepend.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2013-2023, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. """
  12. Show dll dependencies of executable files or other dynamic libraries.
  13. """
  14. import argparse
  15. import glob
  16. import PyInstaller.depend.bindepend
  17. import PyInstaller.log
  18. try:
  19. from argcomplete import autocomplete
  20. except ImportError:
  21. def autocomplete(parser):
  22. return None
  23. def run():
  24. parser = argparse.ArgumentParser()
  25. PyInstaller.log.__add_options(parser)
  26. parser.add_argument(
  27. 'filenames',
  28. nargs='+',
  29. metavar='executable-or-dynamic-library',
  30. help="executables or dynamic libraries for which the dependencies should be shown",
  31. )
  32. autocomplete(parser)
  33. args = parser.parse_args()
  34. PyInstaller.log.__process_options(parser, args)
  35. # Suppress all informative messages from the dependency code.
  36. PyInstaller.log.getLogger('PyInstaller.build.bindepend').setLevel(PyInstaller.log.WARN)
  37. try:
  38. for input_filename_or_pattern in args.filenames:
  39. for filename in glob.glob(input_filename_or_pattern):
  40. print(f"{filename}:")
  41. for lib_name, lib_path in sorted(PyInstaller.depend.bindepend.get_imports(filename)):
  42. print(f" {lib_name} => {lib_path}")
  43. print("")
  44. except KeyboardInterrupt:
  45. raise SystemExit("Aborted by user request.")
  46. if __name__ == '__main__':
  47. run()