diff options
Diffstat (limited to 'setuptools/command/bdist_egg.py')
-rw-r--r-- | setuptools/command/bdist_egg.py | 155 |
1 files changed, 57 insertions, 98 deletions
diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index b21ef741..6cc818d3 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -5,13 +5,10 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 import os from setuptools import Command -from distutils.util import get_platform -from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath +from distutils.dir_util import remove_tree, mkpath 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, safe_name, \ - safe_version, Distribution, yield_lines +from pkg_resources import get_platform, Distribution def write_stub(resource, pyfile): @@ -39,17 +36,16 @@ def write_stub(resource, pyfile): + + + class bdist_egg(Command): + description = "create an \"egg\" distribution" + user_options = [ - ('egg-base=', 'e', "directory containing .egg-info directories" - " (default: top of the source tree)"), ('bdist-dir=', 'd', "temporary directory for creating the distribution"), - ('tag-svn-revision', None, - "Add subversion revision ID to version number"), - ('tag-date', None, "Add date stamp (e.g. 20050528) to version number"), - ('tag-build=', None, "Specify explicit tag to add to version number"), ('plat-name=', 'p', "platform name to embed in generated filenames " "(default: %s)" % get_platform()), @@ -61,48 +57,47 @@ class bdist_egg(Command): ('skip-build', None, "skip rebuilding everything (for testing/debugging)"), ] + boolean_options = [ 'keep-temp', 'skip-build', 'relative','tag-date','tag-svn-revision' ] + + + + + + + + + + + + + + + + + + def initialize_options (self): - self.egg_name = None - self.egg_version = None - self.egg_base = None - self.egg_info = None self.bdist_dir = None self.plat_name = None self.keep_temp = 0 self.dist_dir = None self.skip_build = 0 - self.tag_build = None - self.tag_svn_revision = 0 - self.tag_date = 0 self.egg_output = None - def finalize_options (self): - self.egg_name = safe_name(self.distribution.get_name()) - self.egg_version = self.tagged_version() - try: - list( - parse_requirements('%s==%s' % (self.egg_name,self.egg_version)) - ) - except ValueError: - raise DistutilsOptionError( - "Invalid distribution name or version syntax: %s-%s" % - (self.egg_name,self.egg_version) - ) - if self.egg_base is None: - dirs = self.distribution.package_dir - self.egg_base = (dirs or {}).get('','.') - self.ensure_dirname('egg_base') - self.egg_info = os.path.join( - self.egg_base, self.egg_name+'.egg-info' - ) + + def finalize_options(self): + ei_cmd = self.get_finalized_command("egg_info") + self.egg_info = ei_cmd.egg_info + if self.bdist_dir is None: bdist_base = self.get_finalized_command('bdist').bdist_base self.bdist_dir = os.path.join(bdist_base, 'egg') + if self.plat_name is None: self.plat_name = get_platform() @@ -112,7 +107,7 @@ class bdist_egg(Command): # Compute filename of the output egg basename = Distribution( - None, None, self.egg_name, self.egg_version, + None, None, ei_cmd.egg_name, ei_cmd.egg_version, get_python_version(), self.distribution.has_ext_modules() and self.plat_name ).egg_name() @@ -121,6 +116,11 @@ class bdist_egg(Command): + + + + + 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 @@ -146,26 +146,29 @@ class bdist_egg(Command): finally: self.distribution.data_files = old + def get_outputs(self): return [self.egg_output] - def write_requirements(self): - dist = self.distribution - if not getattr(dist,'install_requires',None) and \ - not getattr(dist,'extras_require',None): return - requires = os.path.join(self.egg_info,"requires.txt") - log.info("writing %s", requires) - if not self.dry_run: - f = open(requires, 'wt') - f.write('\n'.join(yield_lines(dist.install_requires))) - for extra,reqs in dist.extras_require.items(): - f.write('\n\n[%s]\n%s' % (extra, '\n'.join(yield_lines(reqs)))) - f.close() - + + def call_command(self,cmdname,**kw): + """Invoke reinitialized command `cmdname` with keyword args""" + for dirname in INSTALL_DIRECTORY_ATTRS: + kw.setdefault(dirname,self.bdist_dir) + kw.setdefault('skip_build',self.skip_build) + kw.setdefault('dry_run', self.dry_run) + cmd = self.reinitialize_command(cmdname, **kw) + self.run_command(cmdname) + return cmd + + def run(self): + # Generate metadata first + self.run_command("egg_info") + # We run install_lib before install_data, because some data hacks # pull their data path from the install_lib command. - + log.info("installing library code to %s" % self.bdist_dir) cmd = self.call_command('install_lib', warn_dir=0) @@ -193,24 +196,12 @@ class bdist_egg(Command): archive_root = self.bdist_dir egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) - self.mkpath(self.egg_info) if self.distribution.scripts: script_dir = os.path.join(egg_info, 'scripts') log.info("installing scripts to %s" % script_dir) self.call_command('install_scripts', install_dir=script_dir) - self.write_requirements() - log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) - - if not self.dry_run: - metadata = self.distribution.metadata - metadata.version, oldver = self.egg_version, metadata.version - metadata.name, oldname = self.egg_name, metadata.name - try: - metadata.write_pkg_info(self.egg_info) - finally: - metadata.name, metadata.version = oldname, oldver native_libs = os.path.join(self.egg_info,"native_libs.txt") if ext_outputs: @@ -235,49 +226,17 @@ class bdist_egg(Command): "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n" "Use the install_requires/extras_require setup() args instead." ) + # Make the archive make_zipfile(self.egg_output, archive_root, verbose=self.verbose, dry_run=self.dry_run) if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) + # Add to 'Distribution.dist_files' so that the "upload" command works getattr(self.distribution,'dist_files',[]).append( ('bdist_egg',get_python_version(),self.egg_output)) - def tagged_version(self): - version = self.distribution.get_version() - if self.tag_build: - version+='-'+self.tag_build - - if self.tag_svn_revision and os.path.exists('.svn'): - version += '-%s' % self.get_svn_revision() - - if self.tag_date: - import time - version += time.strftime("-%Y%m%d") - - return safe_version(version) - - def get_svn_revision(self): - stdin, stdout = os.popen4("svn info"); stdin.close() - result = stdout.read(); stdout.close() - import re - match = re.search(r'Last Changed Rev: (\d+)', result) - if not match: - raise RuntimeError("svn info error: %s" % result.strip()) - return match.group(1) - - def call_command(self,cmdname,**kw): - """Invoke reinitialized command `cmdname` with keyword args""" - for dirname in INSTALL_DIRECTORY_ATTRS: - kw.setdefault(dirname,self.bdist_dir) - kw.setdefault('skip_build',self.skip_build) - kw.setdefault('dry_run', self.dry_run) - cmd = self.reinitialize_command(cmdname, **kw) - self.run_command(cmdname) - return cmd - - |