[Python-checkins]
python/nondist/sandbox/setuptools/setuptools/command
bdist_egg.py, 1.3, 1.4
pje at users.sourceforge.net
pje at users.sourceforge.net
Tue Mar 22 01:15:06 CET 2005
Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9953/setuptools/command
Modified Files:
bdist_egg.py
Log Message:
Create stub loaders for C extensions, so that the actual dynamic library
can be extracted from the egg.
Index: bdist_egg.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/bdist_egg.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- bdist_egg.py 21 Mar 2005 20:41:57 -0000 1.3
+++ bdist_egg.py 22 Mar 2005 00:15:03 -0000 1.4
@@ -2,7 +2,7 @@
Build .egg distributions"""
-# This module should be kept compatible with Python 2.1
+# This module should be kept compatible with Python 2.3
import os
from distutils.core import Command
@@ -69,7 +69,22 @@
# finalize_options()
+ def write_stub(self, resource, pyfile):
+ f = open(pyfile,'w')
+ f.write('\n'.join([
+ "def __bootstrap__():",
+ " global __bootstrap__, __loader__, __file__",
+ " import sys, pkg_resources",
+ " __file__ = pkg_resources.resource_filename(__name__,%r)"
+ % resource,
+ " del __bootstrap__, __loader__",
+ " reload(sys.modules[__name__])",
+ "__bootstrap__()",
+ "" # terminal \n
+ ]))
+ f.close()
+
def run (self):
if not self.skip_build:
@@ -80,13 +95,32 @@
install.skip_build = self.skip_build
install.warn_dir = 0
+ ext_outputs = \
+ install._mutate_outputs(self.distribution.has_ext_modules(),
+ 'build_ext', 'build_lib',
+ '')
log.info("installing to %s" % self.bdist_dir)
self.run_command('install_lib')
+ to_compile = []
+ for ext_name in ext_outputs:
+ filename,ext = os.path.splitext(ext_name)
+ pyfile = os.path.join(self.bdist_dir, filename + '.py')
+ log.info("creating stub loader for %s" % ext_name)
+ if not self.dry_run:
+ self.write_stub(os.path.basename(ext_name), pyfile)
+ to_compile.append(pyfile)
+
+ if to_compile:
+ install.byte_compile(to_compile)
+
# And make an archive relative to the root of the
# pseudo-installation tree.
- archive_basename = "%s-py%s-%s" % (self.distribution.get_fullname(),
- get_python_version(),self.plat_name)
+ archive_basename = "%s-py%s" % (self.distribution.get_fullname(),
+ get_python_version())
+
+ if ext_outputs:
+ archive_basename += "-" + self.plat_name
# OS/2 objects to any ":" characters in a filename (such as when
# a timestamp is used in a version) so change them to hyphens.
@@ -97,7 +131,7 @@
archive_root = self.bdist_dir
# Make the EGG-INFO directory
- log.info("creating EGG-INFO files")
+ log.info("creating EGG-INFO directory")
egg_info = os.path.join(archive_root,'EGG-INFO')
self.mkpath(egg_info)
@@ -106,10 +140,20 @@
path = os.path.join(self.egg_info,filename)
if os.path.isfile(path):
self.copy_file(path,os.path.join(egg_info,filename))
-
+
+ log.info("writing EGG-INFO/PKG-INFO")
if not self.dry_run:
self.distribution.metadata.write_pkg_info(egg_info)
+ if ext_outputs:
+ log.info("writing EGG-INFO/native_libs.txt")
+ if not self.dry_run:
+ libs_file = open(
+ os.path.join(egg_info,"native_libs.txt"),'wt')
+ libs_file.write('\n'.join(ext_outputs))
+ libs_file.write('\n')
+ libs_file.close()
+
# Make the archive
make_zipfile(pseudoinstall_root+'.egg',
archive_root, verbose=self.verbose,
More information about the Python-checkins
mailing list