MCPcopy
hub / github.com/pyinstaller/pyinstaller / _metadata_from

Method _metadata_from

PyInstaller/depend/analysis.py:835–885  ·  view source on GitHub ↗

Collect metadata whose requirements are implied by given function names. Args: package: The module name that must be imported in a source file to trigger the search. methods: Function names from **package** which take a distri

(self, package, methods=(), recursive_methods=())

Source from the content-addressed store, hash-verified

833 return out
834
835 def _metadata_from(self, package, methods=(), recursive_methods=()) -> set:
836 """
837 Collect metadata whose requirements are implied by given function names.
838
839 Args:
840 package:
841 The module name that must be imported in a source file to trigger the search.
842 methods:
843 Function names from **package** which take a distribution name as an argument and imply that metadata
844 is required for that distribution.
845 recursive_methods:
846 Like **methods** but also implies that a distribution's dependencies' metadata must be collected too.
847 Returns:
848 Required metadata in hook data ``(source, dest)`` format as returned by
849 :func:`PyInstaller.utils.hooks.copy_metadata()`.
850
851 Scan all source code to be included for usage of particular *key* functions which imply that that code will
852 require metadata for some distribution (which may not be its own) at runtime. In the case of a match,
853 collect the required metadata.
854 """
855 from PyInstaller.utils.hooks import copy_metadata
856 from PyInstaller.compat import importlib_metadata
857
858 # Generate sets of possible function names to search for.
859 need_metadata = set()
860 need_recursive_metadata = set()
861 for method in methods:
862 need_metadata.update(bytecode.any_alias(package + "." + method))
863 for method in recursive_methods:
864 need_recursive_metadata.update(bytecode.any_alias(package + "." + method))
865
866 out = set()
867
868 for name, code in self.get_code_using(package).items():
869 for calls in bytecode.recursive_function_calls(code).values():
870 for function_name, args in calls:
871 # Only consider function calls taking one argument.
872 if len(args) != 1:
873 continue
874 package = args[0]
875 try:
876 if function_name in need_metadata:
877 out.update(copy_metadata(package))
878 elif function_name in need_recursive_metadata:
879 out.update(copy_metadata(package, recursive=True))
880
881 except importlib_metadata.PackageNotFoundError:
882 # Currently, we opt to silently skip over missing metadata.
883 continue
884
885 return out
886
887 def get_collected_packages(self) -> list:
888 """

Callers 1

metadata_requiredMethod · 0.95

Calls 3

get_code_usingMethod · 0.95
copy_metadataFunction · 0.90
updateMethod · 0.80

Tested by

no test coverage detected