Commit 18b9ae1e authored by PJ Eby's avatar PJ Eby

Restructure easy_install as a distutils "Command" object, so that it can

access the distutils configuration and logging infrastructure, and can
"inherit" options from a distutils setup script that wants to use it to
install its own dependencies.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041052
parent 8f64fbe5
......@@ -179,11 +179,39 @@ files or directories.
Reference Manual
================
Configuration Files
-------------------
(New in 0.4a2)
You may specify default options for EasyInstall using the standard
distutils configuration files, under the command heading ``easy_install``.
EasyInstall will look first for a ``setup.cfg`` file in the current directory,
then a ``~/.pydistutils.cfg`` or ``$HOME\\pydistutils.cfg`` (on Unix-like OSes
and Windows, respectively), and finally a ``distutils.cfg`` file in the
``distutils`` package directory. Here's a simple example::
[easy_install]
# set the default location to install packages
install_dir = /home/me/lib/python
# Notice that indentation can be used to continue an option
# value; this is especially useful for the "--find-links"
# option, which tells easy_install to use download links on
# these pages before consulting PyPI:
#
find_links = http://sqlobject.org/
http://peak.telecommunity.com/dist/
See also the current Python documentation on the `use and location of distutils
configuration files <http://docs.python.org/inst/config-syntax.html>`_.
Command-Line Options
--------------------
``--zip, -z``
``--zip-ok, -z``
Enable installing the package as a zip file. This can significantly
increase Python's overall import performance if you're installing to
``site-packages`` and not using the ``--multi`` option, because Python
......@@ -221,11 +249,13 @@ Command-Line Options
which will put the latest installed version of the specified packages on
``sys.path`` for you. (For more advanced uses, like selecting specific
versions and enabling optional dependencies, see the ``pkg_resources`` API
doc.) Note that if you install to a directory other than ``site-packages``,
doc.)
Note that if you install to a directory other than ``site-packages``,
this option is automatically in effect, because ``.pth`` files can only be
used in ``site-packages`` (at least in Python 2.3 and 2.4). So, if you use
the ``--install-dir`` or ``-i`` options, you must also use ``require()`` to
enable packages at runtime
the ``--install-dir`` or ``-d`` option (or they are set via configuration
file(s)) you must also use ``require()`` to enable packages at runtime.
``--install-dir=DIR, -d DIR``
Set the installation directory. It is up to you to ensure that this
......@@ -233,39 +263,53 @@ Command-Line Options
``pkg_resources.require()`` to enable the installed package(s) that you
need.
``--build-directory=DIR, -b DIR`` (New in 0.3a3)
Set the directory used to download, extract, and install the package. The
directory is not cleared before or after installation, so the downloaded
packages and extracted contents will remain there afterwards, allowing you
to read any documentation, examples, scripts, etc. that may have been
included with the source distribution (if any).
(New in 0.4a2) If this option is not directly specified on the command line
or in a distutils configuration file, the distutils default installation
location is used. Normally, this would be the ``site-packages`` directory,
but if you are using distutils configuration files, setting things like
``--prefix`` or ``--install-lib``, then those settings are taken into
account when computing the default directory.
This option can only be used when you are specifying a single installation
URL or filename, so that the installer will not be confused by the presence
of multiple ``setup.py`` files in the build directory.
``--find-links=URL, -f URL`` (Option renamed in 0.4a2)
Scan the specified "download pages" for direct links to downloadable eggs
or source distributions. Any usable packages will be downloaded if they
are required by a command line argument. For example, this::
``--scan-url=URL, -s URL`` (New in 0.4a1)
Scan the specified "download page" for direct links to downloadable eggs or
source distributions. Any usable packages will be downloaded if they are
required by a command line argument. For example, this::
easy_install -s http://peak.telecommunity.com/dist PyProtocols
easy_install -f http://peak.telecommunity.com/dist PyProtocols
will download and install the latest version of PyProtocols linked from
the PEAK downloads page, but ignore the other download links on that page.
You may use this option more than once, to list multiple download pages.
If all requested packages can be found using the specified download pages,
the Python Package Index will *not* be consulted.
If all requested packages can be found using links on the specified
download pages, the Python Package Index will *not* be consulted. You can
use ``file:`` URLs to reference a local filename.
You may specify multiple URLs with this option, separated by whitespace.
Note that on the command line, you will probably have to surround the URLs
with quotes, so that they are recognized as a single option value. You can
also specify URLs in a configuration file; see `Configuration Files`_,
above; but note that this means the specified pages will be downloaded
every time you use EasyInstall (unless overridden on the command line) and
thus may make startup slower.
``--index-url=URL, -u URL`` (New in 0.4a1)
Specifies the base URL of the Python Package Index. The default is
http://www.python.org/pypi if not specified. When a package is requested
that is not locally available or linked from a ``--scan-url`` download
that is not locally available or linked from a ``--find-links`` download
page, the package index will be searched for download pages for the needed
package, and those download pages will be searched for links to download
an egg or source distribution.
``--build-directory=DIR, -b DIR`` (New in 0.3a3)
Set the directory used to download, extract, and install the package. The
directory is not cleared before or after installation, so the downloaded
packages and extracted contents will remain there afterwards, allowing you
to read any documentation, examples, scripts, etc. that may have been
included with the source distribution (if any).
This option can only be used when you are specifying a single installation
URL or filename, so that the installer will not be confused by the presence
of multiple ``setup.py`` files in the build directory.
Release Notes/Change History
============================
......@@ -275,6 +319,11 @@ Known Issues
time out or be missing a file.
0.4a2
* Added support for setting options via distutils configuration files
* Renamed ``--scan-url/-s`` to ``--find-links/-f`` to free up ``-s`` for the
script installation directory option.
* Use ``urllib2`` instead of ``urllib``, to allow use of ``https:`` URLs if
Python includes SSL support.
......@@ -292,6 +341,11 @@ Known Issues
with an ``unpack_archive()`` API. These were split out of EasyInstall to
allow reuse by other tools and applications.
* ``setuptools.Command`` now supports reinitializing commands using keyword
arguments to set/reset options. Also, ``Command`` subclasses can now set
their ``command_consumes_arguments`` attribute to ``True`` in order to
receive an ``args`` option containing the rest of the command line.
0.4a1
* Added ``--scan-url`` and ``--index-url`` options, to scan download pages
and search PyPI for needed packages.
......
This diff is collapsed.
......@@ -4,7 +4,7 @@ import distutils.core, setuptools.command
from setuptools.dist import Distribution, Feature
from setuptools.extension import Extension
from setuptools.depends import Require
from distutils.core import Command
from distutils.core import Command as _Command
from distutils.util import convert_path
import os.path
......@@ -37,6 +37,8 @@ def find_packages(where='.'):
return out
def setup(**attrs):
"""Do package setup
......@@ -47,3 +49,34 @@ def setup(**attrs):
"""
attrs.setdefault("distclass",Distribution)
return distutils.core.setup(**attrs)
class Command(_Command):
__doc__ = _Command.__doc__
command_consumes_arguments = False
def reinitialize_command(self, command, reinit_subcommands=0, **kw):
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
for k,v in kw.items():
setattr(cmd,k,v) # update command with keywords
return cmd
......@@ -4,7 +4,7 @@ Build .egg distributions"""
# This module should be kept compatible with Python 2.3
import os
from distutils.core import Command
from setuptools 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, get_python_lib
......@@ -234,16 +234,16 @@ class bdist_egg(Command):
return match.group(1)
def call_command(self,cmdname,**kw):
cmd = self.reinitialize_command(cmdname)
"""Invoke reinitialized command `cmdname` with keyword args"""
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)
kw.setdefault(dirname,self.bdist_dir)
kw.setdefault('skip_build',self.skip_build)
cmd = self.reinitialize_command(cmdname, **kw)
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
......
__all__ = ['Distribution', 'Feature']
from distutils.core import Distribution as _Distribution
from distutils.core import Extension
from setuptools.depends import Require
......@@ -7,8 +8,37 @@ from setuptools.command.install import install
from setuptools.command.install_lib import install_lib
from distutils.errors import DistutilsOptionError, DistutilsPlatformError
from distutils.errors import DistutilsSetupError
sequence = tuple, list
class Distribution(_Distribution):
"""Distribution with support for features, tests, and package data
......@@ -54,7 +84,6 @@ class Distribution(_Distribution):
the distribution. They are used by the feature subsystem to configure the
distribution for the included and excluded features.
"""
def __init__ (self, attrs=None):
have_package_data = hasattr(self, "package_data")
if not have_package_data:
......@@ -83,6 +112,15 @@ class Distribution(_Distribution):
"""Convert feature name to corresponding option attribute name"""
return 'with_'+name.replace('-','_')
def _set_global_opts_from_features(self):
"""Add --with-X/--without-X options based on optional features"""
......@@ -277,14 +315,55 @@ class Distribution(_Distribution):
)
map(self.exclude_package, packages)
def _parse_command_opts(self, parser, args):
# Remove --with-X/--without-X options when processing command args
self.global_options = self.__class__.global_options
self.negative_opt = self.__class__.negative_opt
return _Distribution._parse_command_opts(self, parser, args)
# Handle commands that want to consume all remaining arguments
command = args[0]
nargs = _Distribution._parse_command_opts(self, parser, args)
cmd_class = self.get_command_class(command)
if getattr(cmd_class,'command_consumes_arguments',None):
self.get_option_dict(command)['args'] = ("command line", nargs)
if nargs is not None:
return []
return nargs
def has_dependencies(self):
return not not self.requires
......
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