diff options
author | PJ Eby <distutils-sig@python.org> | 2005-07-06 01:37:41 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-07-06 01:37:41 +0000 |
commit | 4a63bc6f16d3a4616edae1403f3c7bd67bdfa2f3 (patch) | |
tree | a05511b2347181383b54655a960d9e2ecd77458a | |
parent | 52928dfe183fcd7e7e5684914522b1da47938ae1 (diff) | |
download | external_python_setuptools-4a63bc6f16d3a4616edae1403f3c7bd67bdfa2f3.tar.gz external_python_setuptools-4a63bc6f16d3a4616edae1403f3c7bd67bdfa2f3.tar.bz2 external_python_setuptools-4a63bc6f16d3a4616edae1403f3c7bd67bdfa2f3.zip |
Added ``egg_info`` command to ``setuptools``-based packages. This command
just creates or updates the "projectname.egg-info" directory, without
building an egg. It's used by the ``bdist_egg`` command now, and will be
used by the ``test`` and ``develop`` commands later on.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041077
-rwxr-xr-x | EasyInstall.txt | 6 | ||||
-rw-r--r-- | setuptools/command/bdist_egg.py | 155 | ||||
-rwxr-xr-x | setuptools/command/egg_info.py | 164 |
3 files changed, 227 insertions, 98 deletions
diff --git a/EasyInstall.txt b/EasyInstall.txt index 1ce7b459..8227b530 100755 --- a/EasyInstall.txt +++ b/EasyInstall.txt @@ -481,6 +481,12 @@ Known Issues * There's no automatic retry for borked Sourceforge mirrors, which can easily time out or be missing a file. +0.5a5 + * Added ``egg_info`` command to ``setuptools``-based packages. This command + just creates or updates the "projectname.egg-info" directory, without + building an egg. It's used by the ``bdist_egg`` command now, and will be + used by the ``test`` and ``develop`` commands later on. + 0.5a4 * Added ``--always-copy/-a`` option to always copy needed packages to the installation directory, even if they're already present elsewhere on 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 - - diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py new file mode 100755 index 00000000..b35e1956 --- /dev/null +++ b/setuptools/command/egg_info.py @@ -0,0 +1,164 @@ +"""setuptools.command.egg_info + +Create a distribution's .egg-info directory and contents""" + +# This module should be kept compatible with Python 2.3 +import os +from setuptools import Command +from distutils.errors import * +from distutils import log +from pkg_resources import parse_requirements, safe_name, \ + safe_version, yield_lines + + +class egg_info(Command): + + description = "create a distribution's .egg-info directory" + + user_options = [ + ('egg-base=', 'e', "directory containing .egg-info directories" + " (default: top of the source tree)"), + ('tag-svn-revision', 'r', + "Add subversion revision ID to version number"), + ('tag-date', 'd', "Add date stamp (e.g. 20050528) to version number"), + ('tag-build=', 'b', "Specify explicit tag to add to version number"), + ] + + boolean_options = ['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.tag_build = None + self.tag_svn_revision = 0 + self.tag_date = 0 + + + + + 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('',os.curdir) + + self.ensure_dirname('egg_base') + self.egg_info = os.path.join(self.egg_base, self.egg_name+'.egg-info') + + + + + + + + + + + + + + + + + + + + + + def run(self): + # Make the .egg-info directory, then write PKG-INFO and requires.txt + self.mkpath(self.egg_info) + + 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 + + self.write_requirements() + if os.path.exists(os.path.join(self.egg_info,'depends.txt')): + log.warn( + "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n" + "Use the install_requires/extras_require setup() args instead." + ) + + + 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 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) + + + + + + + + + + + + + + + + + + |