code: def create_package_file(
      root: str,
      master_package: str | None,
      subroot: str,
      py_files: list[str],
      opts: Any,
      subs: list[str],
      is_namespace: bool,
      excludes: Sequence[re.Pattern[str]] = (),
      user_template_dir: str | None = None,
  ) -> None:
      """Build the text of the file and write the file."""
      # build a list of sub packages (directories containing an __init__ file)
      subpackages = [
          module_join(master_package, subroot, pkgname)
          for pkgname in subs
          if not is_skipped_package(
              path.join(root, pkgname), opts, excludes
          )
      ]
      # build a list of sub modules
      submodules = [
          sub.split(".")[0]
          for sub in py_files
          if not is_skipped_module(path.join(root, sub), opts, excludes)
          and not is_initpy(sub)
      ]
      submodules = sorted(set(submodules))
      submodules = [
          module_join(master_package, subroot, modname)
          for modname in submodules
      ]
      options = copy(OPTIONS)
      if opts.includeprivate and "private-members" not in options:
          options.append("private-members")
  
      pkgname = module_join(master_package, subroot)
      context = {
          "pkgname": pkgname,
          "subpackages": subpackages,
          "submodules": submodules,
          "is_namespace": is_namespace,
          "modulefirst": opts.modulefirst,
          "separatemodules": opts.separatemodules,
          "automodule_options": options,
          "show_headings": not opts.noheadings,
          "maxdepth": opts.maxdepth,
      }
      if user_template_dir is not None:
          template_path = [user_template_dir, template_dir]
      else:
          template_path = [template_dir]
      text = ReSTRenderer(template_path).render(
          "package.rst_t", context
      )
      write_file(pkgname, text, opts)
  
      if submodules and opts.separatemodules:
          for submodule in submodules:
              create_module_file(
                  None, submodule, opts, user_template_dir
              )
  
imports: from __future__ import annotations
  import argparse
  import fnmatch
  import glob
  import locale
  import os
  import re
  import sys
  from copy import copy
  from importlib.machinery import EXTENSION_SUFFIXES
  from os import path
  from typing import TYPE_CHECKING, Any
  import sphinx.locale
  from sphinx import __display_version__, package_dir
  from sphinx.cmd.quickstart import EXTENSIONS
  from sphinx.locale import __
  from sphinx.util import logging
  from sphinx.util.osutil import FileAvoidWrite, ensuredir
  from sphinx.util.template import ReSTRenderer
label_desc: Use image node_id 6 for calling a global function with example usage: create_package_file(root, master_package, subroot, py_files, opts, subs, is_namespace, excludes, user_template_dir) without return types