Path: blob/main/test/lib/python3.9/site-packages/setuptools/_distutils/command/bdist.py
4804 views
"""distutils.command.bdist12Implements the Distutils 'bdist' command (create a built [binary]3distribution)."""45import os6from distutils.core import Command7from distutils.errors import *8from distutils.util import get_platform91011def show_formats():12"""Print list of available formats (arguments to "--format" option).13"""14from distutils.fancy_getopt import FancyGetopt15formats = []16for format in bdist.format_commands:17formats.append(("formats=" + format, None,18bdist.format_command[format][1]))19pretty_printer = FancyGetopt(formats)20pretty_printer.print_help("List of available distribution formats:")212223class bdist(Command):2425description = "create a built (binary) distribution"2627user_options = [('bdist-base=', 'b',28"temporary directory for creating built distributions"),29('plat-name=', 'p',30"platform name to embed in generated filenames "31"(default: %s)" % get_platform()),32('formats=', None,33"formats for distribution (comma-separated list)"),34('dist-dir=', 'd',35"directory to put final built distributions in "36"[default: dist]"),37('skip-build', None,38"skip rebuilding everything (for testing/debugging)"),39('owner=', 'u',40"Owner name used when creating a tar file"41" [default: current user]"),42('group=', 'g',43"Group name used when creating a tar file"44" [default: current group]"),45]4647boolean_options = ['skip-build']4849help_options = [50('help-formats', None,51"lists available distribution formats", show_formats),52]5354# The following commands do not take a format option from bdist55no_format_option = ('bdist_rpm',)5657# This won't do in reality: will need to distinguish RPM-ish Linux,58# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.59default_format = {'posix': 'gztar',60'nt': 'zip'}6162# Establish the preferred order (for the --help-formats option).63format_commands = ['rpm', 'gztar', 'bztar', 'xztar', 'ztar', 'tar',64'wininst', 'zip', 'msi']6566# And the real information.67format_command = {'rpm': ('bdist_rpm', "RPM distribution"),68'gztar': ('bdist_dumb', "gzip'ed tar file"),69'bztar': ('bdist_dumb', "bzip2'ed tar file"),70'xztar': ('bdist_dumb', "xz'ed tar file"),71'ztar': ('bdist_dumb', "compressed tar file"),72'tar': ('bdist_dumb', "tar file"),73'wininst': ('bdist_wininst',74"Windows executable installer"),75'zip': ('bdist_dumb', "ZIP file"),76'msi': ('bdist_msi', "Microsoft Installer")77}787980def initialize_options(self):81self.bdist_base = None82self.plat_name = None83self.formats = None84self.dist_dir = None85self.skip_build = 086self.group = None87self.owner = None8889def finalize_options(self):90# have to finalize 'plat_name' before 'bdist_base'91if self.plat_name is None:92if self.skip_build:93self.plat_name = get_platform()94else:95self.plat_name = self.get_finalized_command('build').plat_name9697# 'bdist_base' -- parent of per-built-distribution-format98# temporary directories (eg. we'll probably have99# "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)100if self.bdist_base is None:101build_base = self.get_finalized_command('build').build_base102self.bdist_base = os.path.join(build_base,103'bdist.' + self.plat_name)104105self.ensure_string_list('formats')106if self.formats is None:107try:108self.formats = [self.default_format[os.name]]109except KeyError:110raise DistutilsPlatformError(111"don't know how to create built distributions "112"on platform %s" % os.name)113114if self.dist_dir is None:115self.dist_dir = "dist"116117def run(self):118# Figure out which sub-commands we need to run.119commands = []120for format in self.formats:121try:122commands.append(self.format_command[format][0])123except KeyError:124raise DistutilsOptionError("invalid format '%s'" % format)125126# Reinitialize and run each command.127for i in range(len(self.formats)):128cmd_name = commands[i]129sub_cmd = self.reinitialize_command(cmd_name)130if cmd_name not in self.no_format_option:131sub_cmd.format = self.formats[i]132133# passing the owner and group names for tar archiving134if cmd_name == 'bdist_dumb':135sub_cmd.owner = self.owner136sub_cmd.group = self.group137138# If we're going to need to run this command again, tell it to139# keep its temporary files around so subsequent runs go faster.140if cmd_name in commands[i+1:]:141sub_cmd.keep_temp = 1142self.run_command(cmd_name)143144145