Commits

Daniel Holth committed 47726e9 Draft

root of wheel can be either platlib or purelib

  • Participants
  • Parent commits 5fb9cc7

Comments (0)

Files changed (1)

Lib/packaging/command/bdist_wheel.py

 import sys
 import sysconfig
 from shutil import rmtree
-from sysconfig import get_python_version
 
 from packaging.util import get_platform
 from packaging.command.cmd import Command
 
 class bdist_wheel(Command):
 
-    description = 'create a wheel of cheese'
+    description = 'create a wheel distribution'
 
     user_options = [('bdist-dir=', 'd',
                      "temporary directory for creating the distribution"),
         self.format = 'zip'
         self.keep_temp = False
         self.dist_dir = None
+        self.distinfo_dir = None
+        self.root_is_purelib = None
         self.skip_build = None
         self.relative = False
         self.owner = None
     def finalize_options(self):
         if self.bdist_dir is None:
             bdist_base = self.get_finalized_command('bdist').bdist_base
-            self.bdist_dir = os.path.join(bdist_base, 'simple')
+            self.bdist_dir = os.path.join(bdist_base, 'wheel')
              
         self.data_dir = os.path.join(self.bdist_dir, 
                                      self.distribution.get_fullname() + '.data')
         
         self.set_undefined_options('bdist',
                                    'dist_dir', 'plat_name', 'skip_build')
+        
+        self.root_is_purelib = self.distribution.is_pure()        
 
     def get_abbr_impl(self):
         """Return abbreviated implementation name"""
             plat_name = 'noarch'
             impl_name = 'py'
         else:
-            plat_name = self.plat_name.replace('-', '_')
+            plat_name = self.plat_name.replace('-', '_').replace('.', '_')
             impl_name = self.get_abbr_impl()
         nodot = sysconfig.get_config_var("py_version_nodot")
         archive_basename = "%s-%s-%s" % (
         install.skip_build = self.skip_build
         install.warn_dir = False
 
-        for key in ('purelib', 'platlib'):
-            setattr(install,
-                   'install_' + key,
-                   '.')
-
         # Use a custom scheme for the archive, because we have to decide
         # at installation time which scheme to use.
-        for key in ('headers', 'scripts', 'data'):
+        for key in ('headers', 'scripts', 'data', 'purelib', 'platlib'):
             setattr(install,
                     'install_' + key,
                     os.path.join(self.data_dir, key))
+                        
+        if self.root_is_purelib:
+            setattr(install,
+                   'install_purelib',
+                   '')
+        else:
+            setattr(install,
+                    'install_platlib',
+                    '')
 
         logger.info("installing to %s", self.bdist_dir)
         self.fixup_data_files()
                 archive_root = os.path.join(
                     self.bdist_dir,
                     self._ensure_relative(install.install_base))
+                                    
+        self.set_undefined_options('install_distinfo',
+                                   'distinfo_dir')
+        self.write_wheelfile(self.distinfo_dir)
 
         # Make the archive
         filename = self.make_archive(pseudoinstall_root,
             else:
                 rmtree(self.bdist_dir)
                 
+    def write_wheelfile(self, wheelfile_base):
+        from email.message import Message
+        msg = Message()
+        msg['Wheel-Version'] = '0.1'
+        msg['Packager'] = 'packaging'
+        msg['Root-Is-Purelib'] = str(self.root_is_purelib).lower()                
+        wheelfile_path = os.path.join(wheelfile_base, 'WHEEL')
+        logger.info('creating %s', wheelfile_path)
+        with open(wheelfile_path, 'w', encoding='utf-8') as f:
+            f.write(msg.as_string())        
+                
     def fixup_data_files(self):
         """Put all resources in a .data directory"""        
         data_files = {}