Commit c3e492cc authored by PJ Eby's avatar PJ Eby

Reorganize bdist_egg's handling of 'install_data' to better deal with the

various kludges legacy packages are using to install data in their package
directories.  Some use absolute paths in 'distribution.data_files', while
others create various subclasses of 'install_data', each with their own
way of finding out what directory to use!  So 'bdist_egg' now does all its
'install_lib' activity before 'install_data', and pokes the desired build
directory into a wide variety of places, so that all of the known kludges
so far will work correctly.  It also checks for absolute paths in
'data_files' (carefully working around other packages' 'data_files'
kludges!) and converts them back to relative ones, if they are subpaths of
site-packages.

Clearly, we need to get the word out about 'package_files' in Python 2.4
and above, and suggest using 'setuptools' for Python 2.3.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041028
parent 3dbc1ee1
......@@ -7,7 +7,7 @@ import os
from distutils.core import Command
from distutils.util import get_platform
from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath
from distutils.sysconfig import get_python_version
from distutils.sysconfig import get_python_version, get_python_lib
from distutils.errors import *
from distutils import log
from pkg_resources import parse_requirements, get_platform
......@@ -95,19 +95,39 @@ class bdist_egg(Command):
]))
f.close()
def do_install_data(self):
self.get_finalized_command('install').install_lib = self.bdist_dir
site_packages = os.path.normcase(os.path.realpath(get_python_lib()))
old, self.distribution.data_files = self.distribution.data_files,[]
for item in old:
if isinstance(item,tuple) and len(item)==2:
if os.path.isabs(item[0]):
realpath = os.path.realpath(item[0])
normalized = os.path.normcase(realpath)
if normalized==site_packages or normalized.startswith(
site_packages+os.sep
):
item = realpath[len(site_packages)+1:], item[1]
# XXX else: raise ???
self.distribution.data_files.append(item)
try:
install = self.reinitialize_command('install_data')
# kludge for setups that use a 3-tuple inst_data
install.install_dir = install.install_base = \
install.install_data = install.install_lib = self.bdist_dir
install.force = 0; install.root = None
log.info("installing package data to %s" % self.bdist_dir)
self.run_command('install_data')
finally:
self.distribution.data_files = old
def run(self):
if not self.skip_build:
self.run_command('build')
if self.distribution.data_files:
install = self.reinitialize_command('install_data')
install.install_dir = self.bdist_dir
install.force = 0
install.root = None
log.info("installing package data to %s" % self.bdist_dir)
self.run_command('install_data')
# We run install_lib before install_data, because some data hacks
# pull their data path from the install_lib command.
install = self.reinitialize_command('install_lib', reinit_subcommands=1)
install.install_dir = self.bdist_dir
install.skip_build = self.skip_build
......@@ -120,7 +140,6 @@ class bdist_egg(Command):
log.info("installing library code 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)
......@@ -133,6 +152,9 @@ class bdist_egg(Command):
if to_compile:
install.byte_compile(to_compile)
if self.distribution.data_files:
self.do_install_data()
# And make an archive relative to the root of the
# pseudo-installation tree.
archive_basename = "%s-%s-py%s" % ( self.egg_name.replace('-','_'),
......@@ -213,6 +235,15 @@ class bdist_egg(Command):
return match.group(1)
def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0):
"""Create a zip file from all the files under 'base_dir'. The output
zip file will be named 'base_dir' + ".zip". Uses either the "zipfile"
......@@ -244,3 +275,13 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0):
return zip_filename
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment