|  | 
|  | 1 | +""" | 
|  | 2 | +Workaround until https://bitbucket.org/pypa/wheel/issues/91/cannot-create-a-file-when-that-file | 
|  | 3 | +is fixed... | 
|  | 4 | +
 | 
|  | 5 | +Only one small patch in the os.name == nt case: | 
|  | 6 | +-            basedir_observed = os.path.join(self.data_dir, '..') | 
|  | 7 | ++            basedir_observed = os.path.join(self.data_dir, '..', '.') | 
|  | 8 | +""" | 
|  | 9 | + | 
|  | 10 | +from wheel.bdist_wheel import bdist_wheel | 
|  | 11 | +from distutils.sysconfig import get_python_version | 
|  | 12 | +from distutils import log as logger | 
|  | 13 | +from wheel.archive import archive_wheelfile | 
|  | 14 | +import subprocess | 
|  | 15 | +import os | 
|  | 16 | +from shutil import rmtree | 
|  | 17 | + | 
|  | 18 | +class patched_bdist_wheel(bdist_wheel): | 
|  | 19 | + | 
|  | 20 | +    def run(self): | 
|  | 21 | +        build_scripts = self.reinitialize_command('build_scripts') | 
|  | 22 | +        build_scripts.executable = 'python' | 
|  | 23 | + | 
|  | 24 | +        if not self.skip_build: | 
|  | 25 | +            self.run_command('build') | 
|  | 26 | + | 
|  | 27 | +        install = self.reinitialize_command('install', | 
|  | 28 | +                                            reinit_subcommands=True) | 
|  | 29 | +        install.root = self.bdist_dir | 
|  | 30 | +        install.compile = False | 
|  | 31 | +        install.skip_build = self.skip_build | 
|  | 32 | +        install.warn_dir = False | 
|  | 33 | + | 
|  | 34 | +        # A wheel without setuptools scripts is more cross-platform. | 
|  | 35 | +        # Use the (undocumented) `no_ep` option to setuptools' | 
|  | 36 | +        # install_scripts command to avoid creating entry point scripts. | 
|  | 37 | +        install_scripts = self.reinitialize_command('install_scripts') | 
|  | 38 | +        install_scripts.no_ep = True | 
|  | 39 | + | 
|  | 40 | +        # Use a custom scheme for the archive, because we have to decide | 
|  | 41 | +        # at installation time which scheme to use. | 
|  | 42 | +        for key in ('headers', 'scripts', 'data', 'purelib', 'platlib'): | 
|  | 43 | +            setattr(install, | 
|  | 44 | +                    'install_' + key, | 
|  | 45 | +                    os.path.join(self.data_dir, key)) | 
|  | 46 | + | 
|  | 47 | +        basedir_observed = '' | 
|  | 48 | + | 
|  | 49 | +        if os.name == 'nt': | 
|  | 50 | +            # win32 barfs if any of these are ''; could be '.'? | 
|  | 51 | +            # (distutils.command.install:change_roots bug) | 
|  | 52 | +            # PATCHED... | 
|  | 53 | +            basedir_observed = os.path.join(self.data_dir, '..', '.') | 
|  | 54 | +            self.install_libbase = self.install_lib = basedir_observed | 
|  | 55 | + | 
|  | 56 | +        setattr(install, | 
|  | 57 | +                'install_purelib' if self.root_is_pure else 'install_platlib', | 
|  | 58 | +                basedir_observed) | 
|  | 59 | + | 
|  | 60 | +        logger.info("installing to %s", self.bdist_dir) | 
|  | 61 | + | 
|  | 62 | +        self.run_command('install') | 
|  | 63 | + | 
|  | 64 | +        archive_basename = self.get_archive_basename() | 
|  | 65 | + | 
|  | 66 | +        pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) | 
|  | 67 | +        if not self.relative: | 
|  | 68 | +            archive_root = self.bdist_dir | 
|  | 69 | +        else: | 
|  | 70 | +            archive_root = os.path.join( | 
|  | 71 | +                self.bdist_dir, | 
|  | 72 | +                self._ensure_relative(install.install_base)) | 
|  | 73 | + | 
|  | 74 | +        self.set_undefined_options( | 
|  | 75 | +            'install_egg_info', ('target', 'egginfo_dir')) | 
|  | 76 | +        self.distinfo_dir = os.path.join(self.bdist_dir, | 
|  | 77 | +                                         '%s.dist-info' % self.wheel_dist_name) | 
|  | 78 | +        self.egg2dist(self.egginfo_dir, | 
|  | 79 | +                      self.distinfo_dir) | 
|  | 80 | + | 
|  | 81 | +        self.write_wheelfile(self.distinfo_dir) | 
|  | 82 | + | 
|  | 83 | +        self.write_record(self.bdist_dir, self.distinfo_dir) | 
|  | 84 | + | 
|  | 85 | +        # Make the archive | 
|  | 86 | +        if not os.path.exists(self.dist_dir): | 
|  | 87 | +            os.makedirs(self.dist_dir) | 
|  | 88 | +        wheel_name = archive_wheelfile(pseudoinstall_root, archive_root) | 
|  | 89 | + | 
|  | 90 | +        # Sign the archive | 
|  | 91 | +        if 'WHEEL_TOOL' in os.environ: | 
|  | 92 | +            subprocess.call([os.environ['WHEEL_TOOL'], 'sign', wheel_name]) | 
|  | 93 | + | 
|  | 94 | +        # Add to 'Distribution.dist_files' so that the "upload" command works | 
|  | 95 | +        getattr(self.distribution, 'dist_files', []).append( | 
|  | 96 | +            ('bdist_wheel', get_python_version(), wheel_name)) | 
|  | 97 | + | 
|  | 98 | +        if not self.keep_temp: | 
|  | 99 | +            if self.dry_run: | 
|  | 100 | +                logger.info('removing %s', self.bdist_dir) | 
|  | 101 | +            else: | 
|  | 102 | +                rmtree(self.bdist_dir) | 
|  | 103 | + | 
0 commit comments