Commit 4a63bc6f authored by PJ Eby's avatar PJ Eby

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
parent 52928dfe
...@@ -481,6 +481,12 @@ Known Issues ...@@ -481,6 +481,12 @@ Known Issues
* There's no automatic retry for borked Sourceforge mirrors, which can easily * There's no automatic retry for borked Sourceforge mirrors, which can easily
time out or be missing a file. 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 0.5a4
* Added ``--always-copy/-a`` option to always copy needed packages to the * Added ``--always-copy/-a`` option to always copy needed packages to the
installation directory, even if they're already present elsewhere on installation directory, even if they're already present elsewhere on
......
...@@ -5,13 +5,10 @@ Build .egg distributions""" ...@@ -5,13 +5,10 @@ Build .egg distributions"""
# This module should be kept compatible with Python 2.3 # This module should be kept compatible with Python 2.3
import os import os
from setuptools import Command from setuptools import Command
from distutils.util import get_platform from distutils.dir_util import remove_tree, mkpath
from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath
from distutils.sysconfig import get_python_version, get_python_lib from distutils.sysconfig import get_python_version, get_python_lib
from distutils.errors import *
from distutils import log from distutils import log
from pkg_resources import parse_requirements, get_platform, safe_name, \ from pkg_resources import get_platform, Distribution
safe_version, Distribution, yield_lines
def write_stub(resource, pyfile): def write_stub(resource, pyfile):
...@@ -39,17 +36,16 @@ def write_stub(resource, pyfile): ...@@ -39,17 +36,16 @@ def write_stub(resource, pyfile):
class bdist_egg(Command): class bdist_egg(Command):
description = "create an \"egg\" distribution" description = "create an \"egg\" distribution"
user_options = [ user_options = [
('egg-base=', 'e', "directory containing .egg-info directories"
" (default: top of the source tree)"),
('bdist-dir=', 'd', ('bdist-dir=', 'd',
"temporary directory for creating the distribution"), "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', ('plat-name=', 'p',
"platform name to embed in generated filenames " "platform name to embed in generated filenames "
"(default: %s)" % get_platform()), "(default: %s)" % get_platform()),
...@@ -61,48 +57,47 @@ class bdist_egg(Command): ...@@ -61,48 +57,47 @@ class bdist_egg(Command):
('skip-build', None, ('skip-build', None,
"skip rebuilding everything (for testing/debugging)"), "skip rebuilding everything (for testing/debugging)"),
] ]
boolean_options = [ boolean_options = [
'keep-temp', 'skip-build', 'relative','tag-date','tag-svn-revision' 'keep-temp', 'skip-build', 'relative','tag-date','tag-svn-revision'
] ]
def initialize_options (self): 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.bdist_dir = None
self.plat_name = None self.plat_name = None
self.keep_temp = 0 self.keep_temp = 0
self.dist_dir = None self.dist_dir = None
self.skip_build = 0 self.skip_build = 0
self.tag_build = None
self.tag_svn_revision = 0
self.tag_date = 0
self.egg_output = None 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( def finalize_options(self):
self.egg_base, self.egg_name+'.egg-info' ei_cmd = self.get_finalized_command("egg_info")
) self.egg_info = ei_cmd.egg_info
if self.bdist_dir is None: if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'egg') self.bdist_dir = os.path.join(bdist_base, 'egg')
if self.plat_name is None: if self.plat_name is None:
self.plat_name = get_platform() self.plat_name = get_platform()
...@@ -112,7 +107,7 @@ class bdist_egg(Command): ...@@ -112,7 +107,7 @@ class bdist_egg(Command):
# Compute filename of the output egg # Compute filename of the output egg
basename = Distribution( basename = Distribution(
None, None, self.egg_name, self.egg_version, None, None, ei_cmd.egg_name, ei_cmd.egg_version,
get_python_version(), get_python_version(),
self.distribution.has_ext_modules() and self.plat_name self.distribution.has_ext_modules() and self.plat_name
).egg_name() ).egg_name()
...@@ -121,6 +116,11 @@ class bdist_egg(Command): ...@@ -121,6 +116,11 @@ class bdist_egg(Command):
def do_install_data(self): def do_install_data(self):
# Hack for packages that install data to install's --install-lib # 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
...@@ -146,23 +146,26 @@ class bdist_egg(Command): ...@@ -146,23 +146,26 @@ class bdist_egg(Command):
finally: finally:
self.distribution.data_files = old self.distribution.data_files = old
def get_outputs(self): def get_outputs(self):
return [self.egg_output] return [self.egg_output]
def write_requirements(self):
dist = self.distribution def call_command(self,cmdname,**kw):
if not getattr(dist,'install_requires',None) and \ """Invoke reinitialized command `cmdname` with keyword args"""
not getattr(dist,'extras_require',None): return for dirname in INSTALL_DIRECTORY_ATTRS:
requires = os.path.join(self.egg_info,"requires.txt") kw.setdefault(dirname,self.bdist_dir)
log.info("writing %s", requires) kw.setdefault('skip_build',self.skip_build)
if not self.dry_run: kw.setdefault('dry_run', self.dry_run)
f = open(requires, 'wt') cmd = self.reinitialize_command(cmdname, **kw)
f.write('\n'.join(yield_lines(dist.install_requires))) self.run_command(cmdname)
for extra,reqs in dist.extras_require.items(): return cmd
f.write('\n\n[%s]\n%s' % (extra, '\n'.join(yield_lines(reqs))))
f.close()
def run(self): def run(self):
# Generate metadata first
self.run_command("egg_info")
# 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.
...@@ -193,24 +196,12 @@ class bdist_egg(Command): ...@@ -193,24 +196,12 @@ class bdist_egg(Command):
archive_root = self.bdist_dir archive_root = self.bdist_dir
egg_info = os.path.join(archive_root,'EGG-INFO') egg_info = os.path.join(archive_root,'EGG-INFO')
self.mkpath(egg_info) self.mkpath(egg_info)
self.mkpath(self.egg_info)
if self.distribution.scripts: if self.distribution.scripts:
script_dir = os.path.join(egg_info, 'scripts') script_dir = os.path.join(egg_info, 'scripts')
log.info("installing scripts to %s" % script_dir) log.info("installing scripts to %s" % script_dir)
self.call_command('install_scripts', install_dir=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") native_libs = os.path.join(self.egg_info,"native_libs.txt")
if ext_outputs: if ext_outputs:
...@@ -235,49 +226,17 @@ class bdist_egg(Command): ...@@ -235,49 +226,17 @@ class bdist_egg(Command):
"WARNING: 'depends.txt' will not be used by setuptools 0.6!\n" "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n"
"Use the install_requires/extras_require setup() args instead." "Use the install_requires/extras_require setup() args instead."
) )
# Make the archive # Make the archive
make_zipfile(self.egg_output, archive_root, verbose=self.verbose, make_zipfile(self.egg_output, 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)
# Add to 'Distribution.dist_files' so that the "upload" command works
getattr(self.distribution,'dist_files',[]).append( getattr(self.distribution,'dist_files',[]).append(
('bdist_egg',get_python_version(),self.egg_output)) ('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
......
"""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)
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