codekingpro/portable-devtools
114k
1"""distutils.command.bdist_dumb2 3Implements the Distutils 'bdist_dumb' command (create a "dumb" built4distribution -- i.e., just an archive to be unpacked under $prefix or5$exec_prefix)."""6 7import os8from distutils._log import log9 10from ..core import Command11from ..dir_util import ensure_relative, remove_tree12from ..errors import DistutilsPlatformError13from ..sysconfig import get_python_version14from ..util import get_platform15 16 17class bdist_dumb(Command):18 description = "create a \"dumb\" built distribution"19 20 user_options = [21 ('bdist-dir=', 'd', "temporary directory for creating the distribution"),22 (23 'plat-name=',24 'p',25 "platform name to embed in generated filenames "26 "(default: %s)" % get_platform(),27 ),28 (29 'format=',30 'f',31 "archive format to create (tar, gztar, bztar, xztar, ztar, zip)",32 ),33 (34 'keep-temp',35 'k',36 "keep the pseudo-installation tree around after "37 + "creating the distribution archive",38 ),39 ('dist-dir=', 'd', "directory to put final built distributions in"),40 ('skip-build', None, "skip rebuilding everything (for testing/debugging)"),41 (42 'relative',43 None,44 "build the archive using relative paths (default: false)",45 ),46 (47 'owner=',48 'u',49 "Owner name used when creating a tar file [default: current user]",50 ),51 (52 'group=',53 'g',54 "Group name used when creating a tar file [default: current group]",55 ),56 ]57 58 boolean_options = ['keep-temp', 'skip-build', 'relative']59 60 default_format = {'posix': 'gztar', 'nt': 'zip'}61 62 def initialize_options(self):63 self.bdist_dir = None64 self.plat_name = None65 self.format = None66 self.keep_temp = 067 self.dist_dir = None68 self.skip_build = None69 self.relative = 070 self.owner = None71 self.group = None72 73 def finalize_options(self):74 if self.bdist_dir is None:75 bdist_base = self.get_finalized_command('bdist').bdist_base76 self.bdist_dir = os.path.join(bdist_base, 'dumb')77 78 if self.format is None:79 try:80 self.format = self.default_format[os.name]81 except KeyError:82 raise DistutilsPlatformError(83 "don't know how to create dumb built distributions "84 "on platform %s" % os.name85 )86 87 self.set_undefined_options(88 'bdist',89 ('dist_dir', 'dist_dir'),90 ('plat_name', 'plat_name'),91 ('skip_build', 'skip_build'),92 )93 94 def run(self):95 if not self.skip_build:96 self.run_command('build')97 98 install = self.reinitialize_command('install', reinit_subcommands=1)99 install.root = self.bdist_dir100 install.skip_build = self.skip_build101 install.warn_dir = 0102 103 log.info("installing to %s", self.bdist_dir)104 self.run_command('install')105 106 # And make an archive relative to the root of the107 # pseudo-installation tree.108 archive_basename = f"{self.distribution.get_fullname()}.{self.plat_name}"109 110 pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)111 if not self.relative:112 archive_root = self.bdist_dir113 else:114 if self.distribution.has_ext_modules() and (115 install.install_base != install.install_platbase116 ):117 raise DistutilsPlatformError(118 "can't make a dumb built distribution where "119 f"base and platbase are different ({repr(install.install_base)}, {repr(install.install_platbase)})"120 )121 else:122 archive_root = os.path.join(123 self.bdist_dir, ensure_relative(install.install_base)124 )125 126 # Make the archive127 filename = self.make_archive(128 pseudoinstall_root,129 self.format,130 root_dir=archive_root,131 owner=self.owner,132 group=self.group,133 )134 if self.distribution.has_ext_modules():135 pyversion = get_python_version()136 else:137 pyversion = 'any'138 self.distribution.dist_files.append(('bdist_dumb', pyversion, filename))139 140 if not self.keep_temp:141 remove_tree(self.bdist_dir, dry_run=self.dry_run)142 