original_docstring: Returns the python files that |module| is dependent on if module is a
      submodule of fuzzers/. Does not return dependencies that are not submodules
      of fuzzers/, such as std library modules. Has a limit of
      PY_DEPENDENCIES_MAX_DEPTH so that cyclic imports can easily be detected.
      Note that this may not work if a fuzzer.py imports modules dynamically or
      within individual functions. That is ok because we can prevent this during
      code review.
docstring: Returns the python files that |module| is dependent on if module is a
  submodule of fuzzers/. Does not return dependencies that are not submodules
  of fuzzers/, such as std library modules. Has a limit of
  PY_DEPENDENCIES_MAX_DEPTH so that cyclic imports can easily be detected.
  Note that this may not work if a fuzzer.py imports modules dynamically or
  within individual functions. That is ok because we can prevent this during
  code review.
docstring_tokens: Returns the python files that |module| is dependent on if module is a submodule of fuzzers / . Does not return dependencies that are not submodules of fuzzers / such as std library modules . Has a limit of PY_DEPENDENCIES_MAX_DEPTH so that cyclic imports can easily be detected . Note that this may not work if a fuzzer . py imports modules dynamically or within individual functions . That is ok because we can prevent this during code review .
code: def _get_python_dependencies(module: types.ModuleType,
                               depth: int = 0) -> Set[str]:
      """Returns the python files that |module| is dependent on if module is a
      submodule of fuzzers/. Does not return dependencies that are not submodules
      of fuzzers/, such as std library modules. Has a limit of
      PY_DEPENDENCIES_MAX_DEPTH so that cyclic imports can easily be detected.
      Note that this may not work if a fuzzer.py imports modules dynamically or
      within individual functions. That is ok because we can prevent this during
      code review."""
      if depth > PY_DEPENDENCIES_MAX_DEPTH:
          # Enforce a depth to catch cyclic imports.
          format_string = ('Depth: {depth} greater than max: {max_depth}. '
                           'Probably a cyclic import in {module}.')
          raise Exception(
              format_string.format(depth=depth,
                                   max_depth=PY_DEPENDENCIES_MAX_DEPTH,
                                   module=module))
  
      module_path = inspect.getfile(module)
  
      # Just get the dependencies from the cache if we have them.
      # This would break on modules doing abnormal things like writing Python
      # files and then importing them, code review should prevent that from
      # landing though.
      if module_path in PY_DEPENDENCIES_CACHE:
          return PY_DEPENDENCIES_CACHE[module_path]
  
      # Modules depend on themselves.
      dependencies = {module_path}
  
      # This assumes that every module that |module| depends on is imported in
      # top-level code.
      attr_names = dir(module)
      for attr_name in attr_names:
          # Check if attr_name is a module, bail if not.
          imported_module = getattr(module, attr_name)
          if not isinstance(imported_module, types.ModuleType):
              continue
  
          # Files in fuzzers/ can only import code from the Python standard
          # library modules and modules in fuzzers/.
          if is_fuzzers_submodule(imported_module):
              imported_module_path = inspect.getfile(imported_module)
              dependencies.add(imported_module_path)
              # Now recur to get the dependencies of the dependency.
              dependencies = dependencies.union(
                  _get_python_dependencies(imported_module, depth + 1))
  
      PY_DEPENDENCIES_CACHE[module_path] = dependencies
      return dependencies
code_tokens: def _get_python_dependencies ( module : types . ModuleType , depth : int = 0 ) -> Set [ str ] : if depth > PY_DEPENDENCIES_MAX_DEPTH : format_string = ( 'Depth: {depth} greater than max: {max_depth}. ' 'Probably a cyclic import in {module}.' ) raise Exception ( format_string . format ( depth = depth , max_depth = PY_DEPENDENCIES_MAX_DEPTH , module = module ) ) module_path = inspect . getfile ( module ) if module_path in PY_DEPENDENCIES_CACHE : return PY_DEPENDENCIES_CACHE [ module_path ] dependencies = { module_path } attr_names = dir ( module ) for attr_name in attr_names : imported_module = getattr ( module , attr_name ) if not isinstance ( imported_module , types . ModuleType ) : continue if is_fuzzers_submodule ( imported_module ) : imported_module_path = inspect . getfile ( imported_module ) dependencies . add ( imported_module_path ) dependencies = dependencies . union ( _get_python_dependencies ( imported_module , depth + 1 ) ) PY_DEPENDENCIES_CACHE [ module_path ] = dependencies return dependencies
short_docstring: Returns the python files that |module| is dependent on if module is a
  submodule of fuzzers/.
short_docstring_tokens: Returns the python files that |module| is dependent on if module is a submodule of fuzzers / .
comment: """Returns the python files that |module| is dependent on if module is a
      submodule of fuzzers/. Does not return dependencies that are not submodules
      of fuzzers/, such as std library modules. Has a limit of
      PY_DEPENDENCIES_MAX_DEPTH so that cyclic imports can easily be detected.
      Note that this may not work if a fuzzer.py imports modules dynamically or
      within individual functions. That is ok because we can prevent this during
      code review."""$SEP$# Enforce a depth to catch cyclic imports.$SEP$# Just get the dependencies from the cache if we have them.$SEP$# This would break on modules doing abnormal things like writing Python$SEP$# files and then importing them, code review should prevent that from$SEP$# landing though.$SEP$# Modules depend on themselves.$SEP$# This assumes that every module that |module| depends on is imported in$SEP$# top-level code.$SEP$# Check if attr_name is a module, bail if not.$SEP$# Files in fuzzers/ can only import code from the Python standard$SEP$# library modules and modules in fuzzers/.$SEP$# Now recur to get the dependencies of the dependency.