Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
bdist_dumb.py142 linesDownload Raw Back to command
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 log9from typing import ClassVar10 11from ..core import Command12from ..dir_util import ensure_relative, remove_tree13from ..errors import DistutilsPlatformError14from ..sysconfig import get_python_version15from ..util import get_platform16 17 18class bdist_dumb(Command):19    description = "create a \"dumb\" built distribution"20 21    user_options = [22        ('bdist-dir=', 'd', "temporary directory for creating the distribution"),23        (24            'plat-name=',25            'p',26            "platform name to embed in generated filenames "27            f"[default: {get_platform()}]",28        ),29        (30            'format=',31            'f',32            "archive format to create (tar, gztar, bztar, xztar, ztar, zip)",33        ),34        (35            'keep-temp',36            'k',37            "keep the pseudo-installation tree around after 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: ClassVar[list[str]] = ['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 = False67        self.dist_dir = None68        self.skip_build = None69        self.relative = False70        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                    f"on platform {os.name}"85                )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=True)99        install.root = self.bdist_dir100        install.skip_build = self.skip_build101        install.warn_dir = False102 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 ({install.install_base!r}, {install.install_platbase!r})"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)142 
codekingpro/portable-devtools · Team Ai