python (3.11.7)

(root)/
lib/
python3.11/
site-packages/
pip/
_internal/
commands/
freeze.py
       1  import sys
       2  from optparse import Values
       3  from typing import AbstractSet, List
       4  
       5  from pip._internal.cli import cmdoptions
       6  from pip._internal.cli.base_command import Command
       7  from pip._internal.cli.status_codes import SUCCESS
       8  from pip._internal.operations.freeze import freeze
       9  from pip._internal.utils.compat import stdlib_pkgs
      10  
      11  
      12  def _should_suppress_build_backends() -> bool:
      13      return sys.version_info < (3, 12)
      14  
      15  
      16  def _dev_pkgs() -> AbstractSet[str]:
      17      pkgs = {"pip"}
      18  
      19      if _should_suppress_build_backends():
      20          pkgs |= {"setuptools", "distribute", "wheel"}
      21  
      22      return pkgs
      23  
      24  
      25  class ESC[4;38;5;81mFreezeCommand(ESC[4;38;5;149mCommand):
      26      """
      27      Output installed packages in requirements format.
      28  
      29      packages are listed in a case-insensitive sorted order.
      30      """
      31  
      32      usage = """
      33        %prog [options]"""
      34      log_streams = ("ext://sys.stderr", "ext://sys.stderr")
      35  
      36      def add_options(self) -> None:
      37          self.cmd_opts.add_option(
      38              "-r",
      39              "--requirement",
      40              dest="requirements",
      41              action="append",
      42              default=[],
      43              metavar="file",
      44              help=(
      45                  "Use the order in the given requirements file and its "
      46                  "comments when generating output. This option can be "
      47                  "used multiple times."
      48              ),
      49          )
      50          self.cmd_opts.add_option(
      51              "-l",
      52              "--local",
      53              dest="local",
      54              action="store_true",
      55              default=False,
      56              help=(
      57                  "If in a virtualenv that has global access, do not output "
      58                  "globally-installed packages."
      59              ),
      60          )
      61          self.cmd_opts.add_option(
      62              "--user",
      63              dest="user",
      64              action="store_true",
      65              default=False,
      66              help="Only output packages installed in user-site.",
      67          )
      68          self.cmd_opts.add_option(cmdoptions.list_path())
      69          self.cmd_opts.add_option(
      70              "--all",
      71              dest="freeze_all",
      72              action="store_true",
      73              help=(
      74                  "Do not skip these packages in the output:"
      75                  " {}".format(", ".join(_dev_pkgs()))
      76              ),
      77          )
      78          self.cmd_opts.add_option(
      79              "--exclude-editable",
      80              dest="exclude_editable",
      81              action="store_true",
      82              help="Exclude editable package from output.",
      83          )
      84          self.cmd_opts.add_option(cmdoptions.list_exclude())
      85  
      86          self.parser.insert_option_group(0, self.cmd_opts)
      87  
      88      def run(self, options: Values, args: List[str]) -> int:
      89          skip = set(stdlib_pkgs)
      90          if not options.freeze_all:
      91              skip.update(_dev_pkgs())
      92  
      93          if options.excludes:
      94              skip.update(options.excludes)
      95  
      96          cmdoptions.check_list_path_option(options)
      97  
      98          for line in freeze(
      99              requirement=options.requirements,
     100              local_only=options.local,
     101              user_only=options.user,
     102              paths=options.path,
     103              isolated=options.isolated_mode,
     104              skip=skip,
     105              exclude_editable=options.exclude_editable,
     106          ):
     107              sys.stdout.write(line + "\n")
     108          return SUCCESS