python (3.11.7)

(root)/
lib/
python3.11/
distutils/
command/
bdist_dumb.py
       1  """distutils.command.bdist_dumb
       2  
       3  Implements the Distutils 'bdist_dumb' command (create a "dumb" built
       4  distribution -- i.e., just an archive to be unpacked under $prefix or
       5  $exec_prefix)."""
       6  
       7  import os
       8  from distutils.core import Command
       9  from distutils.util import get_platform
      10  from distutils.dir_util import remove_tree, ensure_relative
      11  from distutils.errors import *
      12  from distutils.sysconfig import get_python_version
      13  from distutils import log
      14  
      15  class ESC[4;38;5;81mbdist_dumb(ESC[4;38;5;149mCommand):
      16  
      17      description = "create a \"dumb\" built distribution"
      18  
      19      user_options = [('bdist-dir=', 'd',
      20                       "temporary directory for creating the distribution"),
      21                      ('plat-name=', 'p',
      22                       "platform name to embed in generated filenames "
      23                       "(default: %s)" % get_platform()),
      24                      ('format=', 'f',
      25                       "archive format to create (tar, gztar, bztar, xztar, "
      26                       "ztar, zip)"),
      27                      ('keep-temp', 'k',
      28                       "keep the pseudo-installation tree around after " +
      29                       "creating the distribution archive"),
      30                      ('dist-dir=', 'd',
      31                       "directory to put final built distributions in"),
      32                      ('skip-build', None,
      33                       "skip rebuilding everything (for testing/debugging)"),
      34                      ('relative', None,
      35                       "build the archive using relative paths "
      36                       "(default: false)"),
      37                      ('owner=', 'u',
      38                       "Owner name used when creating a tar file"
      39                       " [default: current user]"),
      40                      ('group=', 'g',
      41                       "Group name used when creating a tar file"
      42                       " [default: current group]"),
      43                     ]
      44  
      45      boolean_options = ['keep-temp', 'skip-build', 'relative']
      46  
      47      default_format = { 'posix': 'gztar',
      48                         'nt': 'zip' }
      49  
      50      def initialize_options(self):
      51          self.bdist_dir = None
      52          self.plat_name = None
      53          self.format = None
      54          self.keep_temp = 0
      55          self.dist_dir = None
      56          self.skip_build = None
      57          self.relative = 0
      58          self.owner = None
      59          self.group = None
      60  
      61      def finalize_options(self):
      62          if self.bdist_dir is None:
      63              bdist_base = self.get_finalized_command('bdist').bdist_base
      64              self.bdist_dir = os.path.join(bdist_base, 'dumb')
      65  
      66          if self.format is None:
      67              try:
      68                  self.format = self.default_format[os.name]
      69              except KeyError:
      70                  raise DistutilsPlatformError(
      71                         "don't know how to create dumb built distributions "
      72                         "on platform %s" % os.name)
      73  
      74          self.set_undefined_options('bdist',
      75                                     ('dist_dir', 'dist_dir'),
      76                                     ('plat_name', 'plat_name'),
      77                                     ('skip_build', 'skip_build'))
      78  
      79      def run(self):
      80          if not self.skip_build:
      81              self.run_command('build')
      82  
      83          install = self.reinitialize_command('install', reinit_subcommands=1)
      84          install.root = self.bdist_dir
      85          install.skip_build = self.skip_build
      86          install.warn_dir = 0
      87  
      88          log.info("installing to %s", self.bdist_dir)
      89          self.run_command('install')
      90  
      91          # And make an archive relative to the root of the
      92          # pseudo-installation tree.
      93          archive_basename = "%s.%s" % (self.distribution.get_fullname(),
      94                                        self.plat_name)
      95  
      96          pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
      97          if not self.relative:
      98              archive_root = self.bdist_dir
      99          else:
     100              if (self.distribution.has_ext_modules() and
     101                  (install.install_base != install.install_platbase)):
     102                  raise DistutilsPlatformError(
     103                         "can't make a dumb built distribution where "
     104                         "base and platbase are different (%s, %s)"
     105                         % (repr(install.install_base),
     106                            repr(install.install_platbase)))
     107              else:
     108                  archive_root = os.path.join(self.bdist_dir,
     109                                     ensure_relative(install.install_base))
     110  
     111          # Make the archive
     112          filename = self.make_archive(pseudoinstall_root,
     113                                       self.format, root_dir=archive_root,
     114                                       owner=self.owner, group=self.group)
     115          if self.distribution.has_ext_modules():
     116              pyversion = get_python_version()
     117          else:
     118              pyversion = 'any'
     119          self.distribution.dist_files.append(('bdist_dumb', pyversion,
     120                                               filename))
     121  
     122          if not self.keep_temp:
     123              remove_tree(self.bdist_dir, dry_run=self.dry_run)