Commit 5bb11a1a authored by PJ Eby's avatar PJ Eby

Package scripts under EGG-INFO/scripts. Refactor subcommand invocations

for less duplication and greater clarity.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041044
parent b9192326
...@@ -96,9 +96,12 @@ class bdist_egg(Command): ...@@ -96,9 +96,12 @@ class bdist_egg(Command):
f.close() f.close()
def do_install_data(self): def do_install_data(self):
# Hack for packages that install data to install's --install-lib
self.get_finalized_command('install').install_lib = self.bdist_dir self.get_finalized_command('install').install_lib = self.bdist_dir
site_packages = os.path.normcase(os.path.realpath(get_python_lib())) site_packages = os.path.normcase(os.path.realpath(get_python_lib()))
old, self.distribution.data_files = self.distribution.data_files,[] old, self.distribution.data_files = self.distribution.data_files,[]
for item in old: for item in old:
if isinstance(item,tuple) and len(item)==2: if isinstance(item,tuple) and len(item)==2:
if os.path.isabs(item[0]): if os.path.isabs(item[0]):
...@@ -110,36 +113,27 @@ class bdist_egg(Command): ...@@ -110,36 +113,27 @@ class bdist_egg(Command):
item = realpath[len(site_packages)+1:], item[1] item = realpath[len(site_packages)+1:], item[1]
# XXX else: raise ??? # XXX else: raise ???
self.distribution.data_files.append(item) self.distribution.data_files.append(item)
try: 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) log.info("installing package data to %s" % self.bdist_dir)
self.run_command('install_data') self.call_command('install_data', force=0, root=None)
finally: finally:
self.distribution.data_files = old self.distribution.data_files = old
def run(self):
if not self.skip_build:
self.run_command('build')
def run(self):
# We run install_lib before install_data, because some data hacks # We run install_lib before install_data, because some data hacks
# pull their data path from the install_lib command. # 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
install.warn_dir = 0
ext_outputs = \
install._mutate_outputs(self.distribution.has_ext_modules(),
'build_ext', 'build_lib',
'')
log.info("installing library code to %s" % self.bdist_dir) log.info("installing library code to %s" % self.bdist_dir)
self.run_command('install_lib') cmd = self.call_command('install_lib', warn_dir=0)
ext_outputs = cmd._mutate_outputs(
self.distribution.has_ext_modules(), 'build_ext', 'build_lib', ''
)
to_compile = [] to_compile = []
for ext_name in ext_outputs: for ext_name in ext_outputs:
filename,ext = os.path.splitext(ext_name) filename,ext = os.path.splitext(ext_name)
pyfile = os.path.join(self.bdist_dir, filename + '.py') pyfile = os.path.join(self.bdist_dir, filename + '.py')
...@@ -149,15 +143,21 @@ class bdist_egg(Command): ...@@ -149,15 +143,21 @@ class bdist_egg(Command):
to_compile.append(pyfile) to_compile.append(pyfile)
if to_compile: if to_compile:
install.byte_compile(to_compile) cmd.byte_compile(to_compile)
if self.distribution.data_files: if self.distribution.data_files:
self.do_install_data() self.do_install_data()
if self.distribution.scripts:
script_dir = os.path.join(self.bdist_dir,'EGG-INFO','scripts')
log.info("installing scripts to %s" % script_dir)
self.call_command('install_scripts', install_dir=script_dir)
# And make an archive relative to the root of the # And make an archive relative to the root of the
# pseudo-installation tree. # pseudo-installation tree.
archive_basename = "%s-%s-py%s" % ( self.egg_name.replace('-','_'), archive_basename = "%s-%s-py%s" % ( self.egg_name.replace('-','_'),
self.egg_version.replace('-','_'), get_python_version()) self.egg_version.replace('-','_'), get_python_version())
if ext_outputs: if ext_outputs:
archive_basename += "-" + self.plat_name archive_basename += "-" + self.plat_name
ext_outputs = [out.replace(os.sep,'/') for out in ext_outputs] ext_outputs = [out.replace(os.sep,'/') for out in ext_outputs]
...@@ -207,7 +207,6 @@ class bdist_egg(Command): ...@@ -207,7 +207,6 @@ class bdist_egg(Command):
make_zipfile(pseudoinstall_root+'.egg', make_zipfile(pseudoinstall_root+'.egg',
archive_root, verbose=self.verbose, archive_root, verbose=self.verbose,
dry_run=self.dry_run) dry_run=self.dry_run)
if not self.keep_temp: if not self.keep_temp:
remove_tree(self.bdist_dir, dry_run=self.dry_run) remove_tree(self.bdist_dir, dry_run=self.dry_run)
...@@ -234,14 +233,23 @@ class bdist_egg(Command): ...@@ -234,14 +233,23 @@ class bdist_egg(Command):
raise RuntimeError("svn info error: %s" % result.strip()) raise RuntimeError("svn info error: %s" % result.strip())
return match.group(1) return match.group(1)
def call_command(self,cmdname,**kw):
cmd = self.reinitialize_command(cmdname)
for dirname in INSTALL_DIRECTORY_ATTRS:
if dirname in cmd.__dict__: # don't overwrite methods!
setattr(cmd,dirname,self.bdist_dir)
cmd.skip_build = self.skip_build
for k,v in kw.items():
setattr(cmd,k,v)
self.run_command(cmdname)
return cmd
# Attribute names of options for commands that might need to be convinced to
# install to the egg build directory
INSTALL_DIRECTORY_ATTRS = [
'install_lib', 'install_dir', 'install_data', 'install_base'
]
def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0):
...@@ -277,11 +285,3 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): ...@@ -277,11 +285,3 @@ def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0):
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