Ticket #182: 0001-use-a-recent-version-of-setuptools.patch

File 0001-use-a-recent-version-of-setuptools.patch, 419.9 KB (added by geal, at 2013-09-12T12:32:45Z)

Setuptools upgrade

  • setup.py

    From ff6da46b7b4bb60ab372f0944b1881c2a828fa66 Mon Sep 17 00:00:00 2001
    From: Geoffroy Couprie <geo.couprie@gmail.com>
    Date: Thu, 12 Sep 2013 14:30:40 +0200
    Subject: [PATCH] use a recent version of setuptools
    
    ---
     setup.py                                           |    4 +-
     setuptools-0.6c16dev4.egg/EGG-INFO/PKG-INFO        |  100 -
     setuptools-0.6c16dev4.egg/EGG-INFO/SOURCES.txt     |   44 -
     .../EGG-INFO/dependency_links.txt                  |    1 -
     .../EGG-INFO/entry_points.txt                      |   59 -
     setuptools-0.6c16dev4.egg/EGG-INFO/top_level.txt   |    3 -
     setuptools-0.6c16dev4.egg/EGG-INFO/zip-safe        |    1 -
     setuptools-0.6c16dev4.egg/easy_install.py          |    5 -
     setuptools-0.6c16dev4.egg/pkg_resources.py         | 2656 --------------------
     setuptools-0.6c16dev4.egg/setuptools/__init__.py   |   90 -
     .../setuptools/archive_util.py                     |  205 --
     .../setuptools/command/__init__.py                 |   20 -
     .../setuptools/command/alias.py                    |   79 -
     .../setuptools/command/bdist_egg.py                |  533 ----
     .../setuptools/command/bdist_rpm.py                |   82 -
     .../setuptools/command/bdist_wininst.py            |   82 -
     .../setuptools/command/build_ext.py                |  285 ---
     .../setuptools/command/build_py.py                 |  211 --
     .../setuptools/command/develop.py                  |  165 --
     .../setuptools/command/easy_install.py             | 1739 -------------
     .../setuptools/command/egg_info.py                 |  451 ----
     .../setuptools/command/install.py                  |  123 -
     .../setuptools/command/install_egg_info.py         |  123 -
     .../setuptools/command/install_lib.py              |   76 -
     .../setuptools/command/install_scripts.py          |   82 -
     .../setuptools/command/register.py                 |   10 -
     .../setuptools/command/rotate.py                   |   57 -
     .../setuptools/command/saveopts.py                 |   24 -
     .../setuptools/command/scriptsetup.py              |  284 ---
     .../setuptools/command/sdist.py                    |  246 --
     .../setuptools/command/setopt.py                   |  158 --
     .../setuptools/command/test.py                     |  164 --
     .../setuptools/command/upload.py                   |  181 --
     setuptools-0.6c16dev4.egg/setuptools/depends.py    |  246 --
     setuptools-0.6c16dev4.egg/setuptools/dist.py       |  861 -------
     setuptools-0.6c16dev4.egg/setuptools/extension.py  |   35 -
     .../setuptools/package_index.py                    |  798 ------
     setuptools-0.6c16dev4.egg/setuptools/sandbox.py    |  287 ---
     setuptools-0.6c16dev4.egg/setuptools/site-patch.py |   74 -
     .../setuptools/tests/__init__.py                   |  369 ---
     .../setuptools/tests/test_packageindex.py          |   27 -
     .../setuptools/tests/test_resources.py             |  533 ----
     setuptools-0.6c16dev4.egg/zetuptoolz.txt           |   96 -
     43 files changed, 1 insertion(+), 11668 deletions(-)
     delete mode 100644 setuptools-0.6c16dev4.egg/EGG-INFO/PKG-INFO
     delete mode 100644 setuptools-0.6c16dev4.egg/EGG-INFO/SOURCES.txt
     delete mode 100644 setuptools-0.6c16dev4.egg/EGG-INFO/dependency_links.txt
     delete mode 100644 setuptools-0.6c16dev4.egg/EGG-INFO/entry_points.txt
     delete mode 100644 setuptools-0.6c16dev4.egg/EGG-INFO/top_level.txt
     delete mode 100644 setuptools-0.6c16dev4.egg/EGG-INFO/zip-safe
     delete mode 100644 setuptools-0.6c16dev4.egg/easy_install.py
     delete mode 100644 setuptools-0.6c16dev4.egg/pkg_resources.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/__init__.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/archive_util.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/__init__.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/alias.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/bdist_egg.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/bdist_rpm.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/bdist_wininst.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/build_ext.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/build_py.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/develop.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/easy_install.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/egg_info.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/install.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/install_egg_info.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/install_lib.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/install_scripts.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/register.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/rotate.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/saveopts.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/scriptsetup.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/sdist.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/setopt.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/test.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/command/upload.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/depends.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/dist.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/extension.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/package_index.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/sandbox.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/site-patch.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/tests/__init__.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/tests/test_packageindex.py
     delete mode 100644 setuptools-0.6c16dev4.egg/setuptools/tests/test_resources.py
     delete mode 100644 setuptools-0.6c16dev4.egg/zetuptoolz.txt
    
    diff --git a/setup.py b/setup.py
    index fe52383..5ec7d23 100644
    a b if len(sys.argv) > 1 and sys.argv[1] == '--fakedependency': 
    7070
    7171__requires__ = install_requires[:]
    7272
    73 egg = os.path.realpath(glob.glob('setuptools-*.egg')[0])
    74 sys.path.insert(0, egg)
    75 import setuptools; setuptools.bootstrap_install_from = egg
     73import setuptools
    7674
    7775from setuptools import setup
    7876from setuptools.command import sdist
  • deleted file setuptools-0.6c16dev4.egg/EGG-INFO/PKG-INFO

    diff --git a/setuptools-0.6c16dev4.egg/EGG-INFO/PKG-INFO b/setuptools-0.6c16dev4.egg/EGG-INFO/PKG-INFO
    deleted file mode 100644
    index f8c5e16..0000000
    + -  
    1 Metadata-Version: 1.0
    2 Name: setuptools
    3 Version: 0.6c16dev4
    4 Summary: Download, build, install, upgrade, and uninstall Python packages -- easily!  (zetuptoolz fork)
    5 Home-page: http://pypi.python.org/pypi/setuptools
    6 Author: Phillip J. Eby
    7 Author-email: distutils-sig@python.org
    8 License: PSF or ZPL
    9 Description: ======================
    10         This is not Setuptools
    11         ======================
    12        
    13         This is the ``zetuptoolz`` fork of setuptools, which is used to install
    14         `Tahoe-LAFS`_. It has a `darcs source repository`_ and `issue tracker`_.
    15        
    16         For a list of differences between this fork and setuptools, see zetuptoolz.txt.
    17        
    18         Note that, to avoid interfering with any setuptools installation, zetuptoolz
    19         does not install a script called ``easy_install``. There is an ``easy_install_z``
    20         script, but that is intended only for developers to test differences between
    21         setuptools and zetuptoolz.
    22        
    23         .. _Tahoe-LAFS: http://tahoe-lafs.org/
    24         .. _darcs source repository: http://tahoe-lafs.org/source/zetuptoolz/trunk
    25         .. _issue tracker: http://tahoe-lafs.org/trac/zetuptoolz
    26        
    27        
    28         --------------------------------
    29         Using Setuptools and EasyInstall
    30         --------------------------------
    31        
    32         Here are some of the available manuals, tutorials, and other resources for
    33         learning about Setuptools, Python Eggs, and EasyInstall:
    34        
    35         * `The EasyInstall user's guide and reference manual`_
    36         * `The setuptools Developer's Guide`_
    37         * `The pkg_resources API reference`_
    38         * `Package Compatibility Notes`_ (user-maintained)
    39         * `The Internal Structure of Python Eggs`_
    40        
    41         Questions, comments, and bug reports should be directed to the `distutils-sig
    42         mailing list`_.  If you have written (or know of) any tutorials, documentation,
    43         plug-ins, or other resources for setuptools users, please let us know about
    44         them there, so this reference list can be updated.  If you have working,
    45         *tested* patches to correct problems or add features, you may submit them to
    46         the `setuptools bug tracker`_.
    47        
    48         .. _setuptools bug tracker: http://bugs.python.org/setuptools/
    49         .. _Package Compatibility Notes: http://peak.telecommunity.com/DevCenter/PackageNotes
    50         .. _The Internal Structure of Python Eggs: http://peak.telecommunity.com/DevCenter/EggFormats
    51         .. _The setuptools Developer's Guide: http://peak.telecommunity.com/DevCenter/setuptools
    52         .. _The pkg_resources API reference: http://peak.telecommunity.com/DevCenter/PkgResources
    53         .. _The EasyInstall user's guide and reference manual: http://peak.telecommunity.com/DevCenter/EasyInstall
    54         .. _distutils-sig mailing list: http://mail.python.org/pipermail/distutils-sig/
    55        
    56        
    57         -------
    58         Credits
    59         -------
    60        
    61         * The original design for the ``.egg`` format and the ``pkg_resources`` API was
    62         co-created by Phillip Eby and Bob Ippolito.  Bob also implemented the first
    63         version of ``pkg_resources``, and supplied the OS X operating system version
    64         compatibility algorithm.
    65        
    66         * Ian Bicking implemented many early "creature comfort" features of
    67         easy_install, including support for downloading via Sourceforge and
    68         Subversion repositories.  Ian's comments on the Web-SIG about WSGI
    69         application deployment also inspired the concept of "entry points" in eggs,
    70         and he has given talks at PyCon and elsewhere to inform and educate the
    71         community about eggs and setuptools.
    72        
    73         * Jim Fulton contributed time and effort to build automated tests of various
    74         aspects of ``easy_install``, and supplied the doctests for the command-line
    75         ``.exe`` wrappers on Windows.
    76        
    77         * Phillip J. Eby is the principal author and maintainer of setuptools, and
    78         first proposed the idea of an importable binary distribution format for
    79         Python application plug-ins.
    80        
    81         * Significant parts of the implementation of setuptools were funded by the Open
    82         Source Applications Foundation, to provide a plug-in infrastructure for the
    83         Chandler PIM application.  In addition, many OSAF staffers (such as Mike
    84         "Code Bear" Taylor) contributed their time and stress as guinea pigs for the
    85         use of eggs and setuptools, even before eggs were "cool".  (Thanks, guys!)
    86        
    87         .. _files:
    88        
    89 Keywords: CPAN PyPI distutils eggs package management
    90 Platform: UNKNOWN
    91 Classifier: Development Status :: 3 - Alpha
    92 Classifier: Intended Audience :: Developers
    93 Classifier: License :: OSI Approved :: Python Software Foundation License
    94 Classifier: License :: OSI Approved :: Zope Public License
    95 Classifier: Operating System :: OS Independent
    96 Classifier: Programming Language :: Python
    97 Classifier: Topic :: Software Development :: Libraries :: Python Modules
    98 Classifier: Topic :: System :: Archiving :: Packaging
    99 Classifier: Topic :: System :: Systems Administration
    100 Classifier: Topic :: Utilities
  • deleted file setuptools-0.6c16dev4.egg/EGG-INFO/SOURCES.txt

    diff --git a/setuptools-0.6c16dev4.egg/EGG-INFO/SOURCES.txt b/setuptools-0.6c16dev4.egg/EGG-INFO/SOURCES.txt
    deleted file mode 100644
    index 07bd4ff..0000000
    + -  
    1 README.txt
    2 easy_install.py
    3 pkg_resources.py
    4 setup.cfg
    5 setup.py
    6 setuptools/__init__.py
    7 setuptools/archive_util.py
    8 setuptools/depends.py
    9 setuptools/dist.py
    10 setuptools/extension.py
    11 setuptools/package_index.py
    12 setuptools/sandbox.py
    13 setuptools/site-patch.py
    14 setuptools.egg-info/PKG-INFO
    15 setuptools.egg-info/SOURCES.txt
    16 setuptools.egg-info/dependency_links.txt
    17 setuptools.egg-info/entry_points.txt
    18 setuptools.egg-info/top_level.txt
    19 setuptools.egg-info/zip-safe
    20 setuptools/command/__init__.py
    21 setuptools/command/alias.py
    22 setuptools/command/bdist_egg.py
    23 setuptools/command/bdist_rpm.py
    24 setuptools/command/bdist_wininst.py
    25 setuptools/command/build_ext.py
    26 setuptools/command/build_py.py
    27 setuptools/command/develop.py
    28 setuptools/command/easy_install.py
    29 setuptools/command/egg_info.py
    30 setuptools/command/install.py
    31 setuptools/command/install_egg_info.py
    32 setuptools/command/install_lib.py
    33 setuptools/command/install_scripts.py
    34 setuptools/command/register.py
    35 setuptools/command/rotate.py
    36 setuptools/command/saveopts.py
    37 setuptools/command/scriptsetup.py
    38 setuptools/command/sdist.py
    39 setuptools/command/setopt.py
    40 setuptools/command/test.py
    41 setuptools/command/upload.py
    42 setuptools/tests/__init__.py
    43 setuptools/tests/test_packageindex.py
    44 setuptools/tests/test_resources.py
    45  No newline at end of file
  • deleted file setuptools-0.6c16dev4.egg/EGG-INFO/dependency_links.txt

    diff --git a/setuptools-0.6c16dev4.egg/EGG-INFO/dependency_links.txt b/setuptools-0.6c16dev4.egg/EGG-INFO/dependency_links.txt
    deleted file mode 100644
    index 8b13789..0000000
    + -  
    1 
  • deleted file setuptools-0.6c16dev4.egg/EGG-INFO/entry_points.txt

    diff --git a/setuptools-0.6c16dev4.egg/EGG-INFO/entry_points.txt b/setuptools-0.6c16dev4.egg/EGG-INFO/entry_points.txt
    deleted file mode 100644
    index 0a31ba0..0000000
    + -  
    1 [distutils.commands]
    2 bdist_rpm = setuptools.command.bdist_rpm:bdist_rpm
    3 rotate = setuptools.command.rotate:rotate
    4 develop = setuptools.command.develop:develop
    5 setopt = setuptools.command.setopt:setopt
    6 build_py = setuptools.command.build_py:build_py
    7 scriptsetup = setuptools.command.scriptsetup:scriptsetup
    8 saveopts = setuptools.command.saveopts:saveopts
    9 egg_info = setuptools.command.egg_info:egg_info
    10 register = setuptools.command.register:register
    11 install_egg_info = setuptools.command.install_egg_info:install_egg_info
    12 alias = setuptools.command.alias:alias
    13 easy_install = setuptools.command.easy_install:easy_install
    14 install_scripts = setuptools.command.install_scripts:install_scripts
    15 bdist_wininst = setuptools.command.bdist_wininst:bdist_wininst
    16 bdist_egg = setuptools.command.bdist_egg:bdist_egg
    17 install = setuptools.command.install:install
    18 test = setuptools.command.test:test
    19 install_lib = setuptools.command.install_lib:install_lib
    20 build_ext = setuptools.command.build_ext:build_ext
    21 sdist = setuptools.command.sdist:sdist
    22 
    23 [egg_info.writers]
    24 dependency_links.txt = setuptools.command.egg_info:overwrite_arg
    25 requires.txt = setuptools.command.egg_info:write_requirements
    26 PKG-INFO = setuptools.command.egg_info:write_pkg_info
    27 eager_resources.txt = setuptools.command.egg_info:overwrite_arg
    28 top_level.txt = setuptools.command.egg_info:write_toplevel_names
    29 namespace_packages.txt = setuptools.command.egg_info:overwrite_arg
    30 entry_points.txt = setuptools.command.egg_info:write_entries
    31 depends.txt = setuptools.command.egg_info:warn_depends_obsolete
    32 
    33 [console_scripts]
    34 easy_install_z-2.6 = setuptools.command.easy_install:main
    35 easy_install_z = setuptools.command.easy_install:main
    36 
    37 [setuptools.file_finders]
    38 svn_cvs = setuptools.command.sdist:_default_revctrl
    39 
    40 [distutils.setup_keywords]
    41 dependency_links = setuptools.dist:assert_string_list
    42 entry_points = setuptools.dist:check_entry_points
    43 extras_require = setuptools.dist:check_extras
    44 test_runner = setuptools.dist:check_importable
    45 package_data = setuptools.dist:check_package_data
    46 install_requires = setuptools.dist:check_requirements
    47 include_package_data = setuptools.dist:assert_bool
    48 exclude_package_data = setuptools.dist:check_package_data
    49 namespace_packages = setuptools.dist:check_nsp
    50 test_suite = setuptools.dist:check_test_suite
    51 eager_resources = setuptools.dist:assert_string_list
    52 zip_safe = setuptools.dist:assert_bool
    53 test_loader = setuptools.dist:check_importable
    54 packages = setuptools.dist:check_packages
    55 tests_require = setuptools.dist:check_requirements
    56 
    57 [setuptools.installation]
    58 eggsecutable = setuptools.command.easy_install:bootstrap
    59 
  • deleted file setuptools-0.6c16dev4.egg/EGG-INFO/top_level.txt

    diff --git a/setuptools-0.6c16dev4.egg/EGG-INFO/top_level.txt b/setuptools-0.6c16dev4.egg/EGG-INFO/top_level.txt
    deleted file mode 100644
    index 4577c6a..0000000
    + -  
    1 easy_install
    2 pkg_resources
    3 setuptools
  • deleted file setuptools-0.6c16dev4.egg/EGG-INFO/zip-safe

    diff --git a/setuptools-0.6c16dev4.egg/EGG-INFO/zip-safe b/setuptools-0.6c16dev4.egg/EGG-INFO/zip-safe
    deleted file mode 100644
    index 8b13789..0000000
    + -  
    1 
  • deleted file setuptools-0.6c16dev4.egg/easy_install.py

    diff --git a/setuptools-0.6c16dev4.egg/easy_install.py b/setuptools-0.6c16dev4.egg/easy_install.py
    deleted file mode 100644
    index d87e984..0000000
    + -  
    1 """Run the EasyInstall command"""
    2 
    3 if __name__ == '__main__':
    4     from setuptools.command.easy_install import main
    5     main()
  • deleted file setuptools-0.6c16dev4.egg/pkg_resources.py

    diff --git a/setuptools-0.6c16dev4.egg/pkg_resources.py b/setuptools-0.6c16dev4.egg/pkg_resources.py
    deleted file mode 100644
    index 3dbdec1..0000000
    + -  
    1 """Package resource API
    2 --------------------
    3 
    4 A resource is a logical file contained within a package, or a logical
    5 subdirectory thereof.  The package resource API expects resource names
    6 to have their path parts separated with ``/``, *not* whatever the local
    7 path separator is.  Do not use os.path operations to manipulate resource
    8 names being passed into the API.
    9 
    10 The package resource API is designed to work with normal filesystem packages,
    11 .egg files, and unpacked .egg files.  It can also work in a limited way with
    12 .zip files and with custom PEP 302 loaders that support the ``get_data()``
    13 method.
    14 """
    15 
    16 import sys, os, zipimport, time, re, imp
    17 
    18 try:
    19     frozenset
    20 except NameError:
    21     from sets import ImmutableSet as frozenset
    22 
    23 # capture these to bypass sandboxing
    24 from os import utime, rename, unlink, mkdir
    25 from os import open as os_open
    26 from os.path import isdir, split
    27 
    28 def _bypass_ensure_directory(name, mode=0777):
    29     # Sandbox-bypassing version of ensure_directory()
    30     dirname, filename = split(name)
    31     if dirname and filename and not isdir(dirname):
    32         _bypass_ensure_directory(dirname)
    33         mkdir(dirname, mode)
    34 
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    42 _state_vars = {}
    43 
    44 def _declare_state(vartype, **kw):
    45     g = globals()
    46     for name, val in kw.iteritems():
    47         g[name] = val
    48         _state_vars[name] = vartype
    49 
    50 def __getstate__():
    51     state = {}
    52     g = globals()
    53     for k, v in _state_vars.iteritems():
    54         state[k] = g['_sget_'+v](g[k])
    55     return state
    56 
    57 def __setstate__(state):
    58     g = globals()
    59     for k, v in state.iteritems():
    60         g['_sset_'+_state_vars[k]](k, g[k], v)
    61     return state
    62 
    63 def _sget_dict(val):
    64     return val.copy()
    65 
    66 def _sset_dict(key, ob, state):
    67     ob.clear()
    68     ob.update(state)
    69 
    70 def _sget_object(val):
    71     return val.__getstate__()
    72 
    73 def _sset_object(key, ob, state):
    74     ob.__setstate__(state)
    75 
    76 _sget_none = _sset_none = lambda *args: None
    77 
    78 
    79 
    80 
    81 
    82 
    83 def get_supported_platform():
    84     """Return this platform's maximum compatible version.
    85 
    86     distutils.util.get_platform() normally reports the minimum version
    87     of Mac OS X that would be required to *use* extensions produced by
    88     distutils.  But what we want when checking compatibility is to know the
    89     version of Mac OS X that we are *running*.  To allow usage of packages that
    90     explicitly require a newer version of Mac OS X, we must also know the
    91     current version of the OS.
    92 
    93     If this condition occurs for any other platform with a version in its
    94     platform strings, this function should be extended accordingly.
    95     """
    96     plat = get_build_platform(); m = macosVersionString.match(plat)
    97     if m is not None and sys.platform == "darwin":
    98         try:
    99             plat = 'macosx-%s-%s' % ('.'.join(_macosx_vers()[:2]), m.group(3))
    100         except ValueError:
    101             pass    # not Mac OS X
    102     return plat
    103 
    104 
    105 
    106 
    107 
    108 
    109 
    110 
    111 
    112 
    113 
    114 
    115 
    116 
    117 
    118 
    119 
    120 
    121 
    122 
    123 
    124 __all__ = [
    125     # Basic resource access and distribution/entry point discovery
    126     'require', 'run_script', 'get_provider',  'get_distribution',
    127     'load_entry_point', 'get_entry_map', 'get_entry_info', 'iter_entry_points',
    128     'resource_string', 'resource_stream', 'resource_filename',
    129     'resource_listdir', 'resource_exists', 'resource_isdir',
    130 
    131     # Environmental control
    132     'declare_namespace', 'working_set', 'add_activation_listener',
    133     'find_distributions', 'set_extraction_path', 'cleanup_resources',
    134     'get_default_cache',
    135 
    136     # Primary implementation classes
    137     'Environment', 'WorkingSet', 'ResourceManager',
    138     'Distribution', 'Requirement', 'EntryPoint',
    139 
    140     # Exceptions
    141     'ResolutionError','VersionConflict','DistributionNotFound','UnknownExtra',
    142     'ExtractionError',
    143 
    144     # Parsing functions and string utilities
    145     'parse_requirements', 'parse_version', 'safe_name', 'safe_version',
    146     'get_platform', 'compatible_platforms', 'yield_lines', 'split_sections',
    147     'safe_extra', 'to_filename',
    148 
    149     # filesystem utilities
    150     'ensure_directory', 'normalize_path',
    151 
    152     # Distribution "precedence" constants
    153     'EGG_DIST', 'BINARY_DIST', 'SOURCE_DIST', 'CHECKOUT_DIST', 'DEVELOP_DIST',
    154 
    155     # "Provider" interfaces, implementations, and registration/lookup APIs
    156     'IMetadataProvider', 'IResourceProvider', 'FileMetadata',
    157     'PathMetadata', 'EggMetadata', 'EmptyProvider', 'empty_provider',
    158     'NullProvider', 'EggProvider', 'DefaultProvider', 'ZipProvider',
    159     'register_finder', 'register_namespace_handler', 'register_loader_type',
    160     'fixup_namespace_packages', 'get_importer',
    161 
    162     # Deprecated/backward compatibility only
    163     'run_main', 'AvailableDistributions',
    164 ]
    165 class ResolutionError(Exception):
    166     """Abstract base for dependency resolution errors"""
    167     def __repr__(self):
    168         return self.__class__.__name__+repr(self.args)
    169 
    170 class VersionConflict(ResolutionError):
    171     """An already-installed version conflicts with the requested version"""
    172 
    173 class DistributionNotFound(ResolutionError):
    174     """A requested distribution was not found"""
    175 
    176 class UnknownExtra(ResolutionError):
    177     """Distribution doesn't have an "extra feature" of the given name"""
    178 
    179 _provider_factories = {}
    180 PY_MAJOR = sys.version[:3]
    181 EGG_DIST    = 3
    182 BINARY_DIST = 2
    183 SOURCE_DIST = 1
    184 CHECKOUT_DIST = 0
    185 DEVELOP_DIST = -1
    186 
    187 def register_loader_type(loader_type, provider_factory):
    188     """Register `provider_factory` to make providers for `loader_type`
    189 
    190     `loader_type` is the type or class of a PEP 302 ``module.__loader__``,
    191     and `provider_factory` is a function that, passed a *module* object,
    192     returns an ``IResourceProvider`` for that module.
    193     """
    194     _provider_factories[loader_type] = provider_factory
    195 
    196 def get_provider(moduleOrReq):
    197     """Return an IResourceProvider for the named module or requirement"""
    198     if isinstance(moduleOrReq,Requirement):
    199         return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
    200     try:
    201         module = sys.modules[moduleOrReq]
    202     except KeyError:
    203         __import__(moduleOrReq)
    204         module = sys.modules[moduleOrReq]
    205     loader = getattr(module, '__loader__', None)
    206     return _find_adapter(_provider_factories, loader)(module)
    207 
    208 def _macosx_vers(_cache=[]):
    209     if not _cache:
    210         from platform import mac_ver
    211         _cache.append(mac_ver()[0].split('.'))
    212     return _cache[0]
    213 
    214 def _macosx_arch(machine):
    215     return {'PowerPC':'ppc', 'Power_Macintosh':'ppc'}.get(machine,machine)
    216 
    217 def get_build_platform():
    218     """Return this platform's string for platform-specific distributions
    219 
    220     XXX Currently this is the same as ``distutils.util.get_platform()``, but it
    221     needs some hacks for Linux and Mac OS X.
    222     """
    223     from distutils.util import get_platform
    224     plat = get_platform()
    225     if sys.platform == "darwin" and not plat.startswith('macosx-'):
    226         try:
    227             version = _macosx_vers()
    228             machine = os.uname()[4].replace(" ", "_")
    229             return "macosx-%d.%d-%s" % (int(version[0]), int(version[1]),
    230                 _macosx_arch(machine))
    231         except ValueError:
    232             # if someone is running a non-Mac darwin system, this will fall
    233             # through to the default implementation
    234             pass
    235     return plat
    236 
    237 macosVersionString = re.compile(r"macosx-(\d+)\.(\d+)-(.*)")
    238 darwinVersionString = re.compile(r"darwin-(\d+)\.(\d+)\.(\d+)-(.*)")
    239 get_platform = get_build_platform   # XXX backward compat
    240 
    241 
    242 
    243 
    244 
    245 
    246 
    247 def compatible_platforms(provided,required):
    248     """Can code for the `provided` platform run on the `required` platform?
    249 
    250     Returns true if either platform is ``None``, or the platforms are equal.
    251 
    252     XXX Needs compatibility checks for Linux and other unixy OSes.
    253     """
    254     if provided is None or required is None or provided==required:
    255         return True     # easy case
    256 
    257     # Mac OS X special cases
    258     reqMac = macosVersionString.match(required)
    259     if reqMac:
    260         provMac = macosVersionString.match(provided)
    261 
    262         # is this a Mac package?
    263         if not provMac:
    264             # this is backwards compatibility for packages built before
    265             # setuptools 0.6. All packages built after this point will
    266             # use the new macosx designation.
    267             provDarwin = darwinVersionString.match(provided)
    268             if provDarwin:
    269                 dversion = int(provDarwin.group(1))
    270                 macosversion = "%s.%s" % (reqMac.group(1), reqMac.group(2))
    271                 if dversion == 7 and macosversion >= "10.3" or \
    272                     dversion == 8 and macosversion >= "10.4":
    273 
    274                     #import warnings
    275                     #warnings.warn("Mac eggs should be rebuilt to "
    276                     #    "use the macosx designation instead of darwin.",
    277                     #    category=DeprecationWarning)
    278                     return True
    279             return False    # egg isn't macosx or legacy darwin
    280 
    281         # are they the same major version and machine type?
    282         if provMac.group(1) != reqMac.group(1) or \
    283             provMac.group(3) != reqMac.group(3):
    284             return False
    285 
    286 
    287 
    288         # is the required OS major update >= the provided one?
    289         if int(provMac.group(2)) > int(reqMac.group(2)):
    290             return False
    291 
    292         return True
    293 
    294     # XXX Linux and other platforms' special cases should go here
    295     return False
    296 
    297 
    298 def run_script(dist_spec, script_name):
    299     """Locate distribution `dist_spec` and run its `script_name` script"""
    300     ns = sys._getframe(1).f_globals
    301     name = ns['__name__']
    302     ns.clear()
    303     ns['__name__'] = name
    304     require(dist_spec)[0].run_script(script_name, ns)
    305 
    306 run_main = run_script   # backward compatibility
    307 
    308 def get_distribution(dist):
    309     """Return a current distribution object for a Requirement or string"""
    310     if isinstance(dist,basestring): dist = Requirement.parse(dist)
    311     if isinstance(dist,Requirement): dist = get_provider(dist)
    312     if not isinstance(dist,Distribution):
    313         raise TypeError("Expected string, Requirement, or Distribution", dist)
    314     return dist
    315 
    316 def load_entry_point(dist, group, name):
    317     """Return `name` entry point of `group` for `dist` or raise ImportError"""
    318     return get_distribution(dist).load_entry_point(group, name)
    319 
    320 def get_entry_map(dist, group=None):
    321     """Return the entry point map for `group`, or the full entry map"""
    322     return get_distribution(dist).get_entry_map(group)
    323 
    324 def get_entry_info(dist, group, name):
    325     """Return the EntryPoint object for `group`+`name`, or ``None``"""
    326     return get_distribution(dist).get_entry_info(group, name)
    327 
    328 
    329 class IMetadataProvider:
    330 
    331     def has_metadata(name):
    332         """Does the package's distribution contain the named metadata?"""
    333 
    334     def get_metadata(name):
    335         """The named metadata resource as a string"""
    336 
    337     def get_metadata_lines(name):
    338         """Yield named metadata resource as list of non-blank non-comment lines
    339 
    340        Leading and trailing whitespace is stripped from each line, and lines
    341        with ``#`` as the first non-blank character are omitted."""
    342 
    343     def metadata_isdir(name):
    344         """Is the named metadata a directory?  (like ``os.path.isdir()``)"""
    345 
    346     def metadata_listdir(name):
    347         """List of metadata names in the directory (like ``os.listdir()``)"""
    348 
    349     def run_script(script_name, namespace):
    350         """Execute the named script in the supplied namespace dictionary"""
    351 
    352 
    353 
    354 
    355 
    356 
    357 
    358 
    359 
    360 
    361 
    362 
    363 
    364 
    365 
    366 
    367 
    368 
    369 
    370 class IResourceProvider(IMetadataProvider):
    371     """An object that provides access to package resources"""
    372 
    373     def get_resource_filename(manager, resource_name):
    374         """Return a true filesystem path for `resource_name`
    375 
    376         `manager` must be an ``IResourceManager``"""
    377 
    378     def get_resource_stream(manager, resource_name):
    379         """Return a readable file-like object for `resource_name`
    380 
    381         `manager` must be an ``IResourceManager``"""
    382 
    383     def get_resource_string(manager, resource_name):
    384         """Return a string containing the contents of `resource_name`
    385 
    386         `manager` must be an ``IResourceManager``"""
    387 
    388     def has_resource(resource_name):
    389         """Does the package contain the named resource?"""
    390 
    391     def resource_isdir(resource_name):
    392         """Is the named resource a directory?  (like ``os.path.isdir()``)"""
    393 
    394     def resource_listdir(resource_name):
    395         """List of resource names in the directory (like ``os.listdir()``)"""
    396 
    397 
    398 
    399 
    400 
    401 
    402 
    403 
    404 
    405 
    406 
    407 
    408 
    409 
    410 
    411 class WorkingSet(object):
    412     """A collection of active distributions on sys.path (or a similar list)"""
    413 
    414     def __init__(self, entries=None):
    415         """Create working set from list of path entries (default=sys.path)"""
    416         self.entries = []
    417         self.entry_keys = {}
    418         self.by_key = {}
    419         self.callbacks = []
    420 
    421         if entries is None:
    422             entries = sys.path
    423 
    424         for entry in entries:
    425             self.add_entry(entry)
    426 
    427 
    428     def add_entry(self, entry):
    429         """Add a path item to ``.entries``, finding any distributions on it
    430 
    431         ``find_distributions(entry, True)`` is used to find distributions
    432         corresponding to the path entry, and they are added.  `entry` is
    433         always appended to ``.entries``, even if it is already present.
    434         (This is because ``sys.path`` can contain the same value more than
    435         once, and the ``.entries`` of the ``sys.path`` WorkingSet should always
    436         equal ``sys.path``.)
    437         """
    438         self.entry_keys.setdefault(entry, [])
    439         self.entries.append(entry)
    440         for dist in find_distributions(entry, True):
    441             self.add(dist, entry, False)
    442 
    443 
    444     def __contains__(self,dist):
    445         """True if `dist` is the active distribution for its project"""
    446         return self.by_key.get(dist.key) == dist
    447 
    448 
    449 
    450 
    451 
    452     def find(self, req):
    453         """Find a distribution matching requirement `req`
    454 
    455         If there is an active distribution for the requested project, this
    456         returns it as long as it meets the version requirement specified by
    457         `req`.  But, if there is an active distribution for the project and it
    458         does *not* meet the `req` requirement, ``VersionConflict`` is raised.
    459         If there is no active distribution for the requested project, ``None``
    460         is returned.
    461         """
    462         dist = self.by_key.get(req.key)
    463         if dist is not None and dist not in req:
    464             raise VersionConflict(dist,req)     # XXX add more info
    465         else:
    466             return dist
    467 
    468     def iter_entry_points(self, group, name=None):
    469         """Yield entry point objects from `group` matching `name`
    470 
    471         If `name` is None, yields all entry points in `group` from all
    472         distributions in the working set, otherwise only ones matching
    473         both `group` and `name` are yielded (in distribution order).
    474         """
    475         for dist in self:
    476             entries = dist.get_entry_map(group)
    477             if name is None:
    478                 for ep in entries.values():
    479                     yield ep
    480             elif name in entries:
    481                 yield entries[name]
    482 
    483     def run_script(self, requires, script_name):
    484         """Locate distribution for `requires` and run `script_name` script"""
    485         ns = sys._getframe(1).f_globals
    486         name = ns['__name__']
    487         ns.clear()
    488         ns['__name__'] = name
    489         self.require(requires)[0].run_script(script_name, ns)
    490 
    491 
    492 
    493     def __iter__(self):
    494         """Yield distributions for non-duplicate projects in the working set
    495 
    496         The yield order is the order in which the items' path entries were
    497         added to the working set.
    498         """
    499         seen = {}
    500         for item in self.entries:
    501             for key in self.entry_keys[item]:
    502                 if key not in seen:
    503                     seen[key]=1
    504                     yield self.by_key[key]
    505 
    506     def add(self, dist, entry=None, insert=True):
    507         """Add `dist` to working set, associated with `entry`
    508 
    509         If `entry` is unspecified, it defaults to the ``.location`` of `dist`.
    510         On exit from this routine, `entry` is added to the end of the working
    511         set's ``.entries`` (if it wasn't already present).
    512 
    513         `dist` is only added to the working set if it's for a project that
    514         doesn't already have a distribution in the set.  If it's added, any
    515         callbacks registered with the ``subscribe()`` method will be called.
    516         """
    517         if insert:
    518             dist.insert_on(self.entries, entry)
    519 
    520         if entry is None:
    521             entry = dist.location
    522         keys = self.entry_keys.setdefault(entry,[])
    523         keys2 = self.entry_keys.setdefault(dist.location,[])
    524         if dist.key in self.by_key:
    525             return      # ignore hidden distros
    526 
    527         # If we have a __requires__ then we can already tell if this
    528         # dist is unsatisfactory, in which case we won't add it.
    529         if __requires__ is not None:
    530             for thisreqstr in __requires__:
    531                 try:
    532                     for thisreq in parse_requirements(thisreqstr):
    533                         if thisreq.key == dist.key:
    534                             if dist not in thisreq:
    535                                 return
    536                 except ValueError, e:
    537                     e.args = tuple(e.args + ({'thisreqstr': thisreqstr},))
    538                     raise
    539 
    540         self.by_key[dist.key] = dist
    541         if dist.key not in keys:
    542             keys.append(dist.key)
    543         if dist.key not in keys2:
    544             keys2.append(dist.key)
    545         self._added_new(dist)
    546 
    547     def resolve(self, requirements, env=None, installer=None):
    548         """List all distributions needed to (recursively) meet `requirements`
    549 
    550         `requirements` must be a sequence of ``Requirement`` objects.  `env`,
    551         if supplied, should be an ``Environment`` instance.  If
    552         not supplied, it defaults to all distributions available within any
    553         entry or distribution in the working set.  `installer`, if supplied,
    554         will be invoked with each requirement that cannot be met by an
    555         already-installed distribution; it should return a ``Distribution`` or
    556         ``None``.
    557         """
    558 
    559         requirements = list(requirements)[::-1]  # set up the stack
    560         processed = {}  # set of processed requirements
    561         best = {}  # key -> dist
    562         to_activate = []
    563 
    564         while requirements:
    565             req = requirements.pop(0)   # process dependencies breadth-first
    566             if req in processed:
    567                 # Ignore cyclic or redundant dependencies
    568                 continue
    569             dist = best.get(req.key)
    570             if dist is None:
    571                 # Find the best distribution and add it to the map
    572                 dist = self.by_key.get(req.key)
    573                 if dist is None:
    574                     if env is None:
    575                         env = Environment(self.entries)
    576                     dist = best[req.key] = env.best_match(req, self, installer)
    577                     if dist is None:
    578                         raise DistributionNotFound(req)  # XXX put more info here
    579                 to_activate.append(dist)
    580             if dist not in req:
    581                 # Oops, the "best" so far conflicts with a dependency
    582                 raise VersionConflict(dist,req) # XXX put more info here
    583             requirements.extend(dist.requires(req.extras)[::-1])
    584             processed[req] = True
    585 
    586         return to_activate    # return list of distros to activate
    587 
    588     def find_plugins(self,
    589         plugin_env, full_env=None, installer=None, fallback=True
    590     ):
    591         """Find all activatable distributions in `plugin_env`
    592 
    593         Example usage::
    594 
    595             distributions, errors = working_set.find_plugins(
    596                 Environment(plugin_dirlist)
    597             )
    598             map(working_set.add, distributions)  # add plugins+libs to sys.path
    599             print "Couldn't load", errors        # display errors
    600 
    601         The `plugin_env` should be an ``Environment`` instance that contains
    602         only distributions that are in the project's "plugin directory" or
    603         directories. The `full_env`, if supplied, should be an ``Environment``
    604         contains all currently-available distributions.  If `full_env` is not
    605         supplied, one is created automatically from the ``WorkingSet`` this
    606         method is called on, which will typically mean that every directory on
    607         ``sys.path`` will be scanned for distributions.
    608 
    609         `installer` is a standard installer callback as used by the
    610         ``resolve()`` method. The `fallback` flag indicates whether we should
    611         attempt to resolve older versions of a plugin if the newest version
    612         cannot be resolved.
    613 
    614         This method returns a 2-tuple: (`distributions`, `error_info`), where
    615         `distributions` is a list of the distributions found in `plugin_env`
    616         that were loadable, along with any other distributions that are needed
    617         to resolve their dependencies.  `error_info` is a dictionary mapping
    618         unloadable plugin distributions to an exception instance describing the
    619         error that occurred. Usually this will be a ``DistributionNotFound`` or
    620         ``VersionConflict`` instance.
    621         """
    622 
    623         plugin_projects = list(plugin_env)
    624         plugin_projects.sort()  # scan project names in alphabetic order
    625 
    626         error_info = {}
    627         distributions = {}
    628 
    629         if full_env is None:
    630             env = Environment(self.entries)
    631             env += plugin_env
    632         else:
    633             env = full_env + plugin_env
    634 
    635         shadow_set = self.__class__([])
    636         map(shadow_set.add, self)   # put all our entries in shadow_set
    637 
    638         for project_name in plugin_projects:
    639 
    640             for dist in plugin_env[project_name]:
    641 
    642                 req = [dist.as_requirement()]
    643 
    644                 try:
    645                     resolvees = shadow_set.resolve(req, env, installer)
    646 
    647                 except ResolutionError,v:
    648                     error_info[dist] = v    # save error info
    649                     if fallback:
    650                         continue    # try the next older version of project
    651                     else:
    652                         break       # give up on this project, keep going
    653 
    654                 else:
    655                     map(shadow_set.add, resolvees)
    656                     distributions.update(dict.fromkeys(resolvees))
    657 
    658                     # success, no need to try any more versions of this project
    659                     break
    660 
    661         distributions = list(distributions)
    662         distributions.sort()
    663 
    664         return distributions, error_info
    665 
    666 
    667 
    668 
    669 
    670     def require(self, *requirements):
    671         """Ensure that distributions matching `requirements` are activated
    672 
    673         `requirements` must be a string or a (possibly-nested) sequence
    674         thereof, specifying the distributions and versions required.  The
    675         return value is a sequence of the distributions that needed to be
    676         activated to fulfill the requirements; all relevant distributions are
    677         included, even if they were already activated in this working set.
    678         """
    679         needed = self.resolve(parse_requirements(requirements))
    680 
    681         for dist in needed:
    682             self.add(dist)
    683 
    684         return needed
    685 
    686     def subscribe(self, callback):
    687         """Invoke `callback` for all distributions (including existing ones)"""
    688         if callback in self.callbacks:
    689             return
    690         self.callbacks.append(callback)
    691         for dist in self:
    692             callback(dist)
    693 
    694     def _added_new(self, dist):
    695         for callback in self.callbacks:
    696             callback(dist)
    697 
    698     def __getstate__(self):
    699         return (
    700             self.entries[:], self.entry_keys.copy(), self.by_key.copy(),
    701             self.callbacks[:]
    702         )
    703 
    704     def __setstate__(self, (entries, keys, by_key, callbacks)):
    705         self.entries = entries[:]
    706         self.entry_keys = keys.copy()
    707         self.by_key = by_key.copy()
    708         self.callbacks = callbacks[:]
    709 
    710 
    711 class Environment(object):
    712     """Searchable snapshot of distributions on a search path"""
    713 
    714     def __init__(self, search_path=None, platform=get_supported_platform(), python=PY_MAJOR):
    715         """Snapshot distributions available on a search path
    716 
    717         Any distributions found on `search_path` are added to the environment.
    718         `search_path` should be a sequence of ``sys.path`` items.  If not
    719         supplied, ``sys.path`` is used.
    720 
    721         `platform` is an optional string specifying the name of the platform
    722         that platform-specific distributions must be compatible with.  If
    723         unspecified, it defaults to the current platform.  `python` is an
    724         optional string naming the desired version of Python (e.g. ``'2.4'``);
    725         it defaults to the current version.
    726 
    727         You may explicitly set `platform` (and/or `python`) to ``None`` if you
    728         wish to map *all* distributions, not just those compatible with the
    729         running platform or Python version.
    730         """
    731         self._distmap = {}
    732         self._cache = {}
    733         self.platform = platform
    734         self.python = python
    735         self.scan(search_path)
    736 
    737     def can_add(self, dist):
    738         """Is distribution `dist` acceptable for this environment?
    739 
    740         The distribution must match the platform and python version
    741         requirements specified when this environment was created, or False
    742         is returned.
    743         """
    744         return (self.python is None or dist.py_version is None
    745             or dist.py_version==self.python) \
    746            and compatible_platforms(dist.platform,self.platform)
    747 
    748     def remove(self, dist):
    749         """Remove `dist` from the environment"""
    750         self._distmap[dist.key].remove(dist)
    751 
    752     def scan(self, search_path=None):
    753         """Scan `search_path` for distributions usable in this environment
    754 
    755         Any distributions found are added to the environment.
    756         `search_path` should be a sequence of ``sys.path`` items.  If not
    757         supplied, ``sys.path`` is used.  Only distributions conforming to
    758         the platform/python version defined at initialization are added.
    759         """
    760         if search_path is None:
    761             search_path = sys.path
    762 
    763         for item in search_path:
    764             for dist in find_distributions(item):
    765                 self.add(dist)
    766 
    767     def __getitem__(self,project_name):
    768         """Return a newest-to-oldest list of distributions for `project_name`
    769         """
    770         try:
    771             return self._cache[project_name]
    772         except KeyError:
    773             project_name = project_name.lower()
    774             if project_name not in self._distmap:
    775                 return []
    776 
    777         if project_name not in self._cache:
    778             dists = self._cache[project_name] = self._distmap[project_name]
    779             _sort_dists(dists)
    780 
    781         return self._cache[project_name]
    782 
    783     def add(self,dist):
    784         """Add `dist` if we ``can_add()`` it and it isn't already added"""
    785         if self.can_add(dist) and dist.has_version():
    786             dists = self._distmap.setdefault(dist.key,[])
    787             if dist not in dists:
    788                 dists.append(dist)
    789                 if dist.key in self._cache:
    790                     _sort_dists(self._cache[dist.key])
    791 
    792 
    793     def best_match(self, req, working_set, installer=None):
    794         """Find distribution best matching `req` and usable on `working_set`
    795 
    796         This calls the ``find(req)`` method of the `working_set` to see if a
    797         suitable distribution is already active.  (This may raise
    798         ``VersionConflict`` if an unsuitable version of the project is already
    799         active in the specified `working_set`.)
    800 
    801         If a suitable distribution isn't active, this method returns the
    802         newest platform-dependent distribution in the environment that meets
    803         the ``Requirement`` in `req`. If no suitable platform-dependent
    804         distribution is found, then the newest platform-independent
    805         distribution that meets the requirement is returned. (A platform-
    806         dependent distribution will typically have code compiled or
    807         specialized for that platform.)
    808 
    809         Otherwise, if `installer` is supplied, then the result of calling the
    810         environment's ``obtain(req, installer)`` method will be returned.
    811         """
    812         dist = working_set.find(req)
    813         if dist is not None:
    814             return dist
    815 
    816         # first try to find a platform-dependent dist
    817         for dist in self[req.key]:
    818             if dist in req and dist.platform is not None:
    819                 return dist
    820 
    821         # then try any other dist
    822         for dist in self[req.key]:
    823             if dist in req:
    824                 return dist
    825 
    826         return self.obtain(req, installer) # try and download/install
    827 
    828     def obtain(self, requirement, installer=None):
    829         """Obtain a distribution matching `requirement` (e.g. via download)
    830 
    831         Obtain a distro that matches requirement (e.g. via download).  In the
    832         base ``Environment`` class, this routine just returns
    833         ``installer(requirement)``, unless `installer` is None, in which case
    834         None is returned instead.  This method is a hook that allows subclasses
    835         to attempt other ways of obtaining a distribution before falling back
    836         to the `installer` argument."""
    837         if installer is not None:
    838             return installer(requirement)
    839 
    840     def __iter__(self):
    841         """Yield the unique project names of the available distributions"""
    842         for key in self._distmap.keys():
    843             if self[key]: yield key
    844 
    845 
    846 
    847 
    848     def __iadd__(self, other):
    849         """In-place addition of a distribution or environment"""
    850         if isinstance(other,Distribution):
    851             self.add(other)
    852         elif isinstance(other,Environment):
    853             for project in other:
    854                 for dist in other[project]:
    855                     self.add(dist)
    856         else:
    857             raise TypeError("Can't add %r to environment" % (other,))
    858         return self
    859 
    860     def __add__(self, other):
    861         """Add an environment or distribution to an environment"""
    862         new = self.__class__([], platform=None, python=None)
    863         for env in self, other:
    864             new += env
    865         return new
    866 
    867 
    868 AvailableDistributions = Environment    # XXX backward compatibility
    869 
    870 
    871 class ExtractionError(RuntimeError):
    872     """An error occurred extracting a resource
    873 
    874     The following attributes are available from instances of this exception:
    875 
    876     manager
    877         The resource manager that raised this exception
    878 
    879     cache_path
    880         The base directory for resource extraction
    881 
    882     original_error
    883         The exception instance that caused extraction to fail
    884     """
    885 
    886 
    887 
    888 
    889 class ResourceManager:
    890     """Manage resource extraction and packages"""
    891     extraction_path = None
    892 
    893     def __init__(self):
    894         self.cached_files = {}
    895 
    896     def resource_exists(self, package_or_requirement, resource_name):
    897         """Does the named resource exist?"""
    898         return get_provider(package_or_requirement).has_resource(resource_name)
    899 
    900     def resource_isdir(self, package_or_requirement, resource_name):
    901         """Is the named resource an existing directory?"""
    902         return get_provider(package_or_requirement).resource_isdir(
    903             resource_name
    904         )
    905 
    906     def resource_filename(self, package_or_requirement, resource_name):
    907         """Return a true filesystem path for specified resource"""
    908         return get_provider(package_or_requirement).get_resource_filename(
    909             self, resource_name
    910         )
    911 
    912     def resource_stream(self, package_or_requirement, resource_name):
    913         """Return a readable file-like object for specified resource"""
    914         return get_provider(package_or_requirement).get_resource_stream(
    915             self, resource_name
    916         )
    917 
    918     def resource_string(self, package_or_requirement, resource_name):
    919         """Return specified resource as a string"""
    920         return get_provider(package_or_requirement).get_resource_string(
    921             self, resource_name
    922         )
    923 
    924     def resource_listdir(self, package_or_requirement, resource_name):
    925         """List the contents of the named resource directory"""
    926         return get_provider(package_or_requirement).resource_listdir(
    927             resource_name
    928         )
    929 
    930     def extraction_error(self):
    931         """Give an error message for problems extracting file(s)"""
    932 
    933         old_exc = sys.exc_info()[1]
    934         cache_path = self.extraction_path or get_default_cache()
    935 
    936         err = ExtractionError("""Can't extract file(s) to egg cache
    937 
    938 The following error occurred while trying to extract file(s) to the Python egg
    939 cache:
    940 
    941   %s
    942 
    943 The Python egg cache directory is currently set to:
    944 
    945   %s
    946 
    947 Perhaps your account does not have write access to this directory?  You can
    948 change the cache directory by setting the PYTHON_EGG_CACHE environment
    949 variable to point to an accessible directory.
    950 """         % (old_exc, cache_path)
    951         )
    952         err.manager        = self
    953         err.cache_path     = cache_path
    954         err.original_error = old_exc
    955         raise err
    956 
    957 
    958 
    959 
    960 
    961 
    962 
    963 
    964 
    965 
    966 
    967 
    968 
    969 
    970 
    971     def get_cache_path(self, archive_name, names=()):
    972         """Return absolute location in cache for `archive_name` and `names`
    973 
    974         The parent directory of the resulting path will be created if it does
    975         not already exist.  `archive_name` should be the base filename of the
    976         enclosing egg (which may not be the name of the enclosing zipfile!),
    977         including its ".egg" extension.  `names`, if provided, should be a
    978         sequence of path name parts "under" the egg's extraction location.
    979 
    980         This method should only be called by resource providers that need to
    981         obtain an extraction location, and only for names they intend to
    982         extract, as it tracks the generated names for possible cleanup later.
    983         """
    984         extract_path = self.extraction_path or get_default_cache()
    985         target_path = os.path.join(extract_path, archive_name+'-tmp', *names)
    986         try:
    987             _bypass_ensure_directory(target_path)
    988         except:
    989             self.extraction_error()
    990 
    991         self.cached_files[target_path] = 1
    992         return target_path
    993 
    994 
    995 
    996 
    997 
    998 
    999 
    1000 
    1001 
    1002 
    1003 
    1004 
    1005 
    1006 
    1007 
    1008 
    1009 
    1010 
    1011 
    1012     def postprocess(self, tempname, filename):
    1013         """Perform any platform-specific postprocessing of `tempname`
    1014 
    1015         This is where Mac header rewrites should be done; other platforms don't
    1016         have anything special they should do.
    1017 
    1018         Resource providers should call this method ONLY after successfully
    1019         extracting a compressed resource.  They must NOT call it on resources
    1020         that are already in the filesystem.
    1021 
    1022         `tempname` is the current (temporary) name of the file, and `filename`
    1023         is the name it will be renamed to by the caller after this routine
    1024         returns.
    1025         """
    1026 
    1027         if os.name == 'posix':
    1028             # Make the resource executable
    1029             mode = ((os.stat(tempname).st_mode) | 0555) & 07777
    1030             os.chmod(tempname, mode)
    1031 
    1032 
    1033 
    1034 
    1035 
    1036 
    1037 
    1038 
    1039 
    1040 
    1041 
    1042 
    1043 
    1044 
    1045 
    1046 
    1047 
    1048 
    1049 
    1050 
    1051 
    1052 
    1053     def set_extraction_path(self, path):
    1054         """Set the base path where resources will be extracted to, if needed.
    1055 
    1056         If you do not call this routine before any extractions take place, the
    1057         path defaults to the return value of ``get_default_cache()``.  (Which
    1058         is based on the ``PYTHON_EGG_CACHE`` environment variable, with various
    1059         platform-specific fallbacks.  See that routine's documentation for more
    1060         details.)
    1061 
    1062         Resources are extracted to subdirectories of this path based upon
    1063         information given by the ``IResourceProvider``.  You may set this to a
    1064         temporary directory, but then you must call ``cleanup_resources()`` to
    1065         delete the extracted files when done.  There is no guarantee that
    1066         ``cleanup_resources()`` will be able to remove all extracted files.
    1067 
    1068         (Note: you may not change the extraction path for a given resource
    1069         manager once resources have been extracted, unless you first call
    1070         ``cleanup_resources()``.)
    1071         """
    1072         if self.cached_files:
    1073             raise ValueError(
    1074                 "Can't change extraction path, files already extracted"
    1075             )
    1076 
    1077         self.extraction_path = path
    1078 
    1079     def cleanup_resources(self, force=False):
    1080         """
    1081         Delete all extracted resource files and directories, returning a list
    1082         of the file and directory names that could not be successfully removed.
    1083         This function does not have any concurrency protection, so it should
    1084         generally only be called when the extraction path is a temporary
    1085         directory exclusive to a single process.  This method is not
    1086         automatically called; you must call it explicitly or register it as an
    1087         ``atexit`` function if you wish to ensure cleanup of a temporary
    1088         directory used for extractions.
    1089         """
    1090         # XXX
    1091 
    1092 
    1093 
    1094 def get_default_cache():
    1095     """Determine the default cache location
    1096 
    1097     This returns the ``PYTHON_EGG_CACHE`` environment variable, if set.
    1098     Otherwise, on Windows, it returns a "Python-Eggs" subdirectory of the
    1099     "Application Data" directory.  On all other systems, it's "~/.python-eggs".
    1100     """
    1101     try:
    1102         return os.environ['PYTHON_EGG_CACHE']
    1103     except KeyError:
    1104         pass
    1105 
    1106     if os.name!='nt':
    1107         return os.path.expanduser('~/.python-eggs')
    1108 
    1109     app_data = 'Application Data'   # XXX this may be locale-specific!
    1110     app_homes = [
    1111         (('APPDATA',), None),       # best option, should be locale-safe
    1112         (('USERPROFILE',), app_data),
    1113         (('HOMEDRIVE','HOMEPATH'), app_data),
    1114         (('HOMEPATH',), app_data),
    1115         (('HOME',), None),
    1116         (('WINDIR',), app_data),    # 95/98/ME
    1117     ]
    1118 
    1119     for keys, subdir in app_homes:
    1120         dirname = ''
    1121         for key in keys:
    1122             if key in os.environ:
    1123                 dirname = os.path.join(dirname, os.environ[key])
    1124             else:
    1125                 break
    1126         else:
    1127             if subdir:
    1128                 dirname = os.path.join(dirname,subdir)
    1129             return os.path.join(dirname, 'Python-Eggs')
    1130     else:
    1131         raise RuntimeError(
    1132             "Please set the PYTHON_EGG_CACHE enviroment variable"
    1133         )
    1134 
    1135 def safe_name(name):
    1136     """Convert an arbitrary string to a standard distribution name
    1137 
    1138     Any runs of non-alphanumeric/. characters are replaced with a single '-'.
    1139     """
    1140     return re.sub('[^A-Za-z0-9.]+', '-', name)
    1141 
    1142 
    1143 def safe_version(version):
    1144     """Convert an arbitrary string to a standard version string
    1145 
    1146     Spaces become dots, and all other non-alphanumeric characters become
    1147     dashes, with runs of multiple dashes condensed to a single dash.
    1148     """
    1149     version = version.replace(' ','.')
    1150     return re.sub('[^A-Za-z0-9.]+', '-', version)
    1151 
    1152 
    1153 def safe_extra(extra):
    1154     """Convert an arbitrary string to a standard 'extra' name
    1155 
    1156     Any runs of non-alphanumeric characters are replaced with a single '_',
    1157     and the result is always lowercased.
    1158     """
    1159     return re.sub('[^A-Za-z0-9.]+', '_', extra).lower()
    1160 
    1161 
    1162 def to_filename(name):
    1163     """Convert a project or version name to its filename-escaped form
    1164 
    1165     Any '-' characters are currently replaced with '_'.
    1166     """
    1167     return name.replace('-','_')
    1168 
    1169 
    1170 
    1171 
    1172 
    1173 
    1174 
    1175 
    1176 class NullProvider:
    1177     """Try to implement resources and metadata for arbitrary PEP 302 loaders"""
    1178 
    1179     egg_name = None
    1180     egg_info = None
    1181     loader = None
    1182 
    1183     def __init__(self, module):
    1184         self.loader = getattr(module, '__loader__', None)
    1185         self.module_path = os.path.dirname(getattr(module, '__file__', ''))
    1186 
    1187     def get_resource_filename(self, manager, resource_name):
    1188         return self._fn(self.module_path, resource_name)
    1189 
    1190     def get_resource_stream(self, manager, resource_name):
    1191         return StringIO(self.get_resource_string(manager, resource_name))
    1192 
    1193     def get_resource_string(self, manager, resource_name):
    1194         return self._get(self._fn(self.module_path, resource_name))
    1195 
    1196     def has_resource(self, resource_name):
    1197         return self._has(self._fn(self.module_path, resource_name))
    1198 
    1199     def has_metadata(self, name):
    1200         return self.egg_info and self._has(self._fn(self.egg_info,name))
    1201 
    1202     def get_metadata(self, name):
    1203         if not self.egg_info:
    1204             return ""
    1205         return self._get(self._fn(self.egg_info,name))
    1206 
    1207     def get_metadata_lines(self, name):
    1208         return yield_lines(self.get_metadata(name))
    1209 
    1210     def resource_isdir(self,resource_name):
    1211         return self._isdir(self._fn(self.module_path, resource_name))
    1212 
    1213     def metadata_isdir(self,name):
    1214         return self.egg_info and self._isdir(self._fn(self.egg_info,name))
    1215 
    1216 
    1217     def resource_listdir(self,resource_name):
    1218         return self._listdir(self._fn(self.module_path,resource_name))
    1219 
    1220     def metadata_listdir(self,name):
    1221         if self.egg_info:
    1222             return self._listdir(self._fn(self.egg_info,name))
    1223         return []
    1224 
    1225     def run_script(self,script_name,namespace):
    1226         script = 'scripts/'+script_name
    1227         if not self.has_metadata(script):
    1228             raise ResolutionError("No script named %r" % script_name)
    1229         script_text = self.get_metadata(script).replace('\r\n','\n')
    1230         script_text = script_text.replace('\r','\n')
    1231         script_filename = self._fn(self.egg_info,script)
    1232         namespace['__file__'] = script_filename
    1233         if os.path.exists(script_filename):
    1234             execfile(script_filename, namespace, namespace)
    1235         else:
    1236             from linecache import cache
    1237             cache[script_filename] = (
    1238                 len(script_text), 0, script_text.split('\n'), script_filename
    1239             )
    1240             script_code = compile(script_text,script_filename,'exec')
    1241             exec script_code in namespace, namespace
    1242 
    1243     def _has(self, path):
    1244         raise NotImplementedError(
    1245             "Can't perform this operation for unregistered loader type"
    1246         )
    1247 
    1248     def _isdir(self, path):
    1249         raise NotImplementedError(
    1250             "Can't perform this operation for unregistered loader type"
    1251         )
    1252 
    1253     def _listdir(self, path):
    1254         raise NotImplementedError(
    1255             "Can't perform this operation for unregistered loader type"
    1256         )
    1257 
    1258     def _fn(self, base, resource_name):
    1259         if resource_name:
    1260             return os.path.join(base, *resource_name.split('/'))
    1261         return base
    1262 
    1263     def _get(self, path):
    1264         if hasattr(self.loader, 'get_data'):
    1265             return self.loader.get_data(path)
    1266         raise NotImplementedError(
    1267             "Can't perform this operation for loaders without 'get_data()'"
    1268         )
    1269 
    1270 register_loader_type(object, NullProvider)
    1271 
    1272 
    1273 class EggProvider(NullProvider):
    1274     """Provider based on a virtual filesystem"""
    1275 
    1276     def __init__(self,module):
    1277         NullProvider.__init__(self,module)
    1278         self._setup_prefix()
    1279 
    1280     def _setup_prefix(self):
    1281         # we assume here that our metadata may be nested inside a "basket"
    1282         # of multiple eggs; that's why we use module_path instead of .archive
    1283         path = self.module_path
    1284         old = None
    1285         while path!=old:
    1286             if path.lower().endswith('.egg'):
    1287                 self.egg_name = os.path.basename(path)
    1288                 self.egg_info = os.path.join(path, 'EGG-INFO')
    1289                 self.egg_root = path
    1290                 break
    1291             old = path
    1292             path, base = os.path.split(path)
    1293 
    1294 
    1295 
    1296 
    1297 
    1298 
    1299 class DefaultProvider(EggProvider):
    1300     """Provides access to package resources in the filesystem"""
    1301 
    1302     def _has(self, path):
    1303         return os.path.exists(path)
    1304 
    1305     def _isdir(self,path):
    1306         return os.path.isdir(path)
    1307 
    1308     def _listdir(self,path):
    1309         return os.listdir(path)
    1310 
    1311     def get_resource_stream(self, manager, resource_name):
    1312         return open(self._fn(self.module_path, resource_name), 'rb')
    1313 
    1314     def _get(self, path):
    1315         stream = open(path, 'rb')
    1316         try:
    1317             return stream.read()
    1318         finally:
    1319             stream.close()
    1320 
    1321 register_loader_type(type(None), DefaultProvider)
    1322 
    1323 
    1324 class EmptyProvider(NullProvider):
    1325     """Provider that returns nothing for all requests"""
    1326 
    1327     _isdir = _has = lambda self,path: False
    1328     _get          = lambda self,path: ''
    1329     _listdir      = lambda self,path: []
    1330     module_path   = None
    1331 
    1332     def __init__(self):
    1333         pass
    1334 
    1335 empty_provider = EmptyProvider()
    1336 
    1337 
    1338 
    1339 
    1340 class ZipProvider(EggProvider):
    1341     """Resource support for zips and eggs"""
    1342 
    1343     eagers = None
    1344 
    1345     def __init__(self, module):
    1346         EggProvider.__init__(self,module)
    1347         self.zipinfo = zipimport._zip_directory_cache[self.loader.archive]
    1348         self.zip_pre = self.loader.archive+os.sep
    1349 
    1350     def _zipinfo_name(self, fspath):
    1351         # Convert a virtual filename (full path to file) into a zipfile subpath
    1352         # usable with the zipimport directory cache for our target archive
    1353         if fspath.startswith(self.zip_pre):
    1354             return fspath[len(self.zip_pre):]
    1355         raise AssertionError(
    1356             "%s is not a subpath of %s" % (fspath,self.zip_pre)
    1357         )
    1358 
    1359     def _parts(self,zip_path):
    1360         # Convert a zipfile subpath into an egg-relative path part list
    1361         fspath = self.zip_pre+zip_path  # pseudo-fs path
    1362         if fspath.startswith(self.egg_root+os.sep):
    1363             return fspath[len(self.egg_root)+1:].split(os.sep)
    1364         raise AssertionError(
    1365             "%s is not a subpath of %s" % (fspath,self.egg_root)
    1366         )
    1367 
    1368     def get_resource_filename(self, manager, resource_name):
    1369         if not self.egg_name:
    1370             raise NotImplementedError(
    1371                 "resource_filename() only supported for .egg, not .zip"
    1372             )
    1373         # no need to lock for extraction, since we use temp names
    1374         zip_path = self._resource_to_zip(resource_name)
    1375         eagers = self._get_eager_resources()
    1376         if '/'.join(self._parts(zip_path)) in eagers:
    1377             for name in eagers:
    1378                 self._extract_resource(manager, self._eager_to_zip(name))
    1379         return self._extract_resource(manager, zip_path)
    1380 
    1381     def _extract_resource(self, manager, zip_path):
    1382 
    1383         if zip_path in self._index():
    1384             for name in self._index()[zip_path]:
    1385                 last = self._extract_resource(
    1386                     manager, os.path.join(zip_path, name)
    1387                 )
    1388             return os.path.dirname(last)  # return the extracted directory name
    1389 
    1390         zip_stat = self.zipinfo[zip_path]
    1391         t,d,size = zip_stat[5], zip_stat[6], zip_stat[3]
    1392         date_time = (
    1393             (d>>9)+1980, (d>>5)&0xF, d&0x1F,                      # ymd
    1394             (t&0xFFFF)>>11, (t>>5)&0x3F, (t&0x1F) * 2, 0, 0, -1   # hms, etc.
    1395         )
    1396         timestamp = time.mktime(date_time)
    1397 
    1398         try:
    1399             real_path = manager.get_cache_path(
    1400                 self.egg_name, self._parts(zip_path)
    1401             )
    1402 
    1403             if os.path.isfile(real_path):
    1404                 stat = os.stat(real_path)
    1405                 if stat.st_size==size and stat.st_mtime==timestamp:
    1406                     # size and stamp match, don't bother extracting
    1407                     return real_path
    1408 
    1409             outf, tmpnam = _mkstemp(".$extract", dir=os.path.dirname(real_path))
    1410             os.write(outf, self.loader.get_data(zip_path))
    1411             os.close(outf)
    1412             utime(tmpnam, (timestamp,timestamp))
    1413             manager.postprocess(tmpnam, real_path)
    1414 
    1415             try:
    1416                 rename(tmpnam, real_path)
    1417 
    1418             except os.error:
    1419                 if os.path.isfile(real_path):
    1420                     stat = os.stat(real_path)
    1421 
    1422                     if stat.st_size==size and stat.st_mtime==timestamp:
    1423                         # size and stamp match, somebody did it just ahead of
    1424                         # us, so we're done
    1425                         return real_path
    1426                     elif os.name=='nt':     # Windows, del old file and retry
    1427                         unlink(real_path)
    1428                         rename(tmpnam, real_path)
    1429                         return real_path
    1430                 raise
    1431 
    1432         except os.error:
    1433             manager.extraction_error()  # report a user-friendly error
    1434 
    1435         return real_path
    1436 
    1437     def _get_eager_resources(self):
    1438         if self.eagers is None:
    1439             eagers = []
    1440             for name in ('native_libs.txt', 'eager_resources.txt'):
    1441                 if self.has_metadata(name):
    1442                     eagers.extend(self.get_metadata_lines(name))
    1443             self.eagers = eagers
    1444         return self.eagers
    1445 
    1446     def _index(self):
    1447         try:
    1448             return self._dirindex
    1449         except AttributeError:
    1450             ind = {}
    1451             for path in self.zipinfo:
    1452                 parts = path.split(os.sep)
    1453                 while parts:
    1454                     parent = os.sep.join(parts[:-1])
    1455                     if parent in ind:
    1456                         ind[parent].append(parts[-1])
    1457                         break
    1458                     else:
    1459                         ind[parent] = [parts.pop()]
    1460             self._dirindex = ind
    1461             return ind
    1462 
    1463     def _has(self, fspath):
    1464         zip_path = self._zipinfo_name(fspath)
    1465         return zip_path in self.zipinfo or zip_path in self._index()
    1466 
    1467     def _isdir(self,fspath):
    1468         return self._zipinfo_name(fspath) in self._index()
    1469 
    1470     def _listdir(self,fspath):
    1471         return list(self._index().get(self._zipinfo_name(fspath), ()))
    1472 
    1473     def _eager_to_zip(self,resource_name):
    1474         return self._zipinfo_name(self._fn(self.egg_root,resource_name))
    1475 
    1476     def _resource_to_zip(self,resource_name):
    1477         return self._zipinfo_name(self._fn(self.module_path,resource_name))
    1478 
    1479 register_loader_type(zipimport.zipimporter, ZipProvider)
    1480 
    1481 
    1482 
    1483 
    1484 
    1485 
    1486 
    1487 
    1488 
    1489 
    1490 
    1491 
    1492 
    1493 
    1494 
    1495 
    1496 
    1497 
    1498 
    1499 
    1500 
    1501 
    1502 
    1503 
    1504 class FileMetadata(EmptyProvider):
    1505     """Metadata handler for standalone PKG-INFO files
    1506 
    1507     Usage::
    1508 
    1509         metadata = FileMetadata("/path/to/PKG-INFO")
    1510 
    1511     This provider rejects all data and metadata requests except for PKG-INFO,
    1512     which is treated as existing, and will be the contents of the file at
    1513     the provided location.
    1514     """
    1515 
    1516     def __init__(self,path):
    1517         self.path = path
    1518 
    1519     def has_metadata(self,name):
    1520         return name=='PKG-INFO'
    1521 
    1522     def get_metadata(self,name):
    1523         if name=='PKG-INFO':
    1524             return open(self.path,'rU').read()
    1525         raise KeyError("No metadata except PKG-INFO is available")
    1526 
    1527     def get_metadata_lines(self,name):
    1528         return yield_lines(self.get_metadata(name))
    1529 
    1530 
    1531 
    1532 
    1533 
    1534 
    1535 
    1536 
    1537 
    1538 
    1539 
    1540 
    1541 
    1542 
    1543 
    1544 
    1545 class PathMetadata(DefaultProvider):
    1546     """Metadata provider for egg directories
    1547 
    1548     Usage::
    1549 
    1550         # Development eggs:
    1551 
    1552         egg_info = "/path/to/PackageName.egg-info"
    1553         base_dir = os.path.dirname(egg_info)
    1554         metadata = PathMetadata(base_dir, egg_info)
    1555         dist_name = os.path.splitext(os.path.basename(egg_info))[0]
    1556         dist = Distribution(basedir,project_name=dist_name,metadata=metadata)
    1557 
    1558         # Unpacked egg directories:
    1559 
    1560         egg_path = "/path/to/PackageName-ver-pyver-etc.egg"
    1561         metadata = PathMetadata(egg_path, os.path.join(egg_path,'EGG-INFO'))
    1562         dist = Distribution.from_filename(egg_path, metadata=metadata)
    1563     """
    1564 
    1565     def __init__(self, path, egg_info):
    1566         self.module_path = path
    1567         self.egg_info = egg_info
    1568 
    1569 
    1570 class EggMetadata(ZipProvider):
    1571     """Metadata provider for .egg files"""
    1572 
    1573     def __init__(self, importer):
    1574         """Create a metadata provider from a zipimporter"""
    1575 
    1576         self.zipinfo = zipimport._zip_directory_cache[importer.archive]
    1577         self.zip_pre = importer.archive+os.sep
    1578         self.loader = importer
    1579         if importer.prefix:
    1580             self.module_path = os.path.join(importer.archive, importer.prefix)
    1581         else:
    1582             self.module_path = importer.archive
    1583         self._setup_prefix()
    1584 
    1585 
    1586 class ImpWrapper:
    1587     """PEP 302 Importer that wraps Python's "normal" import algorithm"""
    1588 
    1589     def __init__(self, path=None):
    1590         self.path = path
    1591 
    1592     def find_module(self, fullname, path=None):
    1593         subname = fullname.split(".")[-1]
    1594         if subname != fullname and self.path is None:
    1595             return None
    1596         if self.path is None:
    1597             path = None
    1598         else:
    1599             path = [self.path]
    1600         try:
    1601             file, filename, etc = imp.find_module(subname, path)
    1602         except ImportError:
    1603             return None
    1604         return ImpLoader(file, filename, etc)
    1605 
    1606 
    1607 class ImpLoader:
    1608     """PEP 302 Loader that wraps Python's "normal" import algorithm"""
    1609 
    1610     def __init__(self, file, filename, etc):
    1611         self.file = file
    1612         self.filename = filename
    1613         self.etc = etc
    1614 
    1615     def load_module(self, fullname):
    1616         try:
    1617             mod = imp.load_module(fullname, self.file, self.filename, self.etc)
    1618         finally:
    1619             if self.file: self.file.close()
    1620         # Note: we don't set __loader__ because we want the module to look
    1621         # normal; i.e. this is just a wrapper for standard import machinery
    1622         return mod
    1623 
    1624 
    1625 
    1626 
    1627 def get_importer(path_item):
    1628     """Retrieve a PEP 302 "importer" for the given path item
    1629 
    1630     If there is no importer, this returns a wrapper around the builtin import
    1631     machinery.  The returned importer is only cached if it was created by a
    1632     path hook.
    1633     """
    1634     try:
    1635         importer = sys.path_importer_cache[path_item]
    1636     except KeyError:
    1637         for hook in sys.path_hooks:
    1638             try:
    1639                 importer = hook(path_item)
    1640             except ImportError:
    1641                 pass
    1642             else:
    1643                 break
    1644         else:
    1645             importer = None
    1646 
    1647     sys.path_importer_cache.setdefault(path_item,importer)
    1648     if importer is None:
    1649         try:
    1650             importer = ImpWrapper(path_item)
    1651         except ImportError:
    1652             pass
    1653     return importer
    1654 
    1655 
    1656 
    1657 
    1658 
    1659 
    1660 
    1661 
    1662 
    1663 
    1664 
    1665 
    1666 
    1667 
    1668 _declare_state('dict', _distribution_finders = {})
    1669 
    1670 def register_finder(importer_type, distribution_finder):
    1671     """Register `distribution_finder` to find distributions in sys.path items
    1672 
    1673     `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
    1674     handler), and `distribution_finder` is a callable that, passed a path
    1675     item and the importer instance, yields ``Distribution`` instances found on
    1676     that path item.  See ``pkg_resources.find_on_path`` for an example."""
    1677     _distribution_finders[importer_type] = distribution_finder
    1678 
    1679 
    1680 def find_distributions(path_item, only=False):
    1681     """Yield distributions accessible via `path_item`"""
    1682     importer = get_importer(path_item)
    1683     finder = _find_adapter(_distribution_finders, importer)
    1684     return finder(importer, path_item, only)
    1685 
    1686 def find_in_zip(importer, path_item, only=False):
    1687     metadata = EggMetadata(importer)
    1688     if metadata.has_metadata('PKG-INFO'):
    1689         yield Distribution.from_filename(path_item, metadata=metadata)
    1690     if only:
    1691         return  # don't yield nested distros
    1692     for subitem in metadata.resource_listdir('/'):
    1693         if subitem.endswith('.egg'):
    1694             subpath = os.path.join(path_item, subitem)
    1695             for dist in find_in_zip(zipimport.zipimporter(subpath), subpath):
    1696                 yield dist
    1697 
    1698 register_finder(zipimport.zipimporter, find_in_zip)
    1699 
    1700 def StringIO(*args, **kw):
    1701     """Thunk to load the real StringIO on demand"""
    1702     global StringIO
    1703     try:
    1704         from cStringIO import StringIO
    1705     except ImportError:
    1706         from StringIO import StringIO
    1707     return StringIO(*args,**kw)
    1708 
    1709 def find_nothing(importer, path_item, only=False):
    1710     return ()
    1711 register_finder(object,find_nothing)
    1712 
    1713 def find_on_path(importer, path_item, only=False):
    1714     """Yield distributions accessible on a sys.path directory"""
    1715     path_item = _normalize_cached(path_item)
    1716 
    1717     if os.path.isdir(path_item) and os.access(path_item, os.R_OK):
    1718         if path_item.lower().endswith('.egg'):
    1719             # unpacked egg
    1720             yield Distribution.from_filename(
    1721                 path_item, metadata=PathMetadata(
    1722                     path_item, os.path.join(path_item,'EGG-INFO')
    1723                 )
    1724             )
    1725         else:
    1726             # scan for .egg and .egg-info in directory
    1727             for entry in os.listdir(path_item):
    1728                 lower = entry.lower()
    1729                 if lower.endswith('.egg-info'):
    1730                     fullpath = os.path.join(path_item, entry)
    1731                     if os.path.isdir(fullpath):
    1732                         # egg-info directory, allow getting metadata
    1733                         metadata = PathMetadata(path_item, fullpath)
    1734                     else:
    1735                         metadata = FileMetadata(fullpath)
    1736                     yield Distribution.from_location(
    1737                         path_item,entry,metadata,precedence=DEVELOP_DIST
    1738                     )
    1739                 elif not only and lower.endswith('.egg'):
    1740                     for dist in find_distributions(os.path.join(path_item, entry)):
    1741                         yield dist
    1742                 elif not only and lower.endswith('.egg-link'):
    1743                     for line in file(os.path.join(path_item, entry)):
    1744                         if not line.strip(): continue
    1745                         for item in find_distributions(os.path.join(path_item,line.rstrip())):
    1746                             yield item
    1747                         break
    1748 register_finder(ImpWrapper, find_on_path)
    1749 
    1750 _declare_state('dict', _namespace_handlers = {})
    1751 _declare_state('dict', _namespace_packages = {})
    1752 
    1753 def register_namespace_handler(importer_type, namespace_handler):
    1754     """Register `namespace_handler` to declare namespace packages
    1755 
    1756     `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
    1757     handler), and `namespace_handler` is a callable like this::
    1758 
    1759         def namespace_handler(importer,path_entry,moduleName,module):
    1760             # return a path_entry to use for child packages
    1761 
    1762     Namespace handlers are only called if the importer object has already
    1763     agreed that it can handle the relevant path item, and they should only
    1764     return a subpath if the module __path__ does not already contain an
    1765     equivalent subpath.  For an example namespace handler, see
    1766     ``pkg_resources.file_ns_handler``.
    1767     """
    1768     _namespace_handlers[importer_type] = namespace_handler
    1769 
    1770 def _handle_ns(packageName, path_item):
    1771     """Ensure that named package includes a subpath of path_item (if needed)"""
    1772     importer = get_importer(path_item)
    1773     if importer is None:
    1774         return None
    1775     loader = importer.find_module(packageName)
    1776     if loader is None:
    1777         return None
    1778     module = sys.modules.get(packageName)
    1779     if module is None:
    1780         module = sys.modules[packageName] = imp.new_module(packageName)
    1781         module.__path__ = []; _set_parent_ns(packageName)
    1782     elif not hasattr(module,'__path__'):
    1783         raise TypeError("Not a package:", packageName)
    1784     handler = _find_adapter(_namespace_handlers, importer)
    1785     subpath = handler(importer,path_item,packageName,module)
    1786     if subpath is not None:
    1787         path = module.__path__; path.append(subpath)
    1788         loader.load_module(packageName); module.__path__ = path
    1789     return subpath
    1790 
    1791 def declare_namespace(packageName):
    1792     """Declare that package 'packageName' is a namespace package"""
    1793 
    1794     imp.acquire_lock()
    1795     try:
    1796         if packageName in _namespace_packages:
    1797             return
    1798 
    1799         path, parent = sys.path, None
    1800         if '.' in packageName:
    1801             parent = '.'.join(packageName.split('.')[:-1])
    1802             declare_namespace(parent)
    1803             __import__(parent)
    1804             try:
    1805                 path = sys.modules[parent].__path__
    1806             except AttributeError:
    1807                 raise TypeError("Not a package:", parent)
    1808 
    1809         # Track what packages are namespaces, so when new path items are added,
    1810         # they can be updated
    1811         _namespace_packages.setdefault(parent,[]).append(packageName)
    1812         _namespace_packages.setdefault(packageName,[])
    1813 
    1814         for path_item in path:
    1815             # Ensure all the parent's path items are reflected in the child,
    1816             # if they apply
    1817             _handle_ns(packageName, path_item)
    1818 
    1819     finally:
    1820         imp.release_lock()
    1821 
    1822 def fixup_namespace_packages(path_item, parent=None):
    1823     """Ensure that previously-declared namespace packages include path_item"""
    1824     imp.acquire_lock()
    1825     try:
    1826         for package in _namespace_packages.get(parent,()):
    1827             subpath = _handle_ns(package, path_item)
    1828             if subpath: fixup_namespace_packages(subpath,package)
    1829     finally:
    1830         imp.release_lock()
    1831 
    1832 def file_ns_handler(importer, path_item, packageName, module):
    1833     """Compute an ns-package subpath for a filesystem or zipfile importer"""
    1834 
    1835     subpath = os.path.join(path_item, packageName.split('.')[-1])
    1836     normalized = _normalize_cached(subpath)
    1837     for item in module.__path__:
    1838         if _normalize_cached(item)==normalized:
    1839             break
    1840     else:
    1841         # Only return the path if it's not already there
    1842         return subpath
    1843 
    1844 register_namespace_handler(ImpWrapper,file_ns_handler)
    1845 register_namespace_handler(zipimport.zipimporter,file_ns_handler)
    1846 
    1847 
    1848 def null_ns_handler(importer, path_item, packageName, module):
    1849     return None
    1850 
    1851 register_namespace_handler(object,null_ns_handler)
    1852 
    1853 
    1854 def normalize_path(filename):
    1855     """Normalize a file/dir name for comparison purposes"""
    1856     return os.path.normcase(os.path.realpath(filename))
    1857 
    1858 def _normalize_cached(filename,_cache={}):
    1859     try:
    1860         return _cache[filename]
    1861     except KeyError:
    1862         _cache[filename] = result = normalize_path(filename)
    1863         return result
    1864 
    1865 def _set_parent_ns(packageName):
    1866     parts = packageName.split('.')
    1867     name = parts.pop()
    1868     if parts:
    1869         parent = '.'.join(parts)
    1870         setattr(sys.modules[parent], name, sys.modules[packageName])
    1871 
    1872 
    1873 def yield_lines(strs):
    1874     """Yield non-empty/non-comment lines of a ``basestring`` or sequence"""
    1875     if isinstance(strs,basestring):
    1876         for s in strs.splitlines():
    1877             s = s.strip()
    1878             if s and not s.startswith('#'):     # skip blank lines/comments
    1879                 yield s
    1880     else:
    1881         for ss in strs:
    1882             for s in yield_lines(ss):
    1883                 yield s
    1884 
    1885 LINE_END = re.compile(r"\s*(#.*)?$").match         # whitespace and comment
    1886 CONTINUE = re.compile(r"\s*\\\s*(#.*)?$").match    # line continuation
    1887 DISTRO   = re.compile(r"\s*((\w|[-.])+)").match    # Distribution or extra
    1888 VERSION  = re.compile(r"\s*(<=?|>=?|==|!=)\s*((\w|[-.])+)").match  # ver. info
    1889 COMMA    = re.compile(r"\s*,").match               # comma between items
    1890 OBRACKET = re.compile(r"\s*\[").match
    1891 CBRACKET = re.compile(r"\s*\]").match
    1892 MODULE   = re.compile(r"\w+(\.\w+)*$").match
    1893 EGG_NAME = re.compile(
    1894     r"(?P<name>[^-]+)"
    1895     r"( -(?P<ver>[^-]+) (-py(?P<pyver>[^-]+) (-(?P<plat>.+))? )? )?",
    1896     re.VERBOSE | re.IGNORECASE
    1897 ).match
    1898 
    1899 component_re = re.compile(r'(\d+ | [a-z]+ | \.| -)', re.VERBOSE)
    1900 replace = {'pre':'c', 'preview':'c','-':'final-','rc':'c','dev':'@'}.get
    1901 
    1902 def _parse_version_parts(s):
    1903     for part in component_re.split(s):
    1904         part = replace(part,part)
    1905         if not part or part=='.':
    1906             continue
    1907         if part[:1] in '0123456789':
    1908             yield part.zfill(8)    # pad for numeric comparison
    1909         else:
    1910             yield '*'+part
    1911 
    1912     yield '*final'  # ensure that alpha/beta/candidate are before final
    1913 
    1914 def parse_version(s):
    1915     """Convert a version string to a chronologically-sortable key
    1916 
    1917     This is a rough cross between distutils' StrictVersion and LooseVersion;
    1918     if you give it versions that would work with StrictVersion, then it behaves
    1919     the same; otherwise it acts like a slightly-smarter LooseVersion. It is
    1920     *possible* to create pathological version coding schemes that will fool
    1921     this parser, but they should be very rare in practice.
    1922 
    1923     The returned value will be a tuple of strings.  Numeric portions of the
    1924     version are padded to 8 digits so they will compare numerically, but
    1925     without relying on how numbers compare relative to strings.  Dots are
    1926     dropped, but dashes are retained.  Trailing zeros between alpha segments
    1927     or dashes are suppressed, so that e.g. "2.4.0" is considered the same as
    1928     "2.4". Alphanumeric parts are lower-cased.
    1929 
    1930     The algorithm assumes that strings like "-" and any alpha string that
    1931     alphabetically follows "final"  represents a "patch level".  So, "2.4-1"
    1932     is assumed to be a branch or patch of "2.4", and therefore "2.4.1" is
    1933     considered newer than "2.4-1", which in turn is newer than "2.4".
    1934 
    1935     Strings like "a", "b", "c", "alpha", "beta", "candidate" and so on (that
    1936     come before "final" alphabetically) are assumed to be pre-release versions,
    1937     so that the version "2.4" is considered newer than "2.4a1".
    1938 
    1939     Finally, to handle miscellaneous cases, the strings "pre", "preview", and
    1940     "rc" are treated as if they were "c", i.e. as though they were release
    1941     candidates, and therefore are not as new as a version string that does not
    1942     contain them, and "dev" is replaced with an '@' so that it sorts lower than
    1943     than any other pre-release tag.
    1944     """
    1945     parts = []
    1946     for part in _parse_version_parts(s.lower()):
    1947         if part.startswith('*'):
    1948             if part<'*final':   # remove '-' before a prerelease tag
    1949                 while parts and parts[-1]=='*final-': parts.pop()
    1950             # remove trailing zeros from each series of numeric parts
    1951             while parts and parts[-1]=='00000000':
    1952                 parts.pop()
    1953         parts.append(part)
    1954     return tuple(parts)
    1955 
    1956 class EntryPoint(object):
    1957     """Object representing an advertised importable object"""
    1958 
    1959     def __init__(self, name, module_name, attrs=(), extras=(), dist=None):
    1960         if not MODULE(module_name):
    1961             raise ValueError("Invalid module name", module_name)
    1962         self.name = name
    1963         self.module_name = module_name
    1964         self.attrs = tuple(attrs)
    1965         self.extras = Requirement.parse(("x[%s]" % ','.join(extras))).extras
    1966         self.dist = dist
    1967 
    1968     def __str__(self):
    1969         s = "%s = %s" % (self.name, self.module_name)
    1970         if self.attrs:
    1971             s += ':' + '.'.join(self.attrs)
    1972         if self.extras:
    1973             s += ' [%s]' % ','.join(self.extras)
    1974         return s
    1975 
    1976     def __repr__(self):
    1977         return "EntryPoint.parse(%r)" % str(self)
    1978 
    1979     def load(self, require=True, env=None, installer=None):
    1980         if require: self.require(env, installer)
    1981         entry = __import__(self.module_name, globals(),globals(), ['__name__'])
    1982         for attr in self.attrs:
    1983             try:
    1984                 entry = getattr(entry,attr)
    1985             except AttributeError:
    1986                 raise ImportError("%r has no %r attribute" % (entry,attr))
    1987         return entry
    1988 
    1989     def require(self, env=None, installer=None):
    1990         if self.extras and not self.dist:
    1991             raise UnknownExtra("Can't require() without a distribution", self)
    1992         map(working_set.add,
    1993             working_set.resolve(self.dist.requires(self.extras),env,installer))
    1994 
    1995 
    1996 
    1997     #@classmethod
    1998     def parse(cls, src, dist=None):
    1999         """Parse a single entry point from string `src`
    2000 
    2001         Entry point syntax follows the form::
    2002 
    2003             name = some.module:some.attr [extra1,extra2]
    2004 
    2005         The entry name and module name are required, but the ``:attrs`` and
    2006         ``[extras]`` parts are optional
    2007         """
    2008         try:
    2009             attrs = extras = ()
    2010             name,value = src.split('=',1)
    2011             if '[' in value:
    2012                 value,extras = value.split('[',1)
    2013                 req = Requirement.parse("x["+extras)
    2014                 if req.specs: raise ValueError
    2015                 extras = req.extras
    2016             if ':' in value:
    2017                 value,attrs = value.split(':',1)
    2018                 if not MODULE(attrs.rstrip()):
    2019                     raise ValueError
    2020                 attrs = attrs.rstrip().split('.')
    2021         except ValueError:
    2022             raise ValueError(
    2023                 "EntryPoint must be in 'name=module:attrs [extras]' format",
    2024                 src
    2025             )
    2026         else:
    2027             return cls(name.strip(), value.strip(), attrs, extras, dist)
    2028 
    2029     parse = classmethod(parse)
    2030 
    2031 
    2032 
    2033 
    2034 
    2035 
    2036 
    2037 
    2038     #@classmethod
    2039     def parse_group(cls, group, lines, dist=None):
    2040         """Parse an entry point group"""
    2041         if not MODULE(group):
    2042             raise ValueError("Invalid group name", group)
    2043         this = {}
    2044         for line in yield_lines(lines):
    2045             ep = cls.parse(line, dist)
    2046             if ep.name in this:
    2047                 raise ValueError("Duplicate entry point", group, ep.name)
    2048             this[ep.name]=ep
    2049         return this
    2050 
    2051     parse_group = classmethod(parse_group)
    2052 
    2053     #@classmethod
    2054     def parse_map(cls, data, dist=None):
    2055         """Parse a map of entry point groups"""
    2056         if isinstance(data,dict):
    2057             data = data.items()
    2058         else:
    2059             data = split_sections(data)
    2060         maps = {}
    2061         for group, lines in data:
    2062             if group is None:
    2063                 if not lines:
    2064                     continue
    2065                 raise ValueError("Entry points must be listed in groups")
    2066             group = group.strip()
    2067             if group in maps:
    2068                 raise ValueError("Duplicate group name", group)
    2069             maps[group] = cls.parse_group(group, lines, dist)
    2070         return maps
    2071 
    2072     parse_map = classmethod(parse_map)
    2073 
    2074 
    2075 
    2076 
    2077 
    2078 
    2079 class Distribution(object):
    2080     """Wrap an actual or potential sys.path entry w/metadata"""
    2081     def __init__(self,
    2082         location=None, metadata=None, project_name=None, version=None,
    2083         py_version=PY_MAJOR, platform=None, precedence = EGG_DIST
    2084     ):
    2085         self.project_name = safe_name(project_name or 'Unknown')
    2086         if version is not None:
    2087             self._version = safe_version(version)
    2088         self.py_version = py_version
    2089         self.platform = platform
    2090         self.location = location
    2091         self.precedence = precedence
    2092         self._provider = metadata or empty_provider
    2093 
    2094     #@classmethod
    2095     def from_location(cls,location,basename,metadata=None,**kw):
    2096         project_name, version, py_version, platform = [None]*4
    2097         basename, ext = os.path.splitext(basename)
    2098         if ext.lower() in (".egg",".egg-info"):
    2099             match = EGG_NAME(basename)
    2100             if match:
    2101                 project_name, version, py_version, platform = match.group(
    2102                     'name','ver','pyver','plat'
    2103                 )
    2104         return cls(
    2105             location, metadata, project_name=project_name, version=version,
    2106             py_version=py_version, platform=platform, **kw
    2107         )
    2108     from_location = classmethod(from_location)
    2109 
    2110     hashcmp = property(
    2111         lambda self: (
    2112             getattr(self,'parsed_version',()), self.precedence, self.key,
    2113             -len(self.location or ''), self.location, self.py_version,
    2114             self.platform
    2115         )
    2116     )
    2117     def __cmp__(self, other): return cmp(self.hashcmp, other)
    2118     def __hash__(self): return hash(self.hashcmp)
    2119 
    2120     # These properties have to be lazy so that we don't have to load any
    2121     # metadata until/unless it's actually needed.  (i.e., some distributions
    2122     # may not know their name or version without loading PKG-INFO)
    2123 
    2124     #@property
    2125     def key(self):
    2126         try:
    2127             return self._key
    2128         except AttributeError:
    2129             self._key = key = self.project_name.lower()
    2130             return key
    2131     key = property(key)
    2132 
    2133     #@property
    2134     def parsed_version(self):
    2135         try:
    2136             return self._parsed_version
    2137         except AttributeError:
    2138             self._parsed_version = pv = parse_version(self.version)
    2139             return pv
    2140 
    2141     parsed_version = property(parsed_version)
    2142 
    2143     #@property
    2144     def version(self):
    2145         try:
    2146             return self._version
    2147         except AttributeError:
    2148             for line in self._get_metadata('PKG-INFO'):
    2149                 if line.lower().startswith('version:'):
    2150                     self._version = safe_version(line.split(':',1)[1].strip())
    2151                     return self._version
    2152             else:
    2153                 raise ValueError(
    2154                     "Missing 'Version:' header and/or PKG-INFO file", self
    2155                 )
    2156     version = property(version)
    2157 
    2158 
    2159 
    2160 
    2161     #@property
    2162     def _dep_map(self):
    2163         try:
    2164             return self.__dep_map
    2165         except AttributeError:
    2166             dm = self.__dep_map = {None: []}
    2167             for name in 'requires.txt', 'depends.txt':
    2168                 for extra,reqs in split_sections(self._get_metadata(name)):
    2169                     if extra: extra = safe_extra(extra)
    2170                     dm.setdefault(extra,[]).extend(parse_requirements(reqs))
    2171             return dm
    2172     _dep_map = property(_dep_map)
    2173 
    2174     def requires(self,extras=()):
    2175         """List of Requirements needed for this distro if `extras` are used"""
    2176         dm = self._dep_map
    2177         deps = []
    2178         deps.extend(dm.get(None,()))
    2179         for ext in extras:
    2180             try:
    2181                 deps.extend(dm[safe_extra(ext)])
    2182             except KeyError:
    2183                 raise UnknownExtra(
    2184                     "%s has no such extra feature %r" % (self, ext)
    2185                 )
    2186         return deps
    2187 
    2188     def _get_metadata(self,name):
    2189         if self.has_metadata(name):
    2190             for line in self.get_metadata_lines(name):
    2191                 yield line
    2192 
    2193     def activate(self,path=None):
    2194         """Ensure distribution is importable on `path` (default=sys.path)"""
    2195         if path is None: path = sys.path
    2196         self.insert_on(path)
    2197         if path is sys.path:
    2198             fixup_namespace_packages(self.location)
    2199             for pkg in self._get_metadata('namespace_packages.txt'):
    2200                 if pkg in sys.modules: declare_namespace(pkg)
    2201 
    2202     def egg_name(self):
    2203         """Return what this distribution's standard .egg filename should be"""
    2204         filename = "%s-%s-py%s" % (
    2205             to_filename(self.project_name), to_filename(self.version),
    2206             self.py_version or PY_MAJOR
    2207         )
    2208 
    2209         if self.platform:
    2210             filename += '-'+self.platform
    2211         return filename
    2212 
    2213     def __repr__(self):
    2214         if self.location:
    2215             return "%s (%s)" % (self,self.location)
    2216         else:
    2217             return str(self)
    2218 
    2219     def __str__(self):
    2220         try: version = getattr(self,'version',None)
    2221         except ValueError: version = None
    2222         version = version or "[unknown version]"
    2223         return "%s %s" % (self.project_name,version)
    2224 
    2225     def __getattr__(self,attr):
    2226         """Delegate all unrecognized public attributes to .metadata provider"""
    2227         if attr.startswith('_'):
    2228             raise AttributeError,attr
    2229         return getattr(self._provider, attr)
    2230 
    2231     #@classmethod
    2232     def from_filename(cls,filename,metadata=None, **kw):
    2233         return cls.from_location(
    2234             _normalize_cached(filename), os.path.basename(filename), metadata,
    2235             **kw
    2236         )
    2237     from_filename = classmethod(from_filename)
    2238 
    2239     def as_requirement(self):
    2240         """Return a ``Requirement`` that matches this distribution exactly"""
    2241         return Requirement.parse('%s==%s' % (self.project_name, self.version))
    2242 
    2243     def load_entry_point(self, group, name):
    2244         """Return the `name` entry point of `group` or raise ImportError"""
    2245         ep = self.get_entry_info(group,name)
    2246         if ep is None:
    2247             raise ImportError("Entry point %r not found" % ((group,name),))
    2248         return ep.load()
    2249 
    2250     def get_entry_map(self, group=None):
    2251         """Return the entry point map for `group`, or the full entry map"""
    2252         try:
    2253             ep_map = self._ep_map
    2254         except AttributeError:
    2255             ep_map = self._ep_map = EntryPoint.parse_map(
    2256                 self._get_metadata('entry_points.txt'), self
    2257             )
    2258         if group is not None:
    2259             return ep_map.get(group,{})
    2260         return ep_map
    2261 
    2262     def get_entry_info(self, group, name):
    2263         """Return the EntryPoint object for `group`+`name`, or ``None``"""
    2264         return self.get_entry_map(group).get(name)
    2265 
    2266 
    2267 
    2268 
    2269 
    2270 
    2271 
    2272 
    2273 
    2274 
    2275 
    2276 
    2277 
    2278 
    2279 
    2280 
    2281 
    2282 
    2283 
    2284     def insert_on(self, path, loc = None):
    2285         """Insert self.location in path before its nearest parent directory"""
    2286 
    2287         loc = loc or self.location
    2288         if not loc:
    2289             return
    2290 
    2291         nloc = _normalize_cached(loc)
    2292         bdir = os.path.dirname(nloc)
    2293         npath= [(p and _normalize_cached(p) or p) for p in path]
    2294 
    2295         bp = None
    2296         for p, item in enumerate(npath):
    2297             if item==nloc:
    2298                 break
    2299             elif item==bdir and self.precedence==EGG_DIST:
    2300                 # if it's an .egg, give it precedence over its directory
    2301                 if path is sys.path:
    2302                     self.check_version_conflict()
    2303                 path.insert(p, loc)
    2304                 npath.insert(p, nloc)
    2305                 break
    2306         else:
    2307             if path is sys.path:
    2308                 self.check_version_conflict()
    2309             path.append(loc)
    2310             return
    2311 
    2312         # p is the spot where we found or inserted loc; now remove duplicates
    2313         while 1:
    2314             try:
    2315                 np = npath.index(nloc, p+1)
    2316             except ValueError:
    2317                 break
    2318             else:
    2319                 del npath[np], path[np]
    2320                 p = np  # ha!
    2321 
    2322         return
    2323 
    2324 
    2325     def check_version_conflict(self):
    2326         if self.key=='setuptools':
    2327             return      # ignore the inevitable setuptools self-conflicts  :(
    2328 
    2329         nsp = dict.fromkeys(self._get_metadata('namespace_packages.txt'))
    2330         loc = normalize_path(self.location)
    2331         for modname in self._get_metadata('top_level.txt'):
    2332             if (modname not in sys.modules or modname in nsp
    2333                 or modname in _namespace_packages
    2334             ):
    2335                 continue
    2336 
    2337             fn = getattr(sys.modules[modname], '__file__', None)
    2338             if fn and (normalize_path(fn).startswith(loc) or fn.startswith(loc)):
    2339                 continue
    2340             issue_warning(
    2341                 "Module %s was already imported from %s, but %s is being added"
    2342                 " to sys.path" % (modname, fn, self.location),
    2343             )
    2344 
    2345     def has_version(self):
    2346         try:
    2347             self.version
    2348         except ValueError:
    2349             issue_warning("Unbuilt egg for "+repr(self))
    2350             return False
    2351         return True
    2352 
    2353     def clone(self,**kw):
    2354         """Copy this distribution, substituting in any changed keyword args"""
    2355         for attr in (
    2356             'project_name', 'version', 'py_version', 'platform', 'location',
    2357             'precedence'
    2358         ):
    2359             kw.setdefault(attr, getattr(self,attr,None))
    2360         kw.setdefault('metadata', self._provider)
    2361         return self.__class__(**kw)
    2362 
    2363 
    2364 
    2365 
    2366     #@property
    2367     def extras(self):
    2368         return [dep for dep in self._dep_map if dep]
    2369     extras = property(extras)
    2370 
    2371 
    2372 def issue_warning(*args,**kw):
    2373     level = 1
    2374     g = globals()
    2375     try:
    2376         # find the first stack frame that is *not* code in
    2377         # the pkg_resources module, to use for the warning
    2378         while sys._getframe(level).f_globals is g:
    2379             level += 1
    2380     except ValueError:
    2381         pass
    2382     from warnings import warn
    2383     warn(stacklevel = level+1, *args, **kw)
    2384 
    2385 
    2386 
    2387 
    2388 
    2389 
    2390 
    2391 
    2392 
    2393 
    2394 
    2395 
    2396 
    2397 
    2398 
    2399 
    2400 
    2401 
    2402 
    2403 
    2404 
    2405 
    2406 
    2407 def parse_requirements(strs):
    2408     """Yield ``Requirement`` objects for each specification in `strs`
    2409 
    2410     `strs` must be an instance of ``basestring``, or a (possibly-nested)
    2411     iterable thereof.
    2412     """
    2413     # create a steppable iterator, so we can handle \-continuations
    2414     lines = iter(yield_lines(strs))
    2415 
    2416     def scan_list(ITEM,TERMINATOR,line,p,groups,item_name):
    2417 
    2418         items = []
    2419 
    2420         while not TERMINATOR(line,p):
    2421             if CONTINUE(line,p):
    2422                 try:
    2423                     line = lines.next(); p = 0
    2424                 except StopIteration:
    2425                     raise ValueError(
    2426                         "\\ must not appear on the last nonblank line"
    2427                     )
    2428 
    2429             match = ITEM(line,p)
    2430             if not match:
    2431                 raise ValueError("Expected "+item_name+" in",line,"at",line[p:])
    2432 
    2433             items.append(match.group(*groups))
    2434             p = match.end()
    2435 
    2436             match = COMMA(line,p)
    2437             if match:
    2438                 p = match.end() # skip the comma
    2439             elif not TERMINATOR(line,p):
    2440                 raise ValueError(
    2441                     "Expected ',' or end-of-list in",line,"at",line[p:]
    2442                 )
    2443 
    2444         match = TERMINATOR(line,p)
    2445         if match: p = match.end()   # skip the terminator, if any
    2446         return line, p, items
    2447 
    2448     for line in lines:
    2449         match = DISTRO(line)
    2450         if not match:
    2451             raise ValueError("Missing distribution spec", line)
    2452         project_name = match.group(1)
    2453         p = match.end()
    2454         extras = []
    2455 
    2456         match = OBRACKET(line,p)
    2457         if match:
    2458             p = match.end()
    2459             line, p, extras = scan_list(
    2460                 DISTRO, CBRACKET, line, p, (1,), "'extra' name"
    2461             )
    2462 
    2463         line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec")
    2464         specs = [(op,safe_version(val)) for op,val in specs]
    2465         yield Requirement(project_name, specs, extras)
    2466 
    2467 
    2468 def _sort_dists(dists):
    2469     tmp = [(dist.hashcmp,dist) for dist in dists]
    2470     tmp.sort()
    2471     dists[::-1] = [d for hc,d in tmp]
    2472 
    2473 
    2474 
    2475 
    2476 
    2477 
    2478 
    2479 
    2480 
    2481 
    2482 
    2483 
    2484 
    2485 
    2486 
    2487 
    2488 
    2489 class Requirement:
    2490     def __init__(self, project_name, specs, extras):
    2491         """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
    2492         self.unsafe_name, project_name = project_name, safe_name(project_name)
    2493         self.project_name, self.key = project_name, project_name.lower()
    2494         index = [(parse_version(v),state_machine[op],op,v) for op,v in specs]
    2495         index.sort()
    2496         self.specs = [(op,ver) for parsed,trans,op,ver in index]
    2497         self.index, self.extras = index, tuple(map(safe_extra,extras))
    2498         self.hashCmp = (
    2499             self.key, tuple([(op,parsed) for parsed,trans,op,ver in index]),
    2500             frozenset(self.extras)
    2501         )
    2502         self.__hash = hash(self.hashCmp)
    2503 
    2504     def __str__(self):
    2505         specs = ','.join([''.join(s) for s in self.specs])
    2506         extras = ','.join(self.extras)
    2507         if extras: extras = '[%s]' % extras
    2508         return '%s%s%s' % (self.project_name, extras, specs)
    2509 
    2510     def __eq__(self,other):
    2511         return isinstance(other,Requirement) and self.hashCmp==other.hashCmp
    2512 
    2513     def __contains__(self,item):
    2514         if isinstance(item,Distribution):
    2515             if item.key != self.key: return False
    2516             if self.index: item = item.parsed_version  # only get if we need it
    2517         elif isinstance(item,basestring):
    2518             item = parse_version(item)
    2519         last = None
    2520         for parsed,trans,op,ver in self.index:
    2521             action = trans[cmp(item,parsed)]
    2522             if action=='F':     return False
    2523             elif action=='T':   return True
    2524             elif action=='+':   last = True
    2525             elif action=='-' or last is None:   last = False
    2526         if last is None: last = True    # no rules encountered
    2527         return last
    2528 
    2529 
    2530     def __hash__(self):
    2531         return self.__hash
    2532 
    2533     def __repr__(self): return "Requirement.parse(%r)" % str(self)
    2534 
    2535     #@staticmethod
    2536     def parse(s):
    2537         reqs = list(parse_requirements(s))
    2538         if reqs:
    2539             if len(reqs)==1:
    2540                 return reqs[0]
    2541             raise ValueError("Expected only one requirement", s)
    2542         raise ValueError("No requirements found", s)
    2543 
    2544     parse = staticmethod(parse)
    2545 
    2546 state_machine = {
    2547     #       =><
    2548     '<' :  '--T',
    2549     '<=':  'T-T',
    2550     '>' :  'F+F',
    2551     '>=':  'T+F',
    2552     '==':  'T..',
    2553     '!=':  'F++',
    2554 }
    2555 
    2556 
    2557 def _get_mro(cls):
    2558     """Get an mro for a type or classic class"""
    2559     if not isinstance(cls,type):
    2560         class cls(cls,object): pass
    2561         return cls.__mro__[1:]
    2562     return cls.__mro__
    2563 
    2564 def _find_adapter(registry, ob):
    2565     """Return an adapter factory for `ob` from `registry`"""
    2566     for t in _get_mro(getattr(ob, '__class__', type(ob))):
    2567         if t in registry:
    2568             return registry[t]
    2569 
    2570 
    2571 def ensure_directory(path):
    2572     """Ensure that the parent directory of `path` exists"""
    2573     dirname = os.path.dirname(path)
    2574     if not os.path.isdir(dirname):
    2575         os.makedirs(dirname)
    2576 
    2577 def split_sections(s):
    2578     """Split a string or iterable thereof into (section,content) pairs
    2579 
    2580     Each ``section`` is a stripped version of the section header ("[section]")
    2581     and each ``content`` is a list of stripped lines excluding blank lines and
    2582     comment-only lines.  If there are any such lines before the first section
    2583     header, they're returned in a first ``section`` of ``None``.
    2584     """
    2585     section = None
    2586     content = []
    2587     for line in yield_lines(s):
    2588         if line.startswith("["):
    2589             if line.endswith("]"):
    2590                 if section or content:
    2591                     yield section, content
    2592                 section = line[1:-1].strip()
    2593                 content = []
    2594             else:
    2595                 raise ValueError("Invalid section heading", line)
    2596         else:
    2597             content.append(line)
    2598 
    2599     # wrap up last segment
    2600     yield section, content
    2601 
    2602 def _mkstemp(*args,**kw):
    2603     from tempfile import mkstemp
    2604     old_open = os.open
    2605     try:
    2606         os.open = os_open   # temporarily bypass sandboxing
    2607         return mkstemp(*args,**kw)
    2608     finally:
    2609         os.open = old_open  # and then put it back
    2610 
    2611 
    2612 # Set up global resource manager (deliberately not state-saved)
    2613 _manager = ResourceManager()
    2614 def _initialize(g):
    2615     for name in dir(_manager):
    2616         if not name.startswith('_'):
    2617             g[name] = getattr(_manager, name)
    2618 _initialize(globals())
    2619 
    2620 # Prepare the master working set and make the ``require()`` API available
    2621 __requires__ = None
    2622 _declare_state('object', working_set = WorkingSet())
    2623 try:
    2624     # Does the main program list any requirements?
    2625     from __main__ import __requires__
    2626 except ImportError:
    2627     pass # No: just use the default working set based on sys.path
    2628 else:
    2629     # Yes: ensure the requirements are met, by prefixing sys.path if necessary
    2630     try:
    2631         working_set.require(__requires__)
    2632     except (VersionConflict, DistributionNotFound):     # try it without defaults already on sys.path
    2633         working_set = WorkingSet([])    # by starting with an empty path
    2634         try:
    2635             for dist in working_set.resolve(
    2636                 parse_requirements(__requires__), Environment()
    2637                 ):
    2638                 working_set.add(dist)
    2639         except DistributionNotFound:
    2640             pass
    2641         for entry in sys.path:  # add any missing entries from sys.path
    2642             if entry not in working_set.entries:
    2643                 working_set.add_entry(entry)
    2644         sys.path[:] = working_set.entries   # then copy back to sys.path
    2645 
    2646 require = working_set.require
    2647 iter_entry_points = working_set.iter_entry_points
    2648 add_activation_listener = working_set.subscribe
    2649 run_script = working_set.run_script
    2650 run_main = run_script   # backward compatibility
    2651 # Activate all distributions already on sys.path, and ensure that
    2652 # all distributions added to the working set in the future (e.g. by
    2653 # calling ``require()``) will get activated as well.
    2654 add_activation_listener(lambda dist: dist.activate())
    2655 working_set.entries=[]; map(working_set.add_entry,sys.path) # match order
    2656 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/__init__.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/__init__.py b/setuptools-0.6c16dev4.egg/setuptools/__init__.py
    deleted file mode 100644
    index 8b4f1ca..0000000
    + -  
    1 """Extensions to the 'distutils' for large or complex distributions"""
    2 from setuptools.extension import Extension, Library
    3 from setuptools.dist import Distribution, Feature, _get_unpatched
    4 import distutils.core, setuptools.command
    5 from setuptools.depends import Require
    6 from distutils.core import Command as _Command
    7 from distutils.util import convert_path
    8 import os.path
    9 import os
    10 import sys
    11 
    12 __version__ = '0.6c16dev4'
    13 __all__ = [
    14     'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require',
    15     'find_packages'
    16 ]
    17 
    18 bootstrap_install_from = None
    19 
    20 def find_packages(where='.', exclude=()):
    21     """Return a list all Python packages found within directory 'where'
    22 
    23     'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it
    24     will be converted to the appropriate local path syntax.  'exclude' is a
    25     sequence of package names to exclude; '*' can be used as a wildcard in the
    26     names, such that 'foo.*' will exclude all subpackages of 'foo' (but not
    27     'foo' itself).
    28     """
    29     out = []
    30     stack=[(convert_path(where), '')]
    31     while stack:
    32         where,prefix = stack.pop(0)
    33         for name in os.listdir(where):
    34             fn = os.path.join(where,name)
    35             if ('.' not in name and os.path.isdir(fn) and
    36                 os.path.isfile(os.path.join(fn,'__init__.py'))
    37             ):
    38                 out.append(prefix+name); stack.append((fn,prefix+name+'.'))
    39     for pat in list(exclude)+['ez_setup']:
    40         from fnmatch import fnmatchcase
    41         out = [item for item in out if not fnmatchcase(item,pat)]
    42     return out
    43 
    44 setup = distutils.core.setup
    45 
    46 _Command = _get_unpatched(_Command)
    47 
    48 class Command(_Command):
    49     __doc__ = _Command.__doc__
    50 
    51     command_consumes_arguments = False
    52 
    53     def __init__(self, dist, **kw):
    54         # Add support for keyword arguments
    55         _Command.__init__(self,dist)
    56         for k,v in kw.items():
    57             setattr(self,k,v)
    58 
    59     def reinitialize_command(self, command, reinit_subcommands=0, **kw):
    60         cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
    61         for k,v in kw.items():
    62             setattr(cmd,k,v)    # update command with keywords
    63         return cmd
    64 
    65 import distutils.core
    66 distutils.core.Command = Command    # we can't patch distutils.cmd, alas
    67 
    68 def findall(dir = os.curdir):
    69     """Find all files under 'dir' and return the list of full filenames
    70     (relative to 'dir').
    71     """
    72     all_files = []
    73     for base, dirs, files in os.walk(dir):
    74         if base==os.curdir or base.startswith(os.curdir+os.sep):
    75             base = base[2:]
    76         if base:
    77             files = [os.path.join(base, f) for f in files]
    78         all_files.extend(filter(os.path.isfile, files))
    79     return all_files
    80 
    81 import distutils.filelist
    82 distutils.filelist.findall = findall    # fix findall bug in distutils.
    83 
    84 
    85 # sys.dont_write_bytecode was introduced in Python 2.6.
    86 if ((hasattr(sys, "dont_write_bytecode") and sys.dont_write_bytecode) or
    87     (not hasattr(sys, "dont_write_bytecode") and os.environ.get("PYTHONDONTWRITEBYTECODE"))):
    88     _dont_write_bytecode = True
    89 else:
    90     _dont_write_bytecode = False
  • deleted file setuptools-0.6c16dev4.egg/setuptools/archive_util.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/archive_util.py b/setuptools-0.6c16dev4.egg/setuptools/archive_util.py
    deleted file mode 100644
    index cd4c3fb..0000000
    + -  
    1 """Utilities for extracting common archive formats"""
    2 
    3 
    4 __all__ = [
    5     "unpack_archive", "unpack_zipfile", "unpack_tarfile", "default_filter",
    6     "UnrecognizedFormat", "extraction_drivers", "unpack_directory",
    7 ]
    8 
    9 import zipfile, tarfile, os, shutil
    10 from pkg_resources import ensure_directory
    11 from distutils.errors import DistutilsError
    12 
    13 class UnrecognizedFormat(DistutilsError):
    14     """Couldn't recognize the archive type"""
    15 
    16 def default_filter(src,dst):
    17     """The default progress/filter callback; returns True for all files"""
    18     return dst
    19 
    20 
    21 
    22 
    23 
    24 
    25 
    26 
    27 
    28 
    29 
    30 
    31 
    32 
    33 
    34 
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    42 def unpack_archive(filename, extract_dir, progress_filter=default_filter,
    43     drivers=None
    44 ):
    45     """Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat``
    46 
    47     `progress_filter` is a function taking two arguments: a source path
    48     internal to the archive ('/'-separated), and a filesystem path where it
    49     will be extracted.  The callback must return the desired extract path
    50     (which may be the same as the one passed in), or else ``None`` to skip
    51     that file or directory.  The callback can thus be used to report on the
    52     progress of the extraction, as well as to filter the items extracted or
    53     alter their extraction paths.
    54 
    55     `drivers`, if supplied, must be a non-empty sequence of functions with the
    56     same signature as this function (minus the `drivers` argument), that raise
    57     ``UnrecognizedFormat`` if they do not support extracting the designated
    58     archive type.  The `drivers` are tried in sequence until one is found that
    59     does not raise an error, or until all are exhausted (in which case
    60     ``UnrecognizedFormat`` is raised).  If you do not supply a sequence of
    61     drivers, the module's ``extraction_drivers`` constant will be used, which
    62     means that ``unpack_zipfile`` and ``unpack_tarfile`` will be tried, in that
    63     order.
    64     """
    65     for driver in drivers or extraction_drivers:
    66         try:
    67             driver(filename, extract_dir, progress_filter)
    68         except UnrecognizedFormat:
    69             continue
    70         else:
    71             return
    72     else:
    73         raise UnrecognizedFormat(
    74             "Not a recognized archive type: %s" % filename
    75         )
    76 
    77 
    78 
    79 
    80 
    81 
    82 
    83 def unpack_directory(filename, extract_dir, progress_filter=default_filter):
    84     """"Unpack" a directory, using the same interface as for archives
    85 
    86     Raises ``UnrecognizedFormat`` if `filename` is not a directory
    87     """
    88     if not os.path.isdir(filename):
    89         raise UnrecognizedFormat("%s is not a directory" % (filename,))
    90 
    91     paths = {filename:('',extract_dir)}
    92     for base, dirs, files in os.walk(filename):
    93         src,dst = paths[base]
    94         for d in dirs:
    95             paths[os.path.join(base,d)] = src+d+'/', os.path.join(dst,d)
    96         for f in files:
    97             name = src+f
    98             target = os.path.join(dst,f)
    99             target = progress_filter(src+f, target)
    100             if not target:
    101                 continue    # skip non-files
    102             ensure_directory(target)
    103             f = os.path.join(base,f)
    104             shutil.copyfile(f, target)
    105             shutil.copystat(f, target)
    106 
    107 
    108 
    109 
    110 
    111 
    112 
    113 
    114 
    115 
    116 
    117 
    118 
    119 
    120 
    121 
    122 
    123 
    124 def unpack_zipfile(filename, extract_dir, progress_filter=default_filter):
    125     """Unpack zip `filename` to `extract_dir`
    126 
    127     Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined
    128     by ``zipfile.is_zipfile()``).  See ``unpack_archive()`` for an explanation
    129     of the `progress_filter` argument.
    130     """
    131 
    132     if not zipfile.is_zipfile(filename):
    133         raise UnrecognizedFormat("%s is not a zip file" % (filename,))
    134 
    135     z = zipfile.ZipFile(filename)
    136     try:
    137         for info in z.infolist():
    138             name = info.filename
    139 
    140             # don't extract absolute paths or ones with .. in them
    141             if name.startswith('/') or '..' in name:
    142                 continue
    143 
    144             target = os.path.join(extract_dir, *name.split('/'))
    145             target = progress_filter(name, target)
    146             if not target:
    147                 continue
    148             if name.endswith('/'):
    149                 # directory
    150                 ensure_directory(target)
    151             else:
    152                 # file
    153                 ensure_directory(target)
    154                 data = z.read(info.filename)
    155                 f = open(target,'wb')
    156                 try:
    157                     f.write(data)
    158                 finally:
    159                     f.close()
    160                     del data
    161     finally:
    162         z.close()
    163 
    164 
    165 def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
    166     """Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
    167 
    168     Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
    169     by ``tarfile.open()``).  See ``unpack_archive()`` for an explanation
    170     of the `progress_filter` argument.
    171     """
    172 
    173     try:
    174         tarobj = tarfile.open(filename)
    175     except tarfile.TarError:
    176         raise UnrecognizedFormat(
    177             "%s is not a compressed or uncompressed tar file" % (filename,)
    178         )
    179 
    180     try:
    181         tarobj.chown = lambda *args: None   # don't do any chowning!
    182         for member in tarobj:
    183             if member.isfile() or member.isdir():
    184                 name = member.name
    185                 # don't extract absolute paths or ones with .. in them
    186                 if not name.startswith('/') and '..' not in name:
    187                     dst = os.path.join(extract_dir, *name.split('/'))
    188                     dst = progress_filter(name, dst)
    189                     if dst:
    190                         if dst.endswith(os.sep):
    191                             dst = dst[:-1]
    192                         try:
    193                             tarobj._extract_member(member,dst)  # XXX Ugh
    194                         except tarfile.ExtractError:
    195                             pass    # chown/chmod/mkfifo/mknode/makedev failed
    196         return True
    197     finally:
    198         tarobj.close()
    199 
    200 
    201 
    202 
    203 extraction_drivers = unpack_directory, unpack_zipfile, unpack_tarfile
    204 
    205 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/__init__.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/__init__.py b/setuptools-0.6c16dev4.egg/setuptools/command/__init__.py
    deleted file mode 100644
    index 80969f3..0000000
    + -  
    1 __all__ = [
    2     'alias', 'bdist_egg', 'bdist_rpm', 'build_ext', 'build_py', 'develop',
    3     'easy_install', 'egg_info', 'install', 'install_lib', 'rotate', 'saveopts',
    4     'sdist', 'setopt', 'test', 'upload', 'install_egg_info', 'install_scripts',
    5     'register', 'bdist_wininst', 'scriptsetup',
    6 ]
    7 
    8 import sys
    9 if sys.version>='2.5':
    10     # In Python 2.5 and above, distutils includes its own upload command
    11     __all__.remove('upload')
    12 
    13 
    14 from distutils.command.bdist import bdist
    15 
    16 if 'egg' not in bdist.format_commands:
    17     bdist.format_command['egg'] = ('bdist_egg', "Python .egg file")
    18     bdist.format_commands.append('egg')
    19 
    20 del bdist, sys
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/alias.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/alias.py b/setuptools-0.6c16dev4.egg/setuptools/command/alias.py
    deleted file mode 100644
    index 3e69ef6..0000000
    + -  
    1 import distutils, os
    2 from setuptools import Command
    3 from distutils.util import convert_path
    4 from distutils import log
    5 from distutils.errors import *
    6 from setuptools.command.setopt import edit_config, option_base, config_file
    7 
    8 def shquote(arg):
    9     """Quote an argument for later parsing by shlex.split()"""
    10     for c in '"', "'", "\\", "#":
    11         if c in arg: return repr(arg)
    12     if arg.split()!=[arg]:
    13         return repr(arg)
    14     return arg
    15 
    16 
    17 class alias(option_base):
    18     """Define a shortcut that invokes one or more commands"""
    19 
    20     description = "define a shortcut to invoke one or more commands"
    21     command_consumes_arguments = True
    22 
    23     user_options = [
    24         ('remove',   'r', 'remove (unset) the alias'),
    25     ] + option_base.user_options
    26 
    27     boolean_options = option_base.boolean_options + ['remove']
    28 
    29     def initialize_options(self):
    30         option_base.initialize_options(self)
    31         self.args = None
    32         self.remove = None
    33 
    34     def finalize_options(self):
    35         option_base.finalize_options(self)
    36         if self.remove and len(self.args)!=1:
    37             raise DistutilsOptionError(
    38                 "Must specify exactly one argument (the alias name) when "
    39                 "using --remove"
    40             )
    41 
    42     def run(self):
    43         aliases = self.distribution.get_option_dict('aliases')
    44 
    45         if not self.args:
    46             print "Command Aliases"
    47             print "---------------"
    48             for alias in aliases:
    49                 print "setup.py alias", format_alias(alias, aliases)
    50             return
    51 
    52         elif len(self.args)==1:
    53             alias, = self.args
    54             if self.remove:
    55                 command = None
    56             elif alias in aliases:
    57                 print "setup.py alias", format_alias(alias, aliases)
    58                 return
    59             else:
    60                 print "No alias definition found for %r" % alias
    61                 return
    62         else:
    63             alias = self.args[0]
    64             command = ' '.join(map(shquote,self.args[1:]))
    65 
    66         edit_config(self.filename, {'aliases': {alias:command}}, self.dry_run)
    67 
    68 
    69 def format_alias(name, aliases):
    70     source, command = aliases[name]
    71     if source == config_file('global'):
    72         source = '--global-config '
    73     elif source == config_file('user'):
    74         source = '--user-config '
    75     elif source == config_file('local'):
    76         source = ''
    77     else:
    78         source = '--filename=%r' % source
    79     return source+name+' '+command
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/bdist_egg.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/bdist_egg.py b/setuptools-0.6c16dev4.egg/setuptools/command/bdist_egg.py
    deleted file mode 100644
    index 7e5a379..0000000
    + -  
    1 """setuptools.command.bdist_egg
    2 
    3 Build .egg distributions"""
    4 
    5 # This module should be kept compatible with Python 2.3
    6 import sys, os, marshal
    7 from setuptools import Command
    8 from distutils.dir_util import remove_tree, mkpath
    9 from distutils.sysconfig import get_python_version, get_python_lib
    10 from distutils import log
    11 from distutils.errors import DistutilsSetupError
    12 from pkg_resources import get_build_platform, Distribution, ensure_directory
    13 from pkg_resources import EntryPoint
    14 from types import CodeType
    15 from setuptools.extension import Library
    16 
    17 def strip_module(filename):
    18     if '.' in filename:
    19         filename = os.path.splitext(filename)[0]
    20     if filename.endswith('module'):
    21         filename = filename[:-6]
    22     return filename
    23 
    24 def write_stub(resource, pyfile):
    25     f = open(pyfile,'w')
    26     f.write('\n'.join([
    27         "def __bootstrap__():",
    28         "   global __bootstrap__, __loader__, __file__",
    29         "   import sys, pkg_resources, imp",
    30         "   __file__ = pkg_resources.resource_filename(__name__,%r)"
    31             % resource,
    32         "   __loader__ = None; del __bootstrap__, __loader__",
    33         "   imp.load_dynamic(__name__,__file__)",
    34         "__bootstrap__()",
    35         "" # terminal \n
    36     ]))
    37     f.close()
    38 
    39 # stub __init__.py for packages distributed without one
    40 NS_PKG_STUB = '__import__("pkg_resources").declare_namespace(__name__)'
    41 
    42 class bdist_egg(Command):
    43 
    44     description = "create an \"egg\" distribution"
    45 
    46     user_options = [
    47         ('bdist-dir=', 'b',
    48             "temporary directory for creating the distribution"),
    49         ('plat-name=', 'p',
    50                      "platform name to embed in generated filenames "
    51                      "(default: %s)" % get_build_platform()),
    52         ('exclude-source-files', None,
    53                      "remove all .py files from the generated egg"),
    54         ('keep-temp', 'k',
    55                      "keep the pseudo-installation tree around after " +
    56                      "creating the distribution archive"),
    57         ('dist-dir=', 'd',
    58                      "directory to put final built distributions in"),
    59         ('skip-build', None,
    60                      "skip rebuilding everything (for testing/debugging)"),
    61     ]
    62 
    63     boolean_options = [
    64         'keep-temp', 'skip-build', 'exclude-source-files'
    65     ]
    66 
    67 
    68 
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    80 
    81 
    82 
    83     def initialize_options (self):
    84         self.bdist_dir = None
    85         self.plat_name = None
    86         self.keep_temp = 0
    87         self.dist_dir = None
    88         self.skip_build = 0
    89         self.egg_output = None
    90         self.exclude_source_files = None
    91 
    92 
    93     def finalize_options(self):
    94         ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info")
    95         self.egg_info = ei_cmd.egg_info
    96 
    97         if self.bdist_dir is None:
    98             bdist_base = self.get_finalized_command('bdist').bdist_base
    99             self.bdist_dir = os.path.join(bdist_base, 'egg')
    100 
    101         if self.plat_name is None:
    102             self.plat_name = get_build_platform()
    103 
    104         self.set_undefined_options('bdist',('dist_dir', 'dist_dir'))
    105 
    106         if self.egg_output is None:
    107 
    108             # Compute filename of the output egg
    109             basename = Distribution(
    110                 None, None, ei_cmd.egg_name, ei_cmd.egg_version,
    111                 get_python_version(),
    112                 self.distribution.has_ext_modules() and self.plat_name
    113             ).egg_name()
    114 
    115             self.egg_output = os.path.join(self.dist_dir, basename+'.egg')
    116 
    117 
    118 
    119 
    120 
    121 
    122 
    123 
    124     def do_install_data(self):
    125         # Hack for packages that install data to install's --install-lib
    126         self.get_finalized_command('install').install_lib = self.bdist_dir
    127 
    128         site_packages = os.path.normcase(os.path.realpath(get_python_lib()))
    129         old, self.distribution.data_files = self.distribution.data_files,[]
    130 
    131         for item in old:
    132             if isinstance(item,tuple) and len(item)==2:
    133                 if os.path.isabs(item[0]):
    134                     realpath = os.path.realpath(item[0])
    135                     normalized = os.path.normcase(realpath)
    136                     if normalized==site_packages or normalized.startswith(
    137                         site_packages+os.sep
    138                     ):
    139                         item = realpath[len(site_packages)+1:], item[1]
    140                     # XXX else: raise ???
    141             self.distribution.data_files.append(item)
    142 
    143         try:
    144             log.info("installing package data to %s" % self.bdist_dir)
    145             self.call_command('install_data', force=0, root=None)
    146         finally:
    147             self.distribution.data_files = old
    148 
    149 
    150     def get_outputs(self):
    151         return [self.egg_output]
    152 
    153 
    154     def call_command(self,cmdname,**kw):
    155         """Invoke reinitialized command `cmdname` with keyword args"""
    156         for dirname in INSTALL_DIRECTORY_ATTRS:
    157             kw.setdefault(dirname,self.bdist_dir)
    158         kw.setdefault('skip_build',self.skip_build)
    159         kw.setdefault('dry_run', self.dry_run)
    160         cmd = self.reinitialize_command(cmdname, **kw)
    161         self.run_command(cmdname)
    162         return cmd
    163 
    164 
    165     def run(self):
    166         # Generate metadata first
    167         self.run_command("egg_info")
    168         # We run install_lib before install_data, because some data hacks
    169         # pull their data path from the install_lib command.
    170         log.info("installing library code to %s" % self.bdist_dir)
    171         instcmd = self.get_finalized_command('install')
    172         old_root = instcmd.root; instcmd.root = None
    173         if self.distribution.has_c_libraries() and not self.skip_build:
    174             self.run_command('build_clib')
    175         cmd = self.call_command('install_lib', warn_dir=0)
    176         instcmd.root = old_root
    177 
    178         all_outputs, ext_outputs = self.get_ext_outputs()
    179         self.stubs = []
    180         to_compile = []
    181         for (p,ext_name) in enumerate(ext_outputs):
    182             filename,ext = os.path.splitext(ext_name)
    183             pyfile = os.path.join(self.bdist_dir, strip_module(filename)+'.py')
    184             self.stubs.append(pyfile)
    185             log.info("creating stub loader for %s" % ext_name)
    186             if not self.dry_run:
    187                 write_stub(os.path.basename(ext_name), pyfile)
    188             to_compile.append(pyfile)
    189             ext_outputs[p] = ext_name.replace(os.sep,'/')
    190 
    191         to_compile.extend(self.make_init_files())
    192         if to_compile:
    193             cmd.byte_compile(to_compile)
    194         if self.distribution.data_files:
    195             self.do_install_data()
    196 
    197         # Make the EGG-INFO directory
    198         archive_root = self.bdist_dir
    199         egg_info = os.path.join(archive_root,'EGG-INFO')
    200         self.mkpath(egg_info)
    201         if self.distribution.scripts:
    202             script_dir = os.path.join(egg_info, 'scripts')
    203             log.info("installing scripts to %s" % script_dir)
    204             self.call_command('install_scripts',install_dir=script_dir,no_ep=1)
    205 
    206         self.copy_metadata_to(egg_info)
    207         native_libs = os.path.join(egg_info, "native_libs.txt")
    208         if all_outputs:
    209             log.info("writing %s" % native_libs)
    210             if not self.dry_run:
    211                 ensure_directory(native_libs)
    212                 libs_file = open(native_libs, 'wt')
    213                 libs_file.write('\n'.join(all_outputs))
    214                 libs_file.write('\n')
    215                 libs_file.close()
    216         elif os.path.isfile(native_libs):
    217             log.info("removing %s" % native_libs)
    218             if not self.dry_run:
    219                 os.unlink(native_libs)
    220 
    221         write_safety_flag(
    222             os.path.join(archive_root,'EGG-INFO'), self.zip_safe()
    223         )
    224 
    225         if os.path.exists(os.path.join(self.egg_info,'depends.txt')):
    226             log.warn(
    227                 "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n"
    228                 "Use the install_requires/extras_require setup() args instead."
    229             )
    230 
    231         if self.exclude_source_files:
    232             self.zap_pyfiles()
    233 
    234         # Make the archive
    235         make_zipfile(self.egg_output, archive_root, verbose=self.verbose,
    236                           dry_run=self.dry_run, mode=self.gen_header())
    237         if not self.keep_temp:
    238             remove_tree(self.bdist_dir, dry_run=self.dry_run)
    239 
    240         # Add to 'Distribution.dist_files' so that the "upload" command works
    241         getattr(self.distribution,'dist_files',[]).append(
    242             ('bdist_egg',get_python_version(),self.egg_output))
    243 
    244 
    245 
    246 
    247     def zap_pyfiles(self):
    248         log.info("Removing .py files from temporary directory")
    249         for base,dirs,files in walk_egg(self.bdist_dir):
    250             for name in files:
    251                 if name.endswith('.py'):
    252                     path = os.path.join(base,name)
    253                     log.debug("Deleting %s", path)
    254                     os.unlink(path)
    255 
    256     def zip_safe(self):
    257         safe = getattr(self.distribution,'zip_safe',None)
    258         if safe is not None:
    259             return safe
    260         log.warn("zip_safe flag not set; analyzing archive contents...")
    261         return analyze_egg(self.bdist_dir, self.stubs)
    262 
    263     def make_init_files(self):
    264         """Create missing package __init__ files"""
    265         init_files = []
    266         for base,dirs,files in walk_egg(self.bdist_dir):
    267             if base==self.bdist_dir:
    268                 # don't put an __init__ in the root
    269                 continue
    270             for name in files:
    271                 if name.endswith('.py'):
    272                     if '__init__.py' not in files:
    273                         pkg = base[len(self.bdist_dir)+1:].replace(os.sep,'.')
    274                         if self.distribution.has_contents_for(pkg):
    275                             log.warn("Creating missing __init__.py for %s",pkg)
    276                             filename = os.path.join(base,'__init__.py')
    277                             if not self.dry_run:
    278                                 f = open(filename,'w'); f.write(NS_PKG_STUB)
    279                                 f.close()
    280                             init_files.append(filename)
    281                     break
    282             else:
    283                 # not a package, don't traverse to subdirectories
    284                 dirs[:] = []
    285 
    286         return init_files
    287 
    288     def gen_header(self):
    289         epm = EntryPoint.parse_map(self.distribution.entry_points or '')
    290         ep = epm.get('setuptools.installation',{}).get('eggsecutable')
    291         if ep is None:
    292             return 'w'  # not an eggsecutable, do it the usual way.
    293 
    294         if not ep.attrs or ep.extras:
    295             raise DistutilsSetupError(
    296                 "eggsecutable entry point (%r) cannot have 'extras' "
    297                 "or refer to a module" % (ep,)
    298             )
    299 
    300         pyver = sys.version[:3]
    301         pkg = ep.module_name
    302         full = '.'.join(ep.attrs)
    303         base = ep.attrs[0]
    304         basename = os.path.basename(self.egg_output)
    305 
    306         header = (
    307             "#!/bin/sh\n"
    308             'if [ `basename $0` = "%(basename)s" ]\n'
    309             'then exec python%(pyver)s -c "'
    310             "import sys, os; sys.path.insert(0, os.path.abspath('$0')); "
    311             "from %(pkg)s import %(base)s; sys.exit(%(full)s())"
    312             '" "$@"\n'
    313             'else\n'
    314             '  echo $0 is not the correct name for this egg file.\n'
    315             '  echo Please rename it back to %(basename)s and try again.\n'
    316             '  exec false\n'
    317             'fi\n'
    318 
    319         ) % locals()
    320 
    321         if not self.dry_run:
    322             mkpath(os.path.dirname(self.egg_output), dry_run=self.dry_run)
    323             f = open(self.egg_output, 'w')
    324             f.write(header)
    325             f.close()
    326         return 'a'
    327 
    328 
    329     def copy_metadata_to(self, target_dir):
    330         prefix = os.path.join(self.egg_info,'')
    331         for path in self.ei_cmd.filelist.files:
    332             if path.startswith(prefix):
    333                 target = os.path.join(target_dir, path[len(prefix):])
    334                 ensure_directory(target)
    335                 self.copy_file(path, target)
    336 
    337     def get_ext_outputs(self):
    338         """Get a list of relative paths to C extensions in the output distro"""
    339 
    340         all_outputs = []
    341         ext_outputs = []
    342 
    343         paths = {self.bdist_dir:''}
    344         for base, dirs, files in os.walk(self.bdist_dir):
    345             for filename in files:
    346                 if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS:
    347                     all_outputs.append(paths[base]+filename)
    348             for filename in dirs:
    349                 paths[os.path.join(base,filename)] = paths[base]+filename+'/'
    350 
    351         if self.distribution.has_ext_modules():
    352             build_cmd = self.get_finalized_command('build_ext')
    353             for ext in build_cmd.extensions:
    354                 if isinstance(ext,Library):
    355                     continue
    356                 fullname = build_cmd.get_ext_fullname(ext.name)
    357                 filename = build_cmd.get_ext_filename(fullname)
    358                 if not os.path.basename(filename).startswith('dl-'):
    359                     if os.path.exists(os.path.join(self.bdist_dir,filename)):
    360                         ext_outputs.append(filename)
    361 
    362         return all_outputs, ext_outputs
    363 
    364 
    365 NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split())
    366 
    367 
    368 
    369 
    370 def walk_egg(egg_dir):
    371     """Walk an unpacked egg's contents, skipping the metadata directory"""
    372     walker = os.walk(egg_dir)
    373     base,dirs,files = walker.next()
    374     if 'EGG-INFO' in dirs:
    375         dirs.remove('EGG-INFO')
    376     yield base,dirs,files
    377     for bdf in walker:
    378         yield bdf
    379 
    380 def analyze_egg(egg_dir, stubs):
    381     # check for existing flag in EGG-INFO
    382     for flag,fn in safety_flags.items():
    383         if os.path.exists(os.path.join(egg_dir,'EGG-INFO',fn)):
    384             return flag
    385     if not can_scan(): return False
    386     safe = True
    387     for base, dirs, files in walk_egg(egg_dir):
    388         for name in files:
    389             if name.endswith('.py') or name.endswith('.pyw'):
    390                 continue
    391             elif name.endswith('.pyc') or name.endswith('.pyo'):
    392                 # always scan, even if we already know we're not safe
    393                 safe = scan_module(egg_dir, base, name, stubs) and safe
    394     return safe
    395 
    396 def write_safety_flag(egg_dir, safe):
    397     # Write or remove zip safety flag file(s)
    398     for flag,fn in safety_flags.items():
    399         fn = os.path.join(egg_dir, fn)
    400         if os.path.exists(fn):
    401             if safe is None or bool(safe)!=flag:
    402                 os.unlink(fn)
    403         elif safe is not None and bool(safe)==flag:
    404             f=open(fn,'wb'); f.write('\n'); f.close()
    405 
    406 safety_flags = {
    407     True: 'zip-safe',
    408     False: 'not-zip-safe',
    409 }
    410 
    411 def scan_module(egg_dir, base, name, stubs):
    412     """Check whether module possibly uses unsafe-for-zipfile stuff"""
    413 
    414     filename = os.path.join(base,name)
    415     if filename[:-1] in stubs:
    416         return True     # Extension module
    417     pkg = base[len(egg_dir)+1:].replace(os.sep,'.')
    418     module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0]
    419     f = open(filename,'rb'); f.read(8)   # skip magic & date
    420     code = marshal.load(f);  f.close()
    421     safe = True
    422     symbols = dict.fromkeys(iter_symbols(code))
    423     for bad in ['__file__', '__path__']:
    424         if bad in symbols:
    425             log.warn("%s: module references %s", module, bad)
    426             safe = False
    427     if 'inspect' in symbols:
    428         for bad in [
    429             'getsource', 'getabsfile', 'getsourcefile', 'getfile'
    430             'getsourcelines', 'findsource', 'getcomments', 'getframeinfo',
    431             'getinnerframes', 'getouterframes', 'stack', 'trace'
    432         ]:
    433             if bad in symbols:
    434                 log.warn("%s: module MAY be using inspect.%s", module, bad)
    435                 safe = False
    436     if '__name__' in symbols and '__main__' in symbols and '.' not in module:
    437         if sys.version[:3]=="2.4":  # -m works w/zipfiles in 2.5
    438             log.warn("%s: top-level module may be 'python -m' script", module)
    439             safe = False
    440     return safe
    441 
    442 def iter_symbols(code):
    443     """Yield names and strings used by `code` and its nested code objects"""
    444     for name in code.co_names: yield name
    445     for const in code.co_consts:
    446         if isinstance(const,basestring):
    447             yield const
    448         elif isinstance(const,CodeType):
    449             for name in iter_symbols(const):
    450                 yield name
    451 
    452 def can_scan():
    453     if not sys.platform.startswith('java') and sys.platform != 'cli':
    454         # CPython, PyPy, etc.
    455         return True
    456     log.warn("Unable to analyze compiled code on this platform.")
    457     log.warn("Please ask the author to include a 'zip_safe'"
    458              " setting (either True or False) in the package's setup.py")
    459 
    460 
    461 
    462 
    463 
    464 
    465 
    466 
    467 
    468 
    469 
    470 
    471 
    472 
    473 
    474 
    475 
    476 
    477 
    478 
    479 
    480 
    481 
    482 
    483 
    484 
    485 
    486 
    487 
    488 
    489 
    490 
    491 
    492 
    493 # Attribute names of options for commands that might need to be convinced to
    494 # install to the egg build directory
    495 
    496 INSTALL_DIRECTORY_ATTRS = [
    497     'install_lib', 'install_dir', 'install_data', 'install_base'
    498 ]
    499 
    500 def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=None,
    501     mode='w'
    502 ):
    503     """Create a zip file from all the files under 'base_dir'.  The output
    504     zip file will be named 'base_dir' + ".zip".  Uses either the "zipfile"
    505     Python module (if available) or the InfoZIP "zip" utility (if installed
    506     and found on the default search path).  If neither tool is available,
    507     raises DistutilsExecError.  Returns the name of the output zip file.
    508     """
    509     import zipfile
    510     mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
    511     log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir)
    512 
    513     def visit(z, dirname, names):
    514         for name in names:
    515             path = os.path.normpath(os.path.join(dirname, name))
    516             if os.path.isfile(path):
    517                 p = path[len(base_dir)+1:]
    518                 if not dry_run:
    519                     z.write(path, p)
    520                 log.debug("adding '%s'" % p)
    521 
    522     if compress is None:
    523         compress = (sys.version>="2.4") # avoid 2.3 zipimport bug when 64 bits
    524 
    525     compression = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED][bool(compress)]
    526     if not dry_run:
    527         z = zipfile.ZipFile(zip_filename, mode, compression=compression)
    528         os.path.walk(base_dir, visit, z)
    529         z.close()
    530     else:
    531         os.path.walk(base_dir, visit, None)
    532     return zip_filename
    533 #
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/bdist_rpm.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/bdist_rpm.py b/setuptools-0.6c16dev4.egg/setuptools/command/bdist_rpm.py
    deleted file mode 100644
    index 8c48da3..0000000
    + -  
    1 # This is just a kludge so that bdist_rpm doesn't guess wrong about the
    2 # distribution name and version, if the egg_info command is going to alter
    3 # them, another kludge to allow you to build old-style non-egg RPMs, and
    4 # finally, a kludge to track .rpm files for uploading when run on Python <2.5.
    5 
    6 from distutils.command.bdist_rpm import bdist_rpm as _bdist_rpm
    7 import sys, os
    8 
    9 class bdist_rpm(_bdist_rpm):
    10 
    11     def initialize_options(self):
    12         _bdist_rpm.initialize_options(self)
    13         self.no_egg = None
    14 
    15     if sys.version<"2.5":
    16         # Track for uploading any .rpm file(s) moved to self.dist_dir
    17         def move_file(self, src, dst, level=1):
    18             _bdist_rpm.move_file(self, src, dst, level)
    19             if dst==self.dist_dir and src.endswith('.rpm'):
    20                 getattr(self.distribution,'dist_files',[]).append(
    21                     ('bdist_rpm',
    22                     src.endswith('.src.rpm') and 'any' or sys.version[:3],
    23                      os.path.join(dst, os.path.basename(src)))
    24                 )
    25 
    26     def run(self):
    27         self.run_command('egg_info')    # ensure distro name is up-to-date
    28         _bdist_rpm.run(self)
    29 
    30 
    31 
    32 
    33 
    34 
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    42     def _make_spec_file(self):
    43         version = self.distribution.get_version()
    44         rpmversion = version.replace('-','_')
    45         spec = _bdist_rpm._make_spec_file(self)
    46         line23 = '%define version '+version
    47         line24 = '%define version '+rpmversion
    48         spec  = [
    49             line.replace(
    50                 "Source0: %{name}-%{version}.tar",
    51                 "Source0: %{name}-%{unmangled_version}.tar"
    52             ).replace(
    53                 "setup.py install ",
    54                 "setup.py install --single-version-externally-managed "
    55             ).replace(
    56                 "%setup",
    57                 "%setup -n %{name}-%{unmangled_version}"
    58             ).replace(line23,line24)
    59             for line in spec
    60         ]
    61         spec.insert(spec.index(line24)+1, "%define unmangled_version "+version)
    62         return spec
    63 
    64 
    65 
    66 
    67 
    68 
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    80 
    81 
    82 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/bdist_wininst.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/bdist_wininst.py b/setuptools-0.6c16dev4.egg/setuptools/command/bdist_wininst.py
    deleted file mode 100644
    index e8521f8..0000000
    + -  
    1 from distutils.command.bdist_wininst import bdist_wininst as _bdist_wininst
    2 import os, sys
    3 
    4 class bdist_wininst(_bdist_wininst):
    5     _good_upload = _bad_upload = None
    6 
    7     def create_exe(self, arcname, fullname, bitmap=None):
    8         _bdist_wininst.create_exe(self, arcname, fullname, bitmap)
    9         installer_name = self.get_installer_filename(fullname)
    10         if self.target_version:
    11             pyversion = self.target_version
    12             # fix 2.5+ bdist_wininst ignoring --target-version spec
    13             self._bad_upload = ('bdist_wininst', 'any', installer_name)
    14         else:
    15             pyversion = 'any'
    16         self._good_upload = ('bdist_wininst', pyversion, installer_name)
    17        
    18     def _fix_upload_names(self):
    19         good, bad = self._good_upload, self._bad_upload
    20         dist_files = getattr(self.distribution, 'dist_files', [])
    21         if bad in dist_files:
    22             dist_files.remove(bad)
    23         if good not in dist_files:
    24             dist_files.append(good)
    25 
    26     def reinitialize_command (self, command, reinit_subcommands=0):
    27         cmd = self.distribution.reinitialize_command(
    28             command, reinit_subcommands)
    29         if command in ('install', 'install_lib'):
    30             cmd.install_lib = None  # work around distutils bug
    31         return cmd
    32 
    33     def run(self):
    34         self._is_running = True
    35         try:
    36             _bdist_wininst.run(self)
    37             self._fix_upload_names()
    38         finally:
    39             self._is_running = False
    40 
    41 
    42     if not hasattr(_bdist_wininst, 'get_installer_filename'):
    43         def get_installer_filename(self, fullname):
    44             # Factored out to allow overriding in subclasses
    45             if self.target_version:
    46                 # if we create an installer for a specific python version,
    47                 # it's better to include this in the name
    48                 installer_name = os.path.join(self.dist_dir,
    49                                               "%s.win32-py%s.exe" %
    50                                                (fullname, self.target_version))
    51             else:
    52                 installer_name = os.path.join(self.dist_dir,
    53                                               "%s.win32.exe" % fullname)
    54             return installer_name
    55     # get_installer_filename()
    56    
    57 
    58 
    59 
    60 
    61 
    62 
    63 
    64 
    65 
    66 
    67 
    68 
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    80 
    81 
    82 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/build_ext.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/build_ext.py b/setuptools-0.6c16dev4.egg/setuptools/command/build_ext.py
    deleted file mode 100644
    index e0d5284..0000000
    + -  
    1 from distutils.command.build_ext import build_ext as _du_build_ext
    2 try:
    3     # Attempt to use Pyrex for building extensions, if available
    4     from Pyrex.Distutils.build_ext import build_ext as _build_ext
    5 except ImportError:
    6     _build_ext = _du_build_ext
    7 
    8 import os, sys
    9 from distutils.file_util import copy_file
    10 from setuptools.extension import Library
    11 from distutils.ccompiler import new_compiler
    12 from distutils.sysconfig import customize_compiler, get_config_var
    13 get_config_var("LDSHARED")  # make sure _config_vars is initialized
    14 from distutils.sysconfig import _config_vars
    15 from distutils import log
    16 from distutils.errors import *
    17 
    18 have_rtld = False
    19 use_stubs = False
    20 libtype = 'shared'
    21 
    22 if sys.platform == "darwin":
    23     use_stubs = True
    24 elif os.name != 'nt':
    25     try:
    26         from dl import RTLD_NOW
    27         have_rtld = True
    28         use_stubs = True
    29     except ImportError:
    30         pass
    31 
    32 def if_dl(s):
    33     if have_rtld:
    34         return s
    35     return ''
    36 
    37 
    38 
    39 
    40 
    41 
    42 class build_ext(_build_ext):
    43     def run(self):
    44         """Build extensions in build directory, then copy if --inplace"""
    45         old_inplace, self.inplace = self.inplace, 0
    46         _build_ext.run(self)
    47         self.inplace = old_inplace
    48         if old_inplace:
    49             self.copy_extensions_to_source()
    50 
    51     def copy_extensions_to_source(self):
    52         build_py = self.get_finalized_command('build_py')
    53         for ext in self.extensions:
    54             fullname = self.get_ext_fullname(ext.name)
    55             filename = self.get_ext_filename(fullname)
    56             modpath = fullname.split('.')
    57             package = '.'.join(modpath[:-1])
    58             package_dir = build_py.get_package_dir(package)
    59             dest_filename = os.path.join(package_dir,os.path.basename(filename))
    60             src_filename = os.path.join(self.build_lib,filename)
    61 
    62             # Always copy, even if source is older than destination, to ensure
    63             # that the right extensions for the current Python/platform are
    64             # used.
    65             copy_file(
    66                 src_filename, dest_filename, verbose=self.verbose,
    67                 dry_run=self.dry_run
    68             )
    69             if ext._needs_stub:
    70                 self.write_stub(package_dir or os.curdir, ext, True)
    71 
    72 
    73     if _build_ext is not _du_build_ext and not hasattr(_build_ext,'pyrex_sources'):
    74         # Workaround for problems using some Pyrex versions w/SWIG and/or 2.4
    75         def swig_sources(self, sources, *otherargs):
    76             # first do any Pyrex processing
    77             sources = _build_ext.swig_sources(self, sources) or sources
    78             # Then do any actual SWIG stuff on the remainder
    79             return _du_build_ext.swig_sources(self, sources, *otherargs)
    80 
    81 
    82 
    83     def get_ext_filename(self, fullname):
    84         filename = _build_ext.get_ext_filename(self,fullname)
    85         if fullname in self.ext_map:
    86             ext = self.ext_map[fullname]
    87             if isinstance(ext,Library):
    88                 fn, ext = os.path.splitext(filename)
    89                 return self.shlib_compiler.library_filename(fn,libtype)
    90             elif use_stubs and ext._links_to_dynamic:
    91                 d,fn = os.path.split(filename)
    92                 return os.path.join(d,'dl-'+fn)
    93         return filename
    94 
    95     def initialize_options(self):
    96         _build_ext.initialize_options(self)
    97         self.shlib_compiler = None
    98         self.shlibs = []
    99         self.ext_map = {}
    100 
    101     def finalize_options(self):
    102         _build_ext.finalize_options(self)
    103         self.extensions = self.extensions or []
    104         self.check_extensions_list(self.extensions)
    105         self.shlibs = [ext for ext in self.extensions
    106                         if isinstance(ext,Library)]
    107         if self.shlibs:
    108             self.setup_shlib_compiler()
    109         for ext in self.extensions:
    110             ext._full_name = self.get_ext_fullname(ext.name)
    111         for ext in self.extensions:
    112             fullname = ext._full_name
    113             self.ext_map[fullname] = ext
    114             ltd = ext._links_to_dynamic = \
    115                 self.shlibs and self.links_to_dynamic(ext) or False
    116             ext._needs_stub = ltd and use_stubs and not isinstance(ext,Library)
    117             filename = ext._file_name = self.get_ext_filename(fullname)
    118             libdir = os.path.dirname(os.path.join(self.build_lib,filename))
    119             if ltd and libdir not in ext.library_dirs:
    120                 ext.library_dirs.append(libdir)
    121             if ltd and use_stubs and os.curdir not in ext.runtime_library_dirs:
    122                 ext.runtime_library_dirs.append(os.curdir)
    123 
    124     def setup_shlib_compiler(self):
    125         compiler = self.shlib_compiler = new_compiler(
    126             compiler=self.compiler, dry_run=self.dry_run, force=self.force
    127         )
    128         if sys.platform == "darwin":
    129             tmp = _config_vars.copy()
    130             try:
    131                 # XXX Help!  I don't have any idea whether these are right...
    132                 _config_vars['LDSHARED'] = "gcc -Wl,-x -dynamiclib -undefined dynamic_lookup"
    133                 _config_vars['CCSHARED'] = " -dynamiclib"
    134                 _config_vars['SO'] = ".dylib"
    135                 customize_compiler(compiler)
    136             finally:
    137                 _config_vars.clear()
    138                 _config_vars.update(tmp)
    139         else:
    140             customize_compiler(compiler)
    141 
    142         if self.include_dirs is not None:
    143             compiler.set_include_dirs(self.include_dirs)
    144         if self.define is not None:
    145             # 'define' option is a list of (name,value) tuples
    146             for (name,value) in self.define:
    147                 compiler.define_macro(name, value)
    148         if self.undef is not None:
    149             for macro in self.undef:
    150                 compiler.undefine_macro(macro)
    151         if self.libraries is not None:
    152             compiler.set_libraries(self.libraries)
    153         if self.library_dirs is not None:
    154             compiler.set_library_dirs(self.library_dirs)
    155         if self.rpath is not None:
    156             compiler.set_runtime_library_dirs(self.rpath)
    157         if self.link_objects is not None:
    158             compiler.set_link_objects(self.link_objects)
    159 
    160         # hack so distutils' build_extension() builds a library instead
    161         compiler.link_shared_object = link_shared_object.__get__(compiler)
    162 
    163 
    164 
    165     def get_export_symbols(self, ext):
    166         if isinstance(ext,Library):
    167             return ext.export_symbols
    168         return _build_ext.get_export_symbols(self,ext)
    169 
    170     def build_extension(self, ext):
    171         _compiler = self.compiler
    172         try:
    173             if isinstance(ext,Library):
    174                 self.compiler = self.shlib_compiler
    175             _build_ext.build_extension(self,ext)
    176             if ext._needs_stub:
    177                 self.write_stub(
    178                     self.get_finalized_command('build_py').build_lib, ext
    179                 )
    180         finally:
    181             self.compiler = _compiler
    182 
    183     def links_to_dynamic(self, ext):
    184         """Return true if 'ext' links to a dynamic lib in the same package"""
    185         # XXX this should check to ensure the lib is actually being built
    186         # XXX as dynamic, and not just using a locally-found version or a
    187         # XXX static-compiled version
    188         libnames = dict.fromkeys([lib._full_name for lib in self.shlibs])
    189         pkg = '.'.join(ext._full_name.split('.')[:-1]+[''])
    190         for libname in ext.libraries:
    191             if pkg+libname in libnames: return True
    192         return False
    193 
    194     def get_outputs(self):
    195         outputs = _build_ext.get_outputs(self)
    196         optimize = self.get_finalized_command('build_py').optimize
    197         for ext in self.extensions:
    198             if ext._needs_stub:
    199                 base = os.path.join(self.build_lib, *ext._full_name.split('.'))
    200                 outputs.append(base+'.py')
    201                 outputs.append(base+'.pyc')
    202                 if optimize:
    203                     outputs.append(base+'.pyo')
    204         return outputs
    205 
    206     def write_stub(self, output_dir, ext, compile=False):
    207         log.info("writing stub loader for %s to %s",ext._full_name, output_dir)
    208         stub_file = os.path.join(output_dir, *ext._full_name.split('.'))+'.py'
    209         if compile and os.path.exists(stub_file):
    210             raise DistutilsError(stub_file+" already exists! Please delete.")
    211         if not self.dry_run:
    212             f = open(stub_file,'w')
    213             f.write('\n'.join([
    214                 "def __bootstrap__():",
    215                 "   global __bootstrap__, __file__, __loader__",
    216                 "   import sys, os, pkg_resources, imp"+if_dl(", dl"),
    217                 "   __file__ = pkg_resources.resource_filename(__name__,%r)"
    218                    % os.path.basename(ext._file_name),
    219                 "   del __bootstrap__",
    220                 "   if '__loader__' in globals():",
    221                 "       del __loader__",
    222                 if_dl("   old_flags = sys.getdlopenflags()"),
    223                 "   old_dir = os.getcwd()",
    224                 "   try:",
    225                 "     os.chdir(os.path.dirname(__file__))",
    226                 if_dl("     sys.setdlopenflags(dl.RTLD_NOW)"),
    227                 "     imp.load_dynamic(__name__,__file__)",
    228                 "   finally:",
    229                 if_dl("     sys.setdlopenflags(old_flags)"),
    230                 "     os.chdir(old_dir)",
    231                 "__bootstrap__()",
    232                 "" # terminal \n
    233             ]))
    234             f.close()
    235         if compile:
    236             from distutils.util import byte_compile
    237             byte_compile([stub_file], optimize=0,
    238                          force=True, dry_run=self.dry_run)
    239             optimize = self.get_finalized_command('install_lib').optimize
    240             if optimize > 0:
    241                 byte_compile([stub_file], optimize=optimize,
    242                              force=True, dry_run=self.dry_run)
    243             if os.path.exists(stub_file) and not self.dry_run:
    244                 os.unlink(stub_file)
    245 
    246 
    247 if use_stubs or os.name=='nt':
    248     # Build shared libraries
    249     #
    250     def link_shared_object(self, objects, output_libname, output_dir=None,
    251         libraries=None, library_dirs=None, runtime_library_dirs=None,
    252         export_symbols=None, debug=0, extra_preargs=None,
    253         extra_postargs=None, build_temp=None, target_lang=None
    254     ):  self.link(
    255             self.SHARED_LIBRARY, objects, output_libname,
    256             output_dir, libraries, library_dirs, runtime_library_dirs,
    257             export_symbols, debug, extra_preargs, extra_postargs,
    258             build_temp, target_lang
    259         )
    260 else:
    261     # Build static libraries everywhere else
    262     libtype = 'static'
    263 
    264     def link_shared_object(self, objects, output_libname, output_dir=None,
    265         libraries=None, library_dirs=None, runtime_library_dirs=None,
    266         export_symbols=None, debug=0, extra_preargs=None,
    267         extra_postargs=None, build_temp=None, target_lang=None
    268     ):
    269         # XXX we need to either disallow these attrs on Library instances,
    270         #     or warn/abort here if set, or something...
    271         #libraries=None, library_dirs=None, runtime_library_dirs=None,
    272         #export_symbols=None, extra_preargs=None, extra_postargs=None,
    273         #build_temp=None
    274 
    275         assert output_dir is None   # distutils build_ext doesn't pass this
    276         output_dir,filename = os.path.split(output_libname)
    277         basename, ext = os.path.splitext(filename)
    278         if self.library_filename("x").startswith('lib'):
    279             # strip 'lib' prefix; this is kludgy if some platform uses
    280             # a different prefix
    281             basename = basename[3:]
    282 
    283         self.create_static_lib(
    284             objects, basename, output_dir, debug, target_lang
    285         )
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/build_py.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/build_py.py b/setuptools-0.6c16dev4.egg/setuptools/command/build_py.py
    deleted file mode 100644
    index c5e3d7f..0000000
    + -  
    1 import os.path, sys, fnmatch
    2 from distutils.command.build_py import build_py as _build_py
    3 from distutils.util import convert_path
    4 from glob import glob
    5 
    6 class build_py(_build_py):
    7     """Enhanced 'build_py' command that includes data files with packages
    8 
    9     The data files are specified via a 'package_data' argument to 'setup()'.
    10     See 'setuptools.dist.Distribution' for more details.
    11 
    12     Also, this version of the 'build_py' command allows you to specify both
    13     'py_modules' and 'packages' in the same setup operation.
    14     """
    15     def finalize_options(self):
    16         _build_py.finalize_options(self)
    17         self.package_data = self.distribution.package_data
    18         self.exclude_package_data = self.distribution.exclude_package_data or {}
    19         if 'data_files' in self.__dict__: del self.__dict__['data_files']
    20 
    21     def run(self):
    22         self.old_run()
    23         if sys.platform == "win32":
    24             from setuptools.command.scriptsetup import do_scriptsetup
    25             do_scriptsetup()
    26 
    27     def old_run(self):
    28         """Build modules, packages, and copy data files to build directory"""
    29         if not self.py_modules and not self.packages:
    30             return
    31 
    32         if self.py_modules:
    33             self.build_modules()
    34 
    35         if self.packages:
    36             self.build_packages()
    37             self.build_package_data()
    38 
    39         # Only compile actual .py files, using our base class' idea of what our
    40         # output files are.
    41         self.byte_compile(_build_py.get_outputs(self, include_bytecode=0))
    42 
    43     def __getattr__(self,attr):
    44         if attr=='data_files':  # lazily compute data files
    45             self.data_files = files = self._get_data_files(); return files
    46         return _build_py.__getattr__(self,attr)
    47 
    48     def _get_data_files(self):
    49         """Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
    50         self.analyze_manifest()
    51         data = []
    52         for package in self.packages or ():
    53             # Locate package source directory
    54             src_dir = self.get_package_dir(package)
    55 
    56             # Compute package build directory
    57             build_dir = os.path.join(*([self.build_lib] + package.split('.')))
    58 
    59             # Length of path to strip from found files
    60             plen = len(src_dir)+1
    61 
    62             # Strip directory from globbed filenames
    63             filenames = [
    64                 file[plen:] for file in self.find_data_files(package, src_dir)
    65                 ]
    66             data.append( (package, src_dir, build_dir, filenames) )
    67         return data
    68 
    69     def find_data_files(self, package, src_dir):
    70         """Return filenames for package's data files in 'src_dir'"""
    71         globs = (self.package_data.get('', [])
    72                  + self.package_data.get(package, []))
    73         files = self.manifest_files.get(package, [])[:]
    74         for pattern in globs:
    75             # Each pattern has to be converted to a platform-specific path
    76             files.extend(glob(os.path.join(src_dir, convert_path(pattern))))
    77         return self.exclude_data_files(package, src_dir, files)
    78 
    79     def build_package_data(self):
    80         """Copy data files into build directory"""
    81         lastdir = None
    82         for package, src_dir, build_dir, filenames in self.data_files:
    83             for filename in filenames:
    84                 target = os.path.join(build_dir, filename)
    85                 self.mkpath(os.path.dirname(target))
    86                 self.copy_file(os.path.join(src_dir, filename), target)
    87 
    88 
    89     def analyze_manifest(self):
    90         self.manifest_files = mf = {}
    91         if not self.distribution.include_package_data:
    92             return
    93         src_dirs = {}
    94         for package in self.packages or ():
    95             # Locate package source directory
    96             src_dirs[assert_relative(self.get_package_dir(package))] = package
    97 
    98         self.run_command('egg_info')
    99         ei_cmd = self.get_finalized_command('egg_info')
    100         for path in ei_cmd.filelist.files:
    101             d,f = os.path.split(assert_relative(path))
    102             prev = None
    103             oldf = f
    104             while d and d!=prev and d not in src_dirs:
    105                 prev = d
    106                 d, df = os.path.split(d)
    107                 f = os.path.join(df, f)
    108             if d in src_dirs:
    109                 if path.endswith('.py') and f==oldf:
    110                     continue    # it's a module, not data
    111                 mf.setdefault(src_dirs[d],[]).append(path)
    112 
    113     def get_data_files(self): pass  # kludge 2.4 for lazy computation
    114 
    115     if sys.version<"2.4":    # Python 2.4 already has this code
    116         def get_outputs(self, include_bytecode=1):
    117             """Return complete list of files copied to the build directory
    118 
    119             This includes both '.py' files and data files, as well as '.pyc'
    120             and '.pyo' files if 'include_bytecode' is true.  (This method is
    121             needed for the 'install_lib' command to do its job properly, and to
    122             generate a correct installation manifest.)
    123             """
    124             return _build_py.get_outputs(self, include_bytecode) + [
    125                 os.path.join(build_dir, filename)
    126                 for package, src_dir, build_dir,filenames in self.data_files
    127                 for filename in filenames
    128                 ]
    129 
    130     def check_package(self, package, package_dir):
    131         """Check namespace packages' __init__ for declare_namespace"""
    132         try:
    133             return self.packages_checked[package]
    134         except KeyError:
    135             pass
    136 
    137         init_py = _build_py.check_package(self, package, package_dir)
    138         self.packages_checked[package] = init_py
    139 
    140         if not init_py or not self.distribution.namespace_packages:
    141             return init_py
    142 
    143         for pkg in self.distribution.namespace_packages:
    144             if pkg==package or pkg.startswith(package+'.'):
    145                 break
    146         else:
    147             return init_py
    148 
    149         f = open(init_py,'rU')
    150         if 'declare_namespace' not in f.read():
    151             from distutils.errors import DistutilsError
    152             raise DistutilsError(
    153               "Namespace package problem: %s is a namespace package, but its\n"
    154               "__init__.py does not call declare_namespace()! Please fix it.\n"
    155               '(See the setuptools manual under "Namespace Packages" for '
    156               "details.)\n" % (package,)
    157             )
    158         f.close()
    159         return init_py
    160 
    161     def initialize_options(self):
    162         self.packages_checked={}
    163         _build_py.initialize_options(self)
    164 
    165 
    166 
    167 
    168 
    169 
    170 
    171     def exclude_data_files(self, package, src_dir, files):
    172         """Filter filenames for package's data files in 'src_dir'"""
    173         globs = (self.exclude_package_data.get('', [])
    174                  + self.exclude_package_data.get(package, []))
    175         bad = []
    176         for pattern in globs:
    177             bad.extend(
    178                 fnmatch.filter(
    179                     files, os.path.join(src_dir, convert_path(pattern))
    180                 )
    181             )
    182         bad = dict.fromkeys(bad)
    183         seen = {}
    184         return [
    185             f for f in files if f not in bad
    186                 and f not in seen and seen.setdefault(f,1)  # ditch dupes
    187         ]
    188 
    189 
    190 def assert_relative(path):
    191     if not os.path.isabs(path):
    192         return path
    193     from distutils.errors import DistutilsSetupError
    194     raise DistutilsSetupError(
    195 """Error: setup script specifies an absolute path:
    196 
    197     %s
    198 
    199 setup() arguments must *always* be /-separated paths relative to the
    200 setup.py directory, *never* absolute paths.
    201 """ % path
    202     )
    203 
    204 
    205 
    206 
    207 
    208 
    209 
    210 
    211 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/develop.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/develop.py b/setuptools-0.6c16dev4.egg/setuptools/command/develop.py
    deleted file mode 100644
    index 303f488..0000000
    + -  
    1 from setuptools.command.easy_install import easy_install
    2 from distutils.util import convert_path
    3 from pkg_resources import Distribution, PathMetadata, normalize_path
    4 from distutils import log
    5 from distutils.errors import *
    6 import sys, os, setuptools, glob
    7 
    8 class develop(easy_install):
    9     """Set up package for development"""
    10 
    11     description = "install package in 'development mode'"
    12 
    13     user_options = easy_install.user_options + [
    14         ("uninstall", "u", "Uninstall this source package"),
    15         ("egg-path=", None, "Set the path to be used in the .egg-link file"),
    16     ]
    17 
    18     boolean_options = easy_install.boolean_options + ['uninstall']
    19 
    20     command_consumes_arguments = False  # override base
    21 
    22     def run(self):
    23         self.old_run()
    24         if sys.platform == "win32":
    25             from setuptools.command.scriptsetup import do_scriptsetup
    26             do_scriptsetup()
    27 
    28     def old_run(self):
    29         if self.uninstall:
    30             self.multi_version = True
    31             self.uninstall_link()
    32         else:
    33             self.install_for_development()
    34         self.warn_deprecated_options()
    35 
    36     def initialize_options(self):
    37         self.uninstall = None
    38         self.egg_path = None
    39         easy_install.initialize_options(self)
    40         self.setup_path = None
    41         self.always_copy_from = '.'   # always copy eggs installed in curdir
    42 
    43     def finalize_options(self):
    44         ei = self.get_finalized_command("egg_info")
    45         if ei.broken_egg_info:
    46             raise DistutilsError(
    47             "Please rename %r to %r before using 'develop'"
    48             % (ei.egg_info, ei.broken_egg_info)
    49             )
    50         self.args = [ei.egg_name]
    51         easy_install.finalize_options(self)
    52         # pick up setup-dir .egg files only: no .egg-info
    53         self.package_index.scan(glob.glob('*.egg'))
    54 
    55         self.egg_link = os.path.join(self.install_dir, ei.egg_name+'.egg-link')
    56         self.egg_base = ei.egg_base
    57         if self.egg_path is None:
    58             self.egg_path = os.path.abspath(ei.egg_base)
    59 
    60         target = normalize_path(self.egg_base)
    61         if normalize_path(os.path.join(self.install_dir, self.egg_path)) != target:
    62             raise DistutilsOptionError(
    63                 "--egg-path must be a relative path from the install"
    64                 " directory to "+target
    65         )
    66        
    67         # Make a distribution for the package's source
    68         self.dist = Distribution(
    69             target,
    70             PathMetadata(target, os.path.abspath(ei.egg_info)),
    71             project_name = ei.egg_name
    72         )
    73 
    74         p = self.egg_base.replace(os.sep,'/')
    75         if p!= os.curdir:
    76             p = '../' * (p.count('/')+1)
    77         self.setup_path = p
    78         p = normalize_path(os.path.join(self.install_dir, self.egg_path, p))
    79         if  p != normalize_path(os.curdir):
    80             raise DistutilsOptionError(
    81                 "Can't get a consistent path to setup script from"
    82                 " installation directory", p, normalize_path(os.curdir))
    83 
    84     def install_for_development(self):
    85         # Ensure metadata is up-to-date
    86         self.run_command('egg_info')
    87         # Build extensions in-place
    88         self.reinitialize_command('build_ext', inplace=1)
    89         self.run_command('build_ext')
    90         self.install_site_py()  # ensure that target dir is site-safe
    91         if setuptools.bootstrap_install_from:
    92             self.easy_install(setuptools.bootstrap_install_from)
    93             setuptools.bootstrap_install_from = None
    94 
    95         # create an .egg-link in the installation dir, pointing to our egg
    96         log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
    97         if not self.dry_run:
    98             f = open(self.egg_link,"w")
    99             f.write(self.egg_path + "\n" + self.setup_path)
    100             f.close()
    101         # postprocess the installed distro, fixing up .pth, installing scripts,
    102         # and handling requirements
    103         self.process_distribution(None, self.dist, not self.no_deps)
    104 
    105 
    106     def uninstall_link(self):
    107         if os.path.exists(self.egg_link):
    108             log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
    109             contents = [line.rstrip() for line in file(self.egg_link)]
    110             if contents not in ([self.egg_path], [self.egg_path, self.setup_path]):
    111                 log.warn("Link points to %s: uninstall aborted", contents)
    112                 return
    113             if not self.dry_run:
    114                 os.unlink(self.egg_link)
    115         if not self.dry_run:
    116             self.update_pth(self.dist)  # remove any .pth link to us
    117         if self.distribution.scripts:
    118             # XXX should also check for entry point scripts!
    119             log.warn("Note: you must uninstall or replace scripts manually!")
    120 
    121 
    122 
    123 
    124 
    125     def install_egg_scripts(self, dist):
    126         if dist is not self.dist:
    127             # Installing a dependency, so fall back to normal behavior
    128             return easy_install.install_egg_scripts(self,dist)
    129 
    130         # create wrapper scripts in the script dir, pointing to dist.scripts
    131 
    132         # new-style...
    133         self.install_wrapper_scripts(dist)
    134 
    135         # ...and old-style
    136         for script_name in self.distribution.scripts or []:
    137             script_path = os.path.abspath(convert_path(script_name))
    138             script_name = os.path.basename(script_path)
    139             f = open(script_path,'rU')
    140             script_text = f.read()
    141             f.close()
    142             self.install_script(dist, script_name, script_text, script_path)
    143 
    144 
    145 
    146 
    147 
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
    156 
    157 
    158 
    159 
    160 
    161 
    162 
    163 
    164 
    165 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/easy_install.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/easy_install.py b/setuptools-0.6c16dev4.egg/setuptools/command/easy_install.py
    deleted file mode 100644
    index 8ac42b4..0000000
    + -  
    1 #!python
    2 """\
    3 Easy Install
    4 ------------
    5 
    6 A tool for doing automatic download/extract/build of distutils-based Python
    7 packages.  For detailed documentation, see the accompanying EasyInstall.txt
    8 file, or visit the `EasyInstall home page`__.
    9 
    10 __ http://peak.telecommunity.com/DevCenter/EasyInstall
    11 """
    12 import sys, os.path, zipimport, shutil, tempfile, zipfile, re, stat, random
    13 from glob import glob
    14 from setuptools import Command, _dont_write_bytecode
    15 from setuptools import __version__ as setuptools_version
    16 from setuptools.sandbox import run_setup
    17 from distutils import log, dir_util
    18 from distutils.sysconfig import get_python_lib
    19 from distutils.errors import DistutilsArgError, DistutilsOptionError, \
    20     DistutilsError
    21 from setuptools.archive_util import unpack_archive
    22 from setuptools.package_index import PackageIndex, parse_bdist_wininst
    23 from setuptools.package_index import URL_SCHEME
    24 from setuptools.command import bdist_egg, egg_info
    25 from pkg_resources import *
    26 sys_executable = os.path.normpath(sys.executable)
    27 
    28 __all__ = [
    29     'samefile', 'easy_install', 'PthDistributions', 'extract_wininst_cfg',
    30     'main', 'get_exe_prefixes',
    31 ]
    32 
    33 def samefile(p1,p2):
    34     if hasattr(os.path,'samefile') and (
    35         os.path.exists(p1) and os.path.exists(p2)
    36     ):
    37         return os.path.samefile(p1,p2)
    38     return (
    39         os.path.normpath(os.path.normcase(p1)) ==
    40         os.path.normpath(os.path.normcase(p2))
    41     )
    42 
    43 class easy_install(Command):
    44     """Manage a download/build/install process"""
    45     description = "Find/get/install Python packages"
    46     command_consumes_arguments = True
    47 
    48     user_options = [
    49         ('prefix=', None, "installation prefix"),
    50         ("zip-ok", "z", "install package as a zipfile"),
    51         ("multi-version", "m", "make apps have to require() a version"),
    52         ("upgrade", "U", "force upgrade (searches PyPI for latest versions)"),
    53         ("install-dir=", "d", "install package to DIR"),
    54         ("script-dir=", "s", "install scripts to DIR"),
    55         ("exclude-scripts", "x", "Don't install scripts"),
    56         ("always-copy", "a", "Copy all needed packages to install dir"),
    57         ("index-url=", "i", "base URL of Python Package Index"),
    58         ("find-links=", "f", "additional URL(s) to search for packages"),
    59         ("delete-conflicting", "D", "no longer needed; don't use this"),
    60         ("ignore-conflicts-at-my-risk", None,
    61             "no longer needed; don't use this"),
    62         ("build-directory=", "b",
    63             "download/extract/build in DIR; keep the results"),
    64         ('optimize=', 'O',
    65          "also compile with optimization: -O1 for \"python -O\", "
    66          "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
    67         ('record=', None,
    68          "filename in which to record list of installed files"),
    69         ('always-unzip', 'Z', "don't install as a zipfile, no matter what"),
    70         ('site-dirs=','S',"list of directories where .pth files work"),
    71         ('editable', 'e', "Install specified packages in editable form"),
    72         ('no-deps', 'N', "don't install dependencies"),
    73         ('allow-hosts=', 'H', "pattern(s) that hostnames must match"),
    74         ('local-snapshots-ok', 'l', "allow building eggs from local checkouts"),
    75     ]
    76     boolean_options = [
    77         'zip-ok', 'multi-version', 'exclude-scripts', 'upgrade', 'always-copy',
    78         'delete-conflicting', 'ignore-conflicts-at-my-risk', 'editable',
    79         'no-deps', 'local-snapshots-ok',
    80     ]
    81     negative_opt = {'always-unzip': 'zip-ok'}
    82     create_index = PackageIndex
    83 
    84     def initialize_options(self):
    85         self.zip_ok = self.local_snapshots_ok = None
    86         self.install_dir = self.script_dir = self.exclude_scripts = None
    87         self.index_url = None
    88         self.find_links = None
    89         self.build_directory = None
    90         self.args = None
    91         self.optimize = self.record = None
    92         self.upgrade = self.always_copy = self.multi_version = None
    93         self.editable = self.no_deps = self.allow_hosts = None
    94         self.root = self.prefix = self.no_report = None
    95 
    96         # Options not specifiable via command line
    97         self.package_index = None
    98         self.pth_file = self.always_copy_from = None
    99         self.delete_conflicting = None
    100         self.ignore_conflicts_at_my_risk = None
    101         self.site_dirs = None
    102         self.installed_projects = {}
    103         self.sitepy_installed = False
    104         # Always read easy_install options, even if we are subclassed, or have
    105         # an independent instance created.  This ensures that defaults will
    106         # always come from the standard configuration file(s)' "easy_install"
    107         # section, even if this is a "develop" or "install" command, or some
    108         # other embedding.
    109         self._dry_run = None
    110         self.verbose = self.distribution.verbose
    111         self.distribution._set_command_options(
    112             self, self.distribution.get_option_dict('easy_install')
    113         )
    114 
    115     def delete_blockers(self, blockers):
    116         for filename in blockers:
    117             if os.path.exists(filename) or os.path.islink(filename):
    118                 log.info("Deleting %s", filename)
    119                 if not self.dry_run:
    120                     if os.path.isdir(filename) and not os.path.islink(filename):
    121                         rmtree(filename)
    122                     else:
    123                         os.unlink(filename)
    124 
    125     def finalize_options(self):
    126         self._expand('install_dir','script_dir','build_directory','site_dirs')
    127         # If a non-default installation directory was specified, default the
    128         # script directory to match it.
    129         if self.script_dir is None:
    130             self.script_dir = self.install_dir
    131 
    132         # Let install_dir get set by install_lib command, which in turn
    133         # gets its info from the install command, and takes into account
    134         # --prefix and --home and all that other crud.
    135         self.set_undefined_options('install_lib',
    136             ('install_dir','install_dir')
    137         )
    138         # Likewise, set default script_dir from 'install_scripts.install_dir'
    139         self.set_undefined_options('install_scripts',
    140             ('install_dir', 'script_dir')
    141         )
    142         # default --record from the install command
    143         self.set_undefined_options('install', ('record', 'record'))
    144         normpath = map(normalize_path, sys.path)
    145         self.all_site_dirs = get_site_dirs()
    146         if self.site_dirs is not None:
    147             site_dirs = [
    148                 os.path.expanduser(s.strip()) for s in self.site_dirs.split(',')
    149             ]
    150             for d in site_dirs:
    151                 if not os.path.isdir(d):
    152                     log.warn("%s (in --site-dirs) does not exist", d)
    153                 elif normalize_path(d) not in normpath:
    154                     raise DistutilsOptionError(
    155                         d+" (in --site-dirs) is not on sys.path"
    156                     )
    157                 else:
    158                     self.all_site_dirs.append(normalize_path(d))
    159         if not self.editable: self.check_site_dir()
    160         self.index_url = self.index_url or "http://pypi.python.org/simple"
    161         self.shadow_path = self.all_site_dirs[:]
    162         for path_item in self.install_dir, normalize_path(self.script_dir):
    163             if path_item not in self.shadow_path:
    164                 self.shadow_path.insert(0, path_item)
    165 
    166         if self.allow_hosts is not None:
    167             hosts = [s.strip() for s in self.allow_hosts.split(',')]
    168         else:
    169             hosts = ['*']
    170         if self.package_index is None:
    171             self.package_index = self.create_index(
    172                 self.index_url, search_path = self.shadow_path+sys.path, hosts=hosts,
    173             )
    174         self.local_index = Environment(self.shadow_path+sys.path)
    175 
    176         if self.find_links is not None:
    177             if isinstance(self.find_links, basestring):
    178                 self.find_links = self.find_links.split()
    179         else:
    180             self.find_links = []
    181         if self.local_snapshots_ok:
    182             self.package_index.scan_egg_links(self.shadow_path+sys.path)
    183         self.package_index.add_find_links(self.find_links)
    184         self.set_undefined_options('install_lib', ('optimize','optimize'))
    185         if not isinstance(self.optimize,int):
    186             try:
    187                 self.optimize = int(self.optimize)
    188                 if not (0 <= self.optimize <= 2): raise ValueError
    189             except ValueError:
    190                 raise DistutilsOptionError("--optimize must be 0, 1, or 2")
    191 
    192         if self.delete_conflicting and self.ignore_conflicts_at_my_risk:
    193             raise DistutilsOptionError(
    194                 "Can't use both --delete-conflicting and "
    195                 "--ignore-conflicts-at-my-risk at the same time"
    196             )
    197         if self.editable and not self.build_directory:
    198             raise DistutilsArgError(
    199                 "Must specify a build directory (-b) when using --editable"
    200             )
    201         if not self.args:
    202             raise DistutilsArgError(
    203                 "No urls, filenames, or requirements specified (see --help)")
    204 
    205         self.outputs = []
    206 
    207     def run(self):
    208         if self.verbose!=self.distribution.verbose:
    209             log.set_verbosity(self.verbose)
    210         try:
    211             for spec in self.args:
    212                 self.easy_install(spec, not self.no_deps)
    213             if self.record:
    214                 outputs = self.outputs
    215                 if self.root:               # strip any package prefix
    216                     root_len = len(self.root)
    217                     for counter in xrange(len(outputs)):
    218                         outputs[counter] = outputs[counter][root_len:]
    219                 from distutils import file_util
    220                 self.execute(
    221                     file_util.write_file, (self.record, outputs),
    222                     "writing list of installed files to '%s'" %
    223                     self.record
    224                 )
    225             self.warn_deprecated_options()
    226         finally:
    227             log.set_verbosity(self.distribution.verbose)
    228 
    229     def pseudo_tempname(self):
    230         """Return a pseudo-tempname base in the install directory.
    231         This code is intentionally naive; if a malicious party can write to
    232         the target directory you're already in deep doodoo.
    233         """
    234         try:
    235             pid = os.getpid()
    236         except:
    237             pid = random.randint(0,sys.maxint)
    238         return os.path.join(self.install_dir, "test-easy-install-%s" % pid)
    239 
    240     def warn_deprecated_options(self):
    241         if self.delete_conflicting or self.ignore_conflicts_at_my_risk:
    242             log.warn(
    243                 "Note: The -D, --delete-conflicting and"
    244                 " --ignore-conflicts-at-my-risk no longer have any purpose"
    245                 " and should not be used."
    246             )
    247 
    248     def check_site_dir(self):
    249         """Verify that self.install_dir is .pth-capable dir, if needed"""
    250         instdir = normalize_path(self.install_dir)
    251         pth_file = os.path.join(instdir,'easy-install.pth')
    252 
    253         # mkdir it if necessary
    254         try:
    255             os.makedirs(instdir)
    256         except OSError:
    257             # Oh well -- hopefully this error simply means that it is already there.
    258             # If not the subsequent write test will identify the problem.
    259             pass
    260         # add it to site dirs
    261         self.all_site_dirs.append(instdir)
    262 
    263         # Is it a configured, PYTHONPATH, implicit, or explicit site dir?
    264         is_site_dir = instdir in self.all_site_dirs
    265 
    266         if not is_site_dir and not self.multi_version:
    267             # No?  Then directly test whether it does .pth file processing
    268             is_site_dir = self.check_pth_processing()
    269         else:
    270             # make sure we can write to target dir
    271             testfile = self.pseudo_tempname()+'.write-test'
    272             test_exists = os.path.exists(testfile)
    273             try:
    274                 if test_exists: os.unlink(testfile)
    275                 open(testfile,'w').close()
    276                 os.unlink(testfile)
    277             except (OSError,IOError):
    278                 self.cant_write_to_target()
    279 
    280         if not is_site_dir and not self.multi_version:
    281             # Can't install non-multi to non-site dir
    282             log.warn(self.no_default_version_msg())
    283 
    284         if is_site_dir:
    285             if self.pth_file is None:
    286                 self.pth_file = PthDistributions(pth_file, self.all_site_dirs)
    287         else:
    288             self.pth_file = None
    289 
    290         if self.multi_version and not os.path.exists(pth_file):
    291             self.sitepy_installed = True    # don't need site.py in this case
    292             self.pth_file = None            # and don't create a .pth file
    293         self.install_dir = instdir
    294 
    295     def cant_write_to_target(self):
    296         msg = """can't create or remove files in install directory
    297 
    298 The following error occurred while trying to add or remove files in the
    299 installation directory:
    300 
    301     %s
    302 
    303 The installation directory you specified (via --install-dir, --prefix, or
    304 the distutils default setting) was:
    305 
    306     %s
    307 """     % (sys.exc_info()[1], self.install_dir,)
    308 
    309         if not os.path.exists(self.install_dir):
    310             msg += """
    311 This directory does not currently exist.  Please create it and try again, or
    312 choose a different installation directory (using the -d or --install-dir
    313 option).
    314 """
    315         else:
    316             msg += """
    317 Perhaps your account does not have write access to this directory?  If the
    318 installation directory is a system-owned directory, you may need to sign in
    319 as the administrator or "root" account.  If you do not have administrative
    320 access to this machine, you may wish to choose a different installation
    321 directory, preferably one that is listed in your PYTHONPATH environment
    322 variable.
    323 
    324 For information on other options, you may wish to consult the
    325 documentation at:
    326 
    327   http://peak.telecommunity.com/EasyInstall.html
    328 
    329 Please make the appropriate changes for your system and try again.
    330 """
    331         raise DistutilsError(msg)
    332 
    333 
    334 
    335 
    336     def check_pth_processing(self):
    337         """Empirically verify whether .pth files are supported in inst. dir"""
    338         instdir = self.install_dir
    339         log.info("Checking .pth file support in %s", instdir)
    340         pth_file = self.pseudo_tempname()+".pth"
    341         ok_file = pth_file+'.ok'
    342         ok_exists = os.path.exists(ok_file)
    343         try:
    344             if ok_exists: os.unlink(ok_file)
    345             f = open(pth_file,'w')
    346         except (OSError,IOError):
    347             self.cant_write_to_target()
    348         else:
    349             try:
    350                 f.write("import os;open(%r,'w').write('OK')\n" % (ok_file,))
    351                 f.close(); f=None
    352                 executable = sys.executable
    353                 if os.name=='nt':
    354                     dirname,basename = os.path.split(executable)
    355                     alt = os.path.join(dirname,'pythonw.exe')
    356                     if basename.lower()=='python.exe' and os.path.exists(alt):
    357                         # use pythonw.exe to avoid opening a console window
    358                         executable = alt
    359 
    360                 from distutils.spawn import spawn
    361                 spawn([executable,'-E','-c','pass'],0)
    362 
    363                 if os.path.exists(ok_file):
    364                     log.info(
    365                         "TEST PASSED: %s appears to support .pth files",
    366                         instdir
    367                     )
    368                     return True
    369             finally:
    370                 if f: f.close()
    371                 if os.path.exists(ok_file): os.unlink(ok_file)
    372                 if os.path.exists(pth_file): os.unlink(pth_file)
    373         if not self.multi_version:
    374             log.warn("TEST FAILED: %s does NOT support .pth files", instdir)
    375         return False
    376 
    377     def install_egg_scripts(self, dist):
    378         """Write all the scripts for `dist`, unless scripts are excluded"""
    379         if not self.exclude_scripts and dist.metadata_isdir('scripts'):
    380             for script_name in dist.metadata_listdir('scripts'):
    381                 self.install_script(
    382                     dist, script_name,
    383                     dist.get_metadata('scripts/'+script_name)
    384                 )
    385         self.install_wrapper_scripts(dist)
    386 
    387     def add_output(self, path):
    388         if os.path.isdir(path):
    389             for base, dirs, files in os.walk(path):
    390                 for filename in files:
    391                     self.outputs.append(os.path.join(base,filename))
    392         else:
    393             self.outputs.append(path)
    394 
    395     def not_editable(self, spec):
    396         if self.editable:
    397             raise DistutilsArgError(
    398                 "Invalid argument %r: you can't use filenames or URLs "
    399                 "with --editable (except via the --find-links option)."
    400                 % (spec,)
    401             )
    402 
    403     def check_editable(self,spec):
    404         if not self.editable:
    405             return
    406 
    407         if os.path.exists(os.path.join(self.build_directory, spec.key)):
    408             raise DistutilsArgError(
    409                 "%r already exists in %s; can't do a checkout there" %
    410                 (spec.key, self.build_directory)
    411             )
    412 
    413 
    414 
    415 
    416 
    417 
    418     def easy_install(self, spec, deps=False):
    419         tmpdir = tempfile.mkdtemp(prefix="easy_install-")
    420         download = None
    421         if not self.editable: self.install_site_py()
    422 
    423         try:
    424             if not isinstance(spec,Requirement):
    425                 if URL_SCHEME(spec):
    426                     # It's a url, download it to tmpdir and process
    427                     self.not_editable(spec)
    428                     download = self.package_index.download(spec, tmpdir)
    429                     return self.install_item(None, download, tmpdir, deps, True)
    430 
    431                 elif os.path.exists(spec):
    432                     # Existing file or directory, just process it directly
    433                     self.not_editable(spec)
    434                     return self.install_item(None, spec, tmpdir, deps, True)
    435                 else:
    436                     spec = parse_requirement_arg(spec)
    437 
    438             self.check_editable(spec)
    439             dist = self.package_index.fetch_distribution(
    440                 spec, tmpdir, self.upgrade, self.editable, not self.always_copy,
    441                 self.local_index
    442             )
    443             if dist is None:
    444                 msg = "Could not find suitable distribution for %r" % spec
    445                 if self.always_copy:
    446                     msg+=" (--always-copy skips system and development eggs)"
    447                 raise DistutilsError(msg)
    448             elif dist.precedence==DEVELOP_DIST:
    449                 # .egg-info dists don't need installing, just process deps
    450                 self.process_distribution(spec, dist, deps, "Using")
    451                 return dist
    452             else:
    453                 return self.install_item(spec, dist.location, tmpdir, deps)
    454 
    455         finally:
    456             if os.path.exists(tmpdir):
    457                 rmtree(tmpdir)
    458 
    459     def install_item(self, spec, download, tmpdir, deps, install_needed=False):
    460 
    461         # Installation is also needed if file in tmpdir or is not an egg
    462         install_needed = install_needed or self.always_copy
    463         install_needed = install_needed or os.path.dirname(download) == tmpdir
    464         install_needed = install_needed or not download.endswith('.egg')
    465         install_needed = install_needed or (
    466             self.always_copy_from is not None and
    467             os.path.dirname(normalize_path(download)) ==
    468             normalize_path(self.always_copy_from)
    469         )
    470 
    471         if spec and not install_needed:
    472             # at this point, we know it's a local .egg, we just don't know if
    473             # it's already installed.
    474             for dist in self.local_index[spec.project_name]:
    475                 if dist.location==download:
    476                     break
    477             else:
    478                 install_needed = True   # it's not in the local index
    479 
    480         log.info("Processing %s", os.path.basename(download))
    481 
    482         if install_needed:
    483             dists = self.install_eggs(spec, download, tmpdir)
    484             for dist in dists:
    485                 self.process_distribution(spec, dist, deps)
    486         else:
    487             dists = [self.check_conflicts(self.egg_distribution(download))]
    488             self.process_distribution(spec, dists[0], deps, "Using")
    489 
    490         if spec is not None:
    491             for dist in dists:
    492                 if dist in spec:
    493                     return dist
    494 
    495 
    496 
    497 
    498 
    499 
    500     def process_distribution(self, requirement, dist, deps=True, *info):
    501         self.update_pth(dist)
    502         self.package_index.add(dist)
    503         self.local_index.add(dist)
    504         self.install_egg_scripts(dist)
    505         self.installed_projects[dist.key] = dist
    506         log.info(self.installation_report(requirement, dist, *info))
    507         if dist.has_metadata('dependency_links.txt'):
    508             self.package_index.add_find_links(
    509                 dist.get_metadata_lines('dependency_links.txt')
    510             )
    511         if not deps and not self.always_copy:
    512             return
    513         elif requirement is not None and dist.key != requirement.key:
    514             log.warn("Skipping dependencies for %s", dist)
    515             return  # XXX this is not the distribution we were looking for
    516         elif requirement is None or dist not in requirement:
    517             # if we wound up with a different version, resolve what we've got
    518             distreq = dist.as_requirement()
    519             requirement = requirement or distreq
    520             requirement = Requirement(
    521                 distreq.project_name, distreq.specs, requirement.extras
    522             )
    523         log.info("Processing dependencies for %s", requirement)
    524         try:
    525             distros = WorkingSet([]).resolve(
    526                 [requirement], self.local_index, self.easy_install
    527             )
    528         except DistributionNotFound, e:
    529             raise DistutilsError(
    530                 "Could not find required distribution %s" % e.args
    531             )
    532         except VersionConflict, e:
    533             raise DistutilsError(
    534                 "Installed distribution %s conflicts with requirement %s"
    535                 % e.args
    536             )
    537         if self.always_copy or self.always_copy_from:
    538             # Force all the relevant distros to be copied or activated
    539             for dist in distros:
    540                 if dist.key not in self.installed_projects:
    541                     self.easy_install(dist.as_requirement())
    542         log.info("Finished processing dependencies for %s", requirement)
    543 
    544     def should_unzip(self, dist):
    545         if self.zip_ok is not None:
    546             return not self.zip_ok
    547         if dist.has_metadata('not-zip-safe'):
    548             return True
    549         if not dist.has_metadata('zip-safe'):
    550             return True
    551         return False
    552 
    553     def maybe_move(self, spec, dist_filename, setup_base):
    554         dst = os.path.join(self.build_directory, spec.key)
    555         if os.path.exists(dst):
    556             log.warn(
    557                "%r already exists in %s; build directory %s will not be kept",
    558                spec.key, self.build_directory, setup_base
    559             )
    560             return setup_base
    561         if os.path.isdir(dist_filename):
    562             setup_base = dist_filename
    563         else:
    564             if os.path.dirname(dist_filename)==setup_base:
    565                 os.unlink(dist_filename)   # get it out of the tmp dir
    566             contents = os.listdir(setup_base)
    567             if len(contents)==1:
    568                 dist_filename = os.path.join(setup_base,contents[0])
    569                 if os.path.isdir(dist_filename):
    570                     # if the only thing there is a directory, move it instead
    571                     setup_base = dist_filename
    572         ensure_directory(dst); shutil.move(setup_base, dst)
    573         return dst
    574 
    575     def install_wrapper_scripts(self, dist):
    576         if not self.exclude_scripts:
    577             for args in get_script_args(dist, script_dir=self.script_dir):
    578                 self.write_script(*args)
    579 
    580 
    581 
    582     def install_script(self, dist, script_name, script_text, dev_path=None):
    583         """Generate a legacy script wrapper and install it"""
    584         spec = str(dist.as_requirement())
    585         is_script = is_python_script(script_text, script_name)
    586 
    587         requires = [spec] + [str(r) for r in dist.requires()]
    588         if is_script and dev_path:
    589             script_text = get_script_header(script_text) + (
    590                 "# EASY-INSTALL-DEV-SCRIPT: %(spec)r,%(script_name)r\n"
    591                 "__requires__ = %(requires)r\n"
    592                 "from pkg_resources import require; require(%(spec)r)\n"
    593                 "del require\n"
    594                 "__file__ = %(dev_path)r\n"
    595                 "execfile(__file__)\n"
    596             ) % locals()
    597         elif is_script:
    598             script_text = get_script_header(script_text) + (
    599                 "# EASY-INSTALL-SCRIPT: %(spec)r,%(script_name)r\n"
    600                 "__requires__ = %(requires)r\n"
    601                 "import pkg_resources\n"
    602                 "pkg_resources.run_script(%(spec)r, %(script_name)r)\n"
    603             ) % locals()
    604         self.write_script(script_name, script_text, 'b')
    605 
    606     def write_script(self, script_name, contents, mode="t", blockers=()):
    607         """Write an executable file to the scripts directory"""
    608         self.delete_blockers(   # clean up old .py/.pyw w/o a script
    609             [os.path.join(self.script_dir,x) for x in blockers])
    610         log.info("Installing %s script to %s", script_name, self.script_dir)
    611         target = os.path.join(self.script_dir, script_name)
    612         self.add_output(target)
    613 
    614         if not self.dry_run:
    615             ensure_directory(target)
    616             f = open(target,"w"+mode)
    617             f.write(contents)
    618             f.close()
    619             chmod(target,0755)
    620 
    621 
    622 
    623 
    624     def install_eggs(self, spec, dist_filename, tmpdir):
    625         # .egg dirs or files are already built, so just return them
    626         if dist_filename.lower().endswith('.egg'):
    627             return [self.install_egg(dist_filename, tmpdir)]
    628         elif dist_filename.lower().endswith('.exe'):
    629             return [self.install_exe(dist_filename, tmpdir)]
    630 
    631         # Anything else, try to extract and build
    632         setup_base = tmpdir
    633         if os.path.isfile(dist_filename) and not dist_filename.endswith('.py'):
    634             unpack_archive(dist_filename, tmpdir, self.unpack_progress)
    635         elif os.path.isdir(dist_filename):
    636             setup_base = os.path.abspath(dist_filename)
    637 
    638         if (setup_base.startswith(tmpdir)   # something we downloaded
    639             and self.build_directory and spec is not None
    640         ):
    641             setup_base = self.maybe_move(spec, dist_filename, setup_base)
    642 
    643         # Find the setup.py file
    644         setup_script = os.path.join(setup_base, 'setup.py')
    645 
    646         if not os.path.exists(setup_script):
    647             setups = glob(os.path.join(setup_base, '*', 'setup.py'))
    648             if not setups:
    649                 raise DistutilsError(
    650                     "Couldn't find a setup script in %s" % os.path.abspath(dist_filename)
    651                 )
    652             if len(setups)>1:
    653                 raise DistutilsError(
    654                     "Multiple setup scripts in %s" % os.path.abspath(dist_filename)
    655                 )
    656             setup_script = setups[0]
    657 
    658         # Now run it, and return the result
    659         if self.editable:
    660             log.info(self.report_editable(spec, setup_script))
    661             return []
    662         else:
    663             return self.build_and_install(setup_script, setup_base)
    664 
    665     def egg_distribution(self, egg_path):
    666         if os.path.isdir(egg_path):
    667             metadata = PathMetadata(egg_path,os.path.join(egg_path,'EGG-INFO'))
    668         else:
    669             metadata = EggMetadata(zipimport.zipimporter(egg_path))
    670         return Distribution.from_filename(egg_path,metadata=metadata)
    671 
    672     def install_egg(self, egg_path, tmpdir):
    673         destination = os.path.join(self.install_dir,os.path.basename(egg_path))
    674         destination = os.path.abspath(destination)
    675         if not self.dry_run:
    676             ensure_directory(destination)
    677 
    678         dist = self.egg_distribution(egg_path)
    679         self.check_conflicts(dist)
    680         if not samefile(egg_path, destination):
    681             if os.path.isdir(destination) and not os.path.islink(destination):
    682                 dir_util.remove_tree(destination, dry_run=self.dry_run)
    683             elif os.path.exists(destination):
    684                 self.execute(os.unlink,(destination,),"Removing "+destination)
    685             uncache_zipdir(destination)
    686             if os.path.isdir(egg_path):
    687                 if egg_path.startswith(tmpdir):
    688                     f,m = shutil.move, "Moving"
    689                 else:
    690                     f,m = shutil.copytree, "Copying"
    691             elif self.should_unzip(dist):
    692                 self.mkpath(destination)
    693                 f,m = self.unpack_and_compile, "Extracting"
    694             elif egg_path.startswith(tmpdir):
    695                 f,m = shutil.move, "Moving"
    696             else:
    697                 f,m = shutil.copy2, "Copying"
    698 
    699             self.execute(f, (egg_path, destination),
    700                 (m+" %s to %s") %
    701                 (os.path.basename(egg_path),os.path.dirname(destination)))
    702 
    703         self.add_output(destination)
    704         return self.egg_distribution(destination)
    705 
    706     def install_exe(self, dist_filename, tmpdir):
    707         # See if it's valid, get data
    708         cfg = extract_wininst_cfg(dist_filename)
    709         if cfg is None:
    710             raise DistutilsError(
    711                 "%s is not a valid distutils Windows .exe" % dist_filename
    712             )
    713         # Create a dummy distribution object until we build the real distro
    714         dist = Distribution(None,
    715             project_name=cfg.get('metadata','name'),
    716             version=cfg.get('metadata','version'), platform="win32"
    717         )
    718 
    719         # Convert the .exe to an unpacked egg
    720         egg_path = dist.location = os.path.join(tmpdir, dist.egg_name()+'.egg')
    721         egg_tmp  = egg_path+'.tmp'
    722         egg_info = os.path.join(egg_tmp, 'EGG-INFO')
    723         pkg_inf = os.path.join(egg_info, 'PKG-INFO')
    724         ensure_directory(pkg_inf)   # make sure EGG-INFO dir exists
    725         dist._provider = PathMetadata(egg_tmp, egg_info)    # XXX
    726         self.exe_to_egg(dist_filename, egg_tmp)
    727 
    728         # Write EGG-INFO/PKG-INFO
    729         if not os.path.exists(pkg_inf):
    730             f = open(pkg_inf,'w')
    731             f.write('Metadata-Version: 1.0\n')
    732             for k,v in cfg.items('metadata'):
    733                 if k!='target_version':
    734                     f.write('%s: %s\n' % (k.replace('_','-').title(), v))
    735             f.close()
    736         script_dir = os.path.join(egg_info,'scripts')
    737         self.delete_blockers(   # delete entry-point scripts to avoid duping
    738             [os.path.join(script_dir,args[0]) for args in get_script_args(dist)]
    739         )
    740         # Build .egg file from tmpdir
    741         bdist_egg.make_zipfile(
    742             egg_path, egg_tmp, verbose=self.verbose, dry_run=self.dry_run
    743         )
    744         # install the .egg
    745         return self.install_egg(egg_path, tmpdir)
    746 
    747     def exe_to_egg(self, dist_filename, egg_tmp):
    748         """Extract a bdist_wininst to the directories an egg would use"""
    749         # Check for .pth file and set up prefix translations
    750         prefixes = get_exe_prefixes(dist_filename)
    751         to_compile = []
    752         native_libs = []
    753         top_level = {}
    754         def process(src,dst):
    755             s = src.lower()
    756             for old,new in prefixes:
    757                 if s.startswith(old):
    758                     src = new+src[len(old):]
    759                     parts = src.split('/')
    760                     dst = os.path.join(egg_tmp, *parts)
    761                     dl = dst.lower()
    762                     if dl.endswith('.pyd') or dl.endswith('.dll'):
    763                         parts[-1] = bdist_egg.strip_module(parts[-1])
    764                         top_level[os.path.splitext(parts[0])[0]] = 1
    765                         native_libs.append(src)
    766                     elif dl.endswith('.py') and old!='SCRIPTS/':
    767                         top_level[os.path.splitext(parts[0])[0]] = 1
    768                         to_compile.append(dst)
    769                     return dst
    770             if not src.endswith('.pth'):
    771                 log.warn("WARNING: can't process %s", src)
    772             return None
    773         # extract, tracking .pyd/.dll->native_libs and .py -> to_compile
    774         unpack_archive(dist_filename, egg_tmp, process)
    775         stubs = []
    776         for res in native_libs:
    777             if res.lower().endswith('.pyd'):    # create stubs for .pyd's
    778                 parts = res.split('/')
    779                 resource = parts[-1]
    780                 parts[-1] = bdist_egg.strip_module(parts[-1])+'.py'
    781                 pyfile = os.path.join(egg_tmp, *parts)
    782                 to_compile.append(pyfile); stubs.append(pyfile)
    783                 bdist_egg.write_stub(resource, pyfile)
    784         self.byte_compile(to_compile)   # compile .py's
    785         bdist_egg.write_safety_flag(os.path.join(egg_tmp,'EGG-INFO'),
    786             bdist_egg.analyze_egg(egg_tmp, stubs))  # write zip-safety flag
    787 
    788         for name in 'top_level','native_libs':
    789             if locals()[name]:
    790                 txt = os.path.join(egg_tmp, 'EGG-INFO', name+'.txt')
    791                 if not os.path.exists(txt):
    792                     open(txt,'w').write('\n'.join(locals()[name])+'\n')
    793 
    794     def check_conflicts(self, dist):
    795         """Verify that there are no conflicting "old-style" packages"""
    796 
    797         return dist     # XXX temporarily disable until new strategy is stable
    798         from imp import find_module, get_suffixes
    799         from glob import glob
    800 
    801         blockers = []
    802         names = dict.fromkeys(dist._get_metadata('top_level.txt')) # XXX private attr
    803 
    804         exts = {'.pyc':1, '.pyo':1}     # get_suffixes() might leave one out
    805         for ext,mode,typ in get_suffixes():
    806             exts[ext] = 1
    807 
    808         for path,files in expand_paths([self.install_dir]+self.all_site_dirs):
    809             for filename in files:
    810                 base,ext = os.path.splitext(filename)
    811                 if base in names:
    812                     if not ext:
    813                         # no extension, check for package
    814                         try:
    815                             f, filename, descr = find_module(base, [path])
    816                         except ImportError:
    817                             continue
    818                         else:
    819                             if f: f.close()
    820                             if filename not in blockers:
    821                                 blockers.append(filename)
    822                     elif ext in exts and base!='site':  # XXX ugh
    823                         blockers.append(os.path.join(path,filename))
    824         if blockers:
    825             self.found_conflicts(dist, blockers)
    826 
    827         return dist
    828 
    829     def found_conflicts(self, dist, blockers):
    830         if self.delete_conflicting:
    831             log.warn("Attempting to delete conflicting packages:")
    832             return self.delete_blockers(blockers)
    833 
    834         msg = """\
    835 -------------------------------------------------------------------------
    836 CONFLICT WARNING:
    837 
    838 The following modules or packages have the same names as modules or
    839 packages being installed, and will be *before* the installed packages in
    840 Python's search path.  You MUST remove all of the relevant files and
    841 directories before you will be able to use the package(s) you are
    842 installing:
    843 
    844    %s
    845 
    846 """ % '\n   '.join(blockers)
    847 
    848         if self.ignore_conflicts_at_my_risk:
    849             msg += """\
    850 (Note: you can run EasyInstall on '%s' with the
    851 --delete-conflicting option to attempt deletion of the above files
    852 and/or directories.)
    853 """ % dist.project_name
    854         else:
    855             msg += """\
    856 Note: you can attempt this installation again with EasyInstall, and use
    857 either the --delete-conflicting (-D) option or the
    858 --ignore-conflicts-at-my-risk option, to either delete the above files
    859 and directories, or to ignore the conflicts, respectively.  Note that if
    860 you ignore the conflicts, the installed package(s) may not work.
    861 """
    862         msg += """\
    863 -------------------------------------------------------------------------
    864 """
    865         sys.stderr.write(msg)
    866         sys.stderr.flush()
    867         if not self.ignore_conflicts_at_my_risk:
    868             raise DistutilsError("Installation aborted due to conflicts")
    869 
    870     def installation_report(self, req, dist, what="Installed"):
    871         """Helpful installation message for display to package users"""
    872         msg = "\n%(what)s %(eggloc)s%(extras)s"
    873         if self.multi_version and not self.no_report:
    874             msg += """
    875 
    876 Because this distribution was installed --multi-version, before you can
    877 import modules from this package in an application, you will need to
    878 'import pkg_resources' and then use a 'require()' call similar to one of
    879 these examples, in order to select the desired version:
    880 
    881     pkg_resources.require("%(name)s")  # latest installed version
    882     pkg_resources.require("%(name)s==%(version)s")  # this exact version
    883     pkg_resources.require("%(name)s>=%(version)s")  # this version or higher
    884 """
    885             if self.install_dir not in map(normalize_path,sys.path):
    886                 msg += """
    887 
    888 Note also that the installation directory must be on sys.path at runtime for
    889 this to work.  (e.g. by being the application's script directory, by being on
    890 PYTHONPATH, or by being added to sys.path by your code.)
    891 """
    892         eggloc = dist.location
    893         name = dist.project_name
    894         version = dist.version
    895         extras = '' # TODO: self.report_extras(req, dist)
    896         return msg % locals()
    897 
    898     def report_editable(self, spec, setup_script):
    899         dirname = os.path.dirname(setup_script)
    900         python = sys.executable
    901         return """\nExtracted editable version of %(spec)s to %(dirname)s
    902 
    903 If it uses setuptools in its setup script, you can activate it in
    904 "development" mode by going to that directory and running::
    905 
    906     %(python)s setup.py develop
    907 
    908 See the setuptools documentation for the "develop" command for more info.
    909 """ % locals()
    910 
    911     def run_setup(self, setup_script, setup_base, args):
    912         sys.modules.setdefault('distutils.command.bdist_egg', bdist_egg)
    913         sys.modules.setdefault('distutils.command.egg_info', egg_info)
    914 
    915         args = list(args)
    916         if self.verbose>2:
    917             v = 'v' * (self.verbose - 1)
    918             args.insert(0,'-'+v)
    919         elif self.verbose<2:
    920             args.insert(0,'-q')
    921         if self.dry_run:
    922             args.insert(0,'-n')
    923         log.info(
    924             "Running %s %s", setup_script[len(setup_base)+1:], ' '.join(args)
    925         )
    926         try:
    927             run_setup(setup_script, args)
    928         except SystemExit, v:
    929             raise DistutilsError("Setup script exited with %s" % (v.args[0],))
    930 
    931     def build_and_install(self, setup_script, setup_base):
    932         args = ['bdist_egg', '--dist-dir']
    933         dist_dir = tempfile.mkdtemp(
    934             prefix='egg-dist-tmp-', dir=os.path.dirname(setup_script)
    935         )
    936         try:
    937             args.append(dist_dir)
    938             self.run_setup(setup_script, setup_base, args)
    939             all_eggs = Environment([dist_dir])
    940             eggs = []
    941             for key in all_eggs:
    942                 for dist in all_eggs[key]:
    943                     eggs.append(self.install_egg(dist.location, setup_base))
    944             if not eggs and not self.dry_run:
    945                 log.warn("No eggs found in %s (setup script problem?)",
    946                     dist_dir)
    947             return eggs
    948         finally:
    949             rmtree(dist_dir)
    950             log.set_verbosity(self.verbose) # restore our log verbosity
    951 
    952     def update_pth(self,dist):
    953         if self.pth_file is None:
    954             return
    955 
    956         for d in self.pth_file[dist.key]:    # drop old entries
    957             if self.multi_version or d.location != dist.location:
    958                 log.info("Removing %s from easy-install.pth file", d)
    959                 self.pth_file.remove(d)
    960                 if d.location in self.shadow_path:
    961                     self.shadow_path.remove(d.location)
    962 
    963         if not self.multi_version:
    964             if dist.location in self.pth_file.paths:
    965                 log.info(
    966                     "%s is already the active version in easy-install.pth",
    967                     dist
    968                 )
    969             else:
    970                 log.info("Adding %s to easy-install.pth file", dist)
    971                 self.pth_file.add(dist) # add new entry
    972                 if dist.location not in self.shadow_path:
    973                     self.shadow_path.append(dist.location)
    974 
    975         if not self.dry_run:
    976 
    977             self.pth_file.save()
    978 
    979             if dist.key=='setuptools':
    980                 # Ensure that setuptools itself never becomes unavailable!
    981                 # XXX should this check for latest version?
    982                 filename = os.path.join(self.install_dir,'setuptools.pth')
    983                 if os.path.islink(filename): os.unlink(filename)
    984                 f = open(filename, 'wt')
    985                 f.write(self.pth_file.make_relative(dist.location)+'\n')
    986                 f.close()
    987 
    988     def unpack_progress(self, src, dst):
    989         # Progress filter for unpacking
    990         log.debug("Unpacking %s to %s", src, dst)
    991         return dst     # only unpack-and-compile skips files for dry run
    992 
    993     def unpack_and_compile(self, egg_path, destination):
    994         to_compile = []; to_chmod = []
    995 
    996         def pf(src,dst):
    997             if dst.endswith('.py') and not src.startswith('EGG-INFO/'):
    998                 to_compile.append(dst)
    999             elif dst.endswith('.dll') or dst.endswith('.so'):
    1000                 to_chmod.append(dst)
    1001             self.unpack_progress(src,dst)
    1002             return not self.dry_run and dst or None
    1003 
    1004         unpack_archive(egg_path, destination, pf)
    1005         self.byte_compile(to_compile)
    1006         if not self.dry_run:
    1007             for f in to_chmod:
    1008                 mode = ((os.stat(f)[stat.ST_MODE]) | 0555) & 07755
    1009                 chmod(f, mode)
    1010 
    1011     def byte_compile(self, to_compile):
    1012         if _dont_write_bytecode:
    1013             self.warn('byte-compiling is disabled, skipping.')
    1014             return
    1015         from distutils.util import byte_compile
    1016         try:
    1017             # try to make the byte compile messages quieter
    1018             log.set_verbosity(self.verbose - 1)
    1019 
    1020             byte_compile(to_compile, optimize=0, force=1, dry_run=self.dry_run)
    1021             if self.optimize:
    1022                 byte_compile(
    1023                     to_compile, optimize=self.optimize, force=1,
    1024                     dry_run=self.dry_run
    1025                 )
    1026         finally:
    1027             log.set_verbosity(self.verbose)     # restore original verbosity
    1028 
    1029 
    1030 
    1031 
    1032 
    1033 
    1034 
    1035 
    1036 
    1037     def no_default_version_msg(self):
    1038         return """bad install directory or PYTHONPATH
    1039 
    1040 You are attempting to install a package to a directory that is not
    1041 on PYTHONPATH and which Python does not read ".pth" files from.  The
    1042 installation directory you specified (via --install-dir, --prefix, or
    1043 the distutils default setting) was:
    1044 
    1045     %s
    1046 
    1047 and your PYTHONPATH environment variable currently contains:
    1048 
    1049     %r
    1050 
    1051 Here are some of your options for correcting the problem:
    1052 
    1053 * You can choose a different installation directory, i.e., one that is
    1054   on PYTHONPATH or supports .pth files
    1055 
    1056 * You can add the installation directory to the PYTHONPATH environment
    1057   variable.  (It must then also be on PYTHONPATH whenever you run
    1058   Python and want to use the package(s) you are installing.)
    1059 
    1060 * You can set up the installation directory to support ".pth" files by
    1061   using one of the approaches described here:
    1062 
    1063   http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations
    1064 
    1065 Proceeding to install.  Please remember that unless you make one of
    1066 these changes you will not be able to run the installed code.
    1067 """ % (
    1068         self.install_dir, os.environ.get('PYTHONPATH','')
    1069     )
    1070 
    1071 
    1072 
    1073 
    1074 
    1075 
    1076 
    1077 
    1078 
    1079 
    1080     def install_site_py(self):
    1081         """Make sure there's a site.py in the target dir, if needed"""
    1082 
    1083         if self.sitepy_installed:
    1084             return  # already did it, or don't need to
    1085 
    1086         sitepy = os.path.join(self.install_dir, "site.py")
    1087         source = resource_string("setuptools", "site-patch.py")
    1088         current = ""
    1089 
    1090         if os.path.exists(sitepy):
    1091             log.debug("Checking existing site.py in %s", self.install_dir)
    1092             current = open(sitepy,'rb').read()
    1093             if not current.startswith('def __boot():'):
    1094                 print ("\n"
    1095                        "***********************************************************************\n"
    1096                        "Warning: %s is not a\n"
    1097                        "setuptools-generated site.py. It will not be overwritten.\n"
    1098                        "***********************************************************************\n"
    1099                       ) % (sitepy,)
    1100                 self.sitepy_installed = True
    1101                 return
    1102 
    1103         if current != source:
    1104             log.info("Creating %s", sitepy)
    1105             if not self.dry_run:
    1106                 ensure_directory(sitepy)
    1107                 f = open(sitepy,'wb')
    1108                 f.write(source)
    1109                 f.close()
    1110             self.byte_compile([sitepy])
    1111 
    1112         self.sitepy_installed = True
    1113 
    1114 
    1115 
    1116 
    1117 
    1118 
    1119 
    1120 
    1121 
    1122 
    1123 
    1124 
    1125     INSTALL_SCHEMES = dict(
    1126         posix = dict(
    1127             install_dir = '$base/lib/python$py_version_short/site-packages',
    1128             script_dir  = '$base/bin',
    1129         ),
    1130     )
    1131 
    1132     DEFAULT_SCHEME = dict(
    1133         install_dir = '$base/Lib/site-packages',
    1134         script_dir  = '$base/Scripts',
    1135     )
    1136 
    1137     def _expand(self, *attrs):
    1138         config_vars = self.get_finalized_command('install').config_vars
    1139 
    1140         if self.prefix:
    1141             # Set default install_dir/scripts from --prefix
    1142             config_vars = config_vars.copy()
    1143             config_vars['base'] = self.prefix
    1144             scheme = self.INSTALL_SCHEMES.get(os.name,self.DEFAULT_SCHEME)
    1145             for attr,val in scheme.items():
    1146                 if getattr(self,attr,None) is None:
    1147                     setattr(self,attr,val)
    1148 
    1149         from distutils.util import subst_vars
    1150         for attr in attrs:
    1151             val = getattr(self, attr)
    1152             if val is not None:
    1153                 val = subst_vars(val, config_vars)
    1154                 if os.name == 'posix':
    1155                     val = os.path.expanduser(val)
    1156                 setattr(self, attr, val)
    1157 
    1158 
    1159 
    1160 
    1161 
    1162 
    1163 
    1164 
    1165 
    1166 def get_site_dirs():
    1167     # return a list of 'site' dirs
    1168     sitedirs = filter(None,os.environ.get('PYTHONPATH','').split(os.pathsep))
    1169     prefixes = [sys.prefix]
    1170     if sys.exec_prefix != sys.prefix:
    1171         prefixes.append(sys.exec_prefix)
    1172     for prefix in prefixes:
    1173         if prefix:
    1174             if sys.platform in ('os2emx', 'riscos'):
    1175                 sitedirs.append(os.path.join(prefix, "Lib", "site-packages"))
    1176             elif os.sep == '/':
    1177                 sitedirs.extend([os.path.join(prefix,
    1178                                          "lib",
    1179                                          "python" + sys.version[:3],
    1180                                          "site-packages"),
    1181                             os.path.join(prefix, "lib", "site-python")])
    1182             else:
    1183                 sitedirs.extend(
    1184                     [prefix, os.path.join(prefix, "lib", "site-packages")]
    1185                 )
    1186             if sys.platform == 'darwin':
    1187                 # for framework builds *only* we add the standard Apple
    1188                 # locations. Currently only per-user, but /Library and
    1189                 # /Network/Library could be added too
    1190                 if 'Python.framework' in prefix:
    1191                     home = os.environ.get('HOME')
    1192                     if home:
    1193                         sitedirs.append(
    1194                             os.path.join(home,
    1195                                          'Library',
    1196                                          'Python',
    1197                                          sys.version[:3],
    1198                                          'site-packages'))
    1199     for plat_specific in (0,1):
    1200         site_lib = get_python_lib(plat_specific)
    1201         if site_lib not in sitedirs: sitedirs.append(site_lib)
    1202 
    1203     sitedirs = map(normalize_path, sitedirs)
    1204     return sitedirs
    1205 
    1206 
    1207 def expand_paths(inputs):
    1208     """Yield sys.path directories that might contain "old-style" packages"""
    1209 
    1210     seen = {}
    1211 
    1212     for dirname in inputs:
    1213         dirname = normalize_path(dirname)
    1214         if dirname in seen:
    1215             continue
    1216 
    1217         seen[dirname] = 1
    1218         if not os.path.isdir(dirname):
    1219             continue
    1220 
    1221         files = os.listdir(dirname)
    1222         yield dirname, files
    1223 
    1224         for name in files:
    1225             if not name.endswith('.pth'):
    1226                 # We only care about the .pth files
    1227                 continue
    1228             if name in ('easy-install.pth','setuptools.pth'):
    1229                 # Ignore .pth files that we control
    1230                 continue
    1231 
    1232             # Read the .pth file
    1233             f = open(os.path.join(dirname,name))
    1234             lines = list(yield_lines(f))
    1235             f.close()
    1236 
    1237             # Yield existing non-dupe, non-import directory lines from it
    1238             for line in lines:
    1239                 if not line.startswith("import"):
    1240                     line = normalize_path(line.rstrip())
    1241                     if line not in seen:
    1242                         seen[line] = 1
    1243                         if not os.path.isdir(line):
    1244                             continue
    1245                         yield line, os.listdir(line)
    1246 
    1247 
    1248 def extract_wininst_cfg(dist_filename):
    1249     """Extract configuration data from a bdist_wininst .exe
    1250 
    1251     Returns a ConfigParser.RawConfigParser, or None
    1252     """
    1253     f = open(dist_filename,'rb')
    1254     try:
    1255         endrec = zipfile._EndRecData(f)
    1256         if endrec is None:
    1257             return None
    1258 
    1259         prepended = (endrec[9] - endrec[5]) - endrec[6]
    1260         if prepended < 12:  # no wininst data here
    1261             return None
    1262         f.seek(prepended-12)
    1263 
    1264         import struct, StringIO, ConfigParser
    1265         tag, cfglen, bmlen = struct.unpack("<iii",f.read(12))
    1266         if tag not in (0x1234567A, 0x1234567B):
    1267             return None     # not a valid tag
    1268 
    1269         f.seek(prepended-(12+cfglen))
    1270         cfg = ConfigParser.RawConfigParser({'version':'','target_version':''})
    1271         try:
    1272             cfg.readfp(StringIO.StringIO(f.read(cfglen).split(chr(0),1)[0]))
    1273         except ConfigParser.Error:
    1274             return None
    1275         if not cfg.has_section('metadata') or not cfg.has_section('Setup'):
    1276             return None
    1277         return cfg
    1278 
    1279     finally:
    1280         f.close()
    1281 
    1282 
    1283 
    1284 
    1285 
    1286 
    1287 
    1288 
    1289 def get_exe_prefixes(exe_filename):
    1290     """Get exe->egg path translations for a given .exe file"""
    1291 
    1292     prefixes = [
    1293         ('PURELIB/', ''), ('PLATLIB/pywin32_system32', ''),
    1294         ('PLATLIB/', ''),
    1295         ('SCRIPTS/', 'EGG-INFO/scripts/')
    1296     ]
    1297     z = zipfile.ZipFile(exe_filename)
    1298     try:
    1299         for info in z.infolist():
    1300             name = info.filename
    1301             parts = name.split('/')
    1302             if len(parts)==3 and parts[2]=='PKG-INFO':
    1303                 if parts[1].endswith('.egg-info'):
    1304                     prefixes.insert(0,('/'.join(parts[:2]), 'EGG-INFO/'))
    1305                     break
    1306             if len(parts)!=2 or not name.endswith('.pth'):
    1307                 continue
    1308             if name.endswith('-nspkg.pth'):
    1309                 continue
    1310             if parts[0].upper() in ('PURELIB','PLATLIB'):
    1311                 for pth in yield_lines(z.read(name)):
    1312                     pth = pth.strip().replace('\\','/')
    1313                     if not pth.startswith('import'):
    1314                         prefixes.append((('%s/%s/' % (parts[0],pth)), ''))
    1315     finally:
    1316         z.close()
    1317     prefixes = [(x.lower(),y) for x, y in prefixes]
    1318     prefixes.sort(); prefixes.reverse()
    1319     return prefixes
    1320 
    1321 
    1322 def parse_requirement_arg(spec):
    1323     try:
    1324         return Requirement.parse(spec)
    1325     except ValueError:
    1326         raise DistutilsError(
    1327             "Not a URL, existing file, or requirement spec: %r" % (spec,)
    1328         )
    1329 
    1330 class PthDistributions(Environment):
    1331     """A .pth file with Distribution paths in it"""
    1332 
    1333     dirty = False
    1334 
    1335     def __init__(self, filename, sitedirs=()):
    1336         self.filename = filename; self.sitedirs=map(normalize_path, sitedirs)
    1337         self.basedir = normalize_path(os.path.dirname(self.filename))
    1338         self._load(); Environment.__init__(self, [], None, None)
    1339         for path in yield_lines(self.paths):
    1340             map(self.add, find_distributions(path, True))
    1341 
    1342     def _load(self):
    1343         self.paths = []
    1344         saw_import = False
    1345         seen = dict.fromkeys(self.sitedirs)
    1346         if os.path.isfile(self.filename):
    1347             for line in open(self.filename,'rt'):
    1348                 if line.startswith('import'):
    1349                     saw_import = True
    1350                     continue
    1351                 path = line.rstrip()
    1352                 self.paths.append(path)
    1353                 if not path.strip() or path.strip().startswith('#'):
    1354                     continue
    1355                 # skip non-existent paths, in case somebody deleted a package
    1356                 # manually, and duplicate paths as well
    1357                 path = self.paths[-1] = normalize_path(
    1358                     os.path.join(self.basedir,path)
    1359                 )
    1360                 if not os.path.exists(path) or path in seen:
    1361                     self.paths.pop()    # skip it
    1362                     self.dirty = True   # we cleaned up, so we're dirty now :)
    1363                     continue
    1364                 seen[path] = 1
    1365 
    1366         if self.paths and not saw_import:
    1367             self.dirty = True   # ensure anything we touch has import wrappers
    1368         while self.paths and not self.paths[-1].strip():
    1369             self.paths.pop()
    1370 
    1371     def save(self):
    1372         """Write changed .pth file back to disk"""
    1373         if not self.dirty:
    1374             return
    1375 
    1376         data = '\n'.join(map(self.make_relative,self.paths))
    1377         if data:
    1378             log.debug("Saving %s", self.filename)
    1379             data = (
    1380                 "import sys; sys.__plen = len(sys.path)\n"
    1381                 "%s\n"
    1382                 "import sys; new=sys.path[sys.__plen:];"
    1383                 " del sys.path[sys.__plen:];"
    1384                 " p=getattr(sys,'__egginsert',len(os.environ.get('PYTHONPATH','').split(os.pathsep))); sys.path[p:p]=new;"
    1385                 " sys.__egginsert = p+len(new)\n"
    1386             ) % data
    1387 
    1388             if os.path.islink(self.filename):
    1389                 os.unlink(self.filename)
    1390             f = open(self.filename,'wb')
    1391             f.write(data); f.close()
    1392 
    1393         elif os.path.exists(self.filename):
    1394             log.debug("Deleting empty %s", self.filename)
    1395             os.unlink(self.filename)
    1396 
    1397         self.dirty = False
    1398 
    1399     def add(self,dist):
    1400         """Add `dist` to the distribution map"""
    1401         if dist.location not in self.paths and dist.location not in self.sitedirs:
    1402             self.paths.append(dist.location); self.dirty = True
    1403         Environment.add(self,dist)
    1404 
    1405     def remove(self,dist):
    1406         """Remove `dist` from the distribution map"""
    1407         while dist.location in self.paths:
    1408             self.paths.remove(dist.location); self.dirty = True
    1409         Environment.remove(self,dist)
    1410 
    1411 
    1412     def make_relative(self,path):
    1413         npath, last = os.path.split(normalize_path(path))
    1414         baselen = len(self.basedir)
    1415         parts = [last]
    1416         sep = os.altsep=='/' and '/' or os.sep
    1417         while len(npath)>=baselen:
    1418             if npath==self.basedir:
    1419                 parts.append(os.curdir)
    1420                 parts.reverse()
    1421                 return sep.join(parts)
    1422             npath, last = os.path.split(npath)
    1423             parts.append(last)
    1424         else:
    1425             return path
    1426 
    1427 def get_script_header(script_text, executable=sys_executable, wininst=False):
    1428     """Create a #! line, getting options (if any) from script_text"""
    1429     from distutils.command.build_scripts import first_line_re
    1430     first = (script_text+'\n').splitlines()[0]
    1431     match = first_line_re.match(first)
    1432     options = ''
    1433     if match:
    1434         options = match.group(1) or ''
    1435         if options: options = ' '+options
    1436     if wininst:
    1437         executable = "python.exe"
    1438     else:
    1439         executable = nt_quote_arg(executable)
    1440     hdr = "#!%(executable)s%(options)s\n" % locals()
    1441     if unicode(hdr,'ascii','ignore').encode('ascii') != hdr:
    1442         # Non-ascii path to sys.executable, use -x to prevent warnings
    1443         if options:
    1444             if options.strip().startswith('-'):
    1445                 options = ' -x'+options.strip()[1:]
    1446             # else: punt, we can't do it, let the warning happen anyway
    1447         else:
    1448             options = ' -x'
    1449     executable = fix_jython_executable(executable, options)
    1450     hdr = "#!%(executable)s%(options)s\n" % locals()
    1451     return hdr
    1452 
    1453 def auto_chmod(func, arg, exc):
    1454     if func is os.remove and os.name=='nt':
    1455         chmod(arg, stat.S_IWRITE)
    1456         return func(arg)
    1457     exc = sys.exc_info()
    1458     raise exc[0], (exc[1][0], exc[1][1] + (" %s %s" % (func,arg)))
    1459 
    1460 def uncache_zipdir(path):
    1461     """Ensure that the importer caches dont have stale info for `path`"""
    1462     from zipimport import _zip_directory_cache as zdc
    1463     _uncache(path, zdc)
    1464     _uncache(path, sys.path_importer_cache)
    1465 
    1466 def _uncache(path, cache):
    1467     if path in cache:
    1468         del cache[path]
    1469     else:
    1470         path = normalize_path(path)
    1471         for p in cache:
    1472             if normalize_path(p)==path:
    1473                 del cache[p]
    1474                 return
    1475 
    1476 def is_python(text, filename='<string>'):
    1477     "Is this string a valid Python script?"
    1478     try:
    1479         compile(text, filename, 'exec')
    1480     except (SyntaxError, TypeError):
    1481         return False
    1482     else:
    1483         return True
    1484 
    1485 def is_sh(executable):
    1486     """Determine if the specified executable is a .sh (contains a #! line)"""
    1487     try:
    1488         fp = open(executable)
    1489         magic = fp.read(2)
    1490         fp.close()
    1491     except (OSError,IOError): return executable
    1492     return magic == '#!'
    1493 
    1494 def nt_quote_arg(arg):
    1495     """Quote a command line argument according to Windows parsing rules"""
    1496 
    1497     result = []
    1498     needquote = False
    1499     nb = 0
    1500 
    1501     needquote = (" " in arg) or ("\t" in arg)
    1502     if needquote:
    1503         result.append('"')
    1504 
    1505     for c in arg:
    1506         if c == '\\':
    1507             nb += 1
    1508         elif c == '"':
    1509             # double preceding backslashes, then add a \"
    1510             result.append('\\' * (nb*2) + '\\"')
    1511             nb = 0
    1512         else:
    1513             if nb:
    1514                 result.append('\\' * nb)
    1515                 nb = 0
    1516             result.append(c)
    1517 
    1518     if nb:
    1519         result.append('\\' * nb)
    1520 
    1521     if needquote:
    1522         result.append('\\' * nb)    # double the trailing backslashes
    1523         result.append('"')
    1524 
    1525     return ''.join(result)
    1526 
    1527 
    1528 
    1529 
    1530 
    1531 
    1532 
    1533 
    1534 
    1535 def is_python_script(script_text, filename):
    1536     """Is this text, as a whole, a Python script? (as opposed to shell/bat/etc.
    1537     """
    1538     if filename.endswith('.py') or filename.endswith('.pyw'):
    1539         return True     # extension says it's Python
    1540     if is_python(script_text, filename):
    1541         return True     # it's syntactically valid Python
    1542     if script_text.startswith('#!'):
    1543         # It begins with a '#!' line, so check if 'python' is in it somewhere
    1544         return 'python' in script_text.splitlines()[0].lower()
    1545 
    1546     return False    # Not any Python I can recognize
    1547 
    1548 try:
    1549     from os import chmod as _chmod
    1550 except ImportError:
    1551     # Jython compatibility
    1552     def _chmod(*args): pass
    1553 
    1554 def chmod(path, mode):
    1555     log.debug("changing mode of %s to %o", path, mode)
    1556     try:
    1557         _chmod(path, mode)
    1558     except os.error, e:
    1559         log.debug("chmod failed: %s", e)
    1560 
    1561 def fix_jython_executable(executable, options):
    1562     if sys.platform.startswith('java') and is_sh(executable):
    1563         # Workaround Jython's sys.executable being a .sh (an invalid
    1564         # shebang line interpreter)
    1565         if options:
    1566             # Can't apply the workaround, leave it broken
    1567             log.warn("WARNING: Unable to adapt shebang line for Jython,"
    1568                              " the following script is NOT executable\n"
    1569                      "         see http://bugs.jython.org/issue1112 for"
    1570                              " more information.")
    1571         else:
    1572             return '/usr/bin/env %s' % executable
    1573     return executable
    1574 
    1575 
    1576 def get_script_args(dist, executable=sys_executable, wininst=False, script_dir=None):
    1577     """Yield write_script() argument tuples for a distribution's entrypoints"""
    1578     spec = str(dist.as_requirement())
    1579     requires = [spec] + [str(r) for r in dist.requires()]
    1580     header = get_script_header("", executable, wininst)
    1581     generated_by = "# generated by zetuptoolz %s" % (setuptools_version,)
    1582 
    1583     for group in 'console_scripts', 'gui_scripts':
    1584         for name, ep in dist.get_entry_map(group).items():
    1585             script_head, script_tail = ((
    1586                 "# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n"
    1587                 "%(generated_by)s\n"
    1588                 "__requires__ = %(requires)r\n"
    1589                 "import sys\n"
    1590                 "from pkg_resources import load_entry_point\n"
    1591                 "\n"
    1592             ) % locals(), (
    1593                 "sys.exit(\n"
    1594                 "   load_entry_point(%(spec)r, %(group)r, %(name)r)()\n"
    1595                 ")\n"
    1596             ) % locals())
    1597 
    1598             if wininst or sys.platform == "win32":
    1599                 # On Windows/wininst, add a .py[w] extension. Delete any existing
    1600                 # -script.py[w], .exe, and .exe.manifest.
    1601                 if group=='gui_scripts':
    1602                     ext = '.pyw'
    1603                     old = ['','.pyw','-script.pyw','.exe','.exe.manifest']
    1604                     which_python = 'pythonw.exe'
    1605                     new_header = re.sub('(?i)python.exe', which_python, header)
    1606                 else:
    1607                     ext = '.pyscript'
    1608                     old = ['','.pyscript','.py','.pyc','.pyo','-script.py','.exe','.exe.manifest']
    1609                     which_python = 'python.exe'
    1610                     new_header = re.sub('(?i)pythonw.exe', which_python, header)
    1611 
    1612                 len_ext = len(ext)
    1613                 script_head += (
    1614                     "# If this script doesn't work for you, make sure that the %(ext)s\n"
    1615                     "# extension is included in the PATHEXT environment variable, and is\n"
    1616                     "# associated with %(which_python)s in the registry.\n"
    1617                     "\n"
    1618                     "if sys.argv[0].endswith(%(ext)r):\n"
    1619                     "    sys.argv[0] = sys.argv[0][:-%(len_ext)r]\n"
    1620                     "\n"
    1621                 ) % locals()
    1622 
    1623                 if os.path.exists(new_header[2:-1]) or sys.platform != 'win32':
    1624                     hdr = new_header
    1625                 else:
    1626                     hdr = header
    1627                 yield (name+ext, hdr + script_head + script_tail, 't', [name+x for x in old])
    1628 
    1629                 # Also write a shell script that runs the .pyscript, for cygwin.
    1630                 #
    1631                 # We can't use a Python script, because the Python interpreter that we want
    1632                 # to use is the native Windows one, which won't understand a cygwin path.
    1633                 # Windows paths written with forward slashes are universally understood
    1634                 # (by native Python, cygwin Python, and bash), so we'll use 'cygpath -m' to
    1635                 # get the directory from which the script was run in that form. This makes
    1636                 # the cygwin script and .pyscript position-independent, provided they are
    1637                 # in the same directory.
    1638 
    1639                 def quote_path(s):
    1640                     return "\\'".join("'" + p.replace('\\', '/') + "'" for p in s.split("'"))
    1641 
    1642                 pyscript = quote_path("/"+name+ext)
    1643                 python_path = quote_path(sys.executable)
    1644                 shell_script_text = (
    1645                     '#!/bin/sh\n'
    1646                     '%(generated_by)s\n'
    1647                     '\n'
    1648                     'ScriptDir=`cygpath -m "$0/.."`\n'
    1649                     '%(python_path)s "${ScriptDir}"%(pyscript)s "$@"\n'
    1650                 ) % locals()
    1651                 yield (name, shell_script_text, 'b')
    1652             else:
    1653                 # On other platforms, we assume the right thing to do is to
    1654                 # just write the stub with no extension.
    1655                 yield (name, header + script_head + script_tail)
    1656 
    1657 
    1658 def rmtree(path, ignore_errors=False, onerror=auto_chmod):
    1659     """Recursively delete a directory tree.
    1660 
    1661     This code is taken from the Python 2.4 version of 'shutil', because
    1662     the 2.3 version doesn't really work right.
    1663     """
    1664     if ignore_errors:
    1665         def onerror(*args):
    1666             pass
    1667     elif onerror is None:
    1668         def onerror(*args):
    1669             raise
    1670     names = []
    1671     try:
    1672         names = os.listdir(path)
    1673     except os.error, err:
    1674         onerror(os.listdir, path, sys.exc_info())
    1675     for name in names:
    1676         fullname = os.path.join(path, name)
    1677         try:
    1678             mode = os.lstat(fullname).st_mode
    1679         except os.error:
    1680             mode = 0
    1681         if stat.S_ISDIR(mode):
    1682             rmtree(fullname, ignore_errors, onerror)
    1683         else:
    1684             try:
    1685                 os.remove(fullname)
    1686             except os.error, err:
    1687                 onerror(os.remove, fullname, sys.exc_info())
    1688     try:
    1689         os.rmdir(path)
    1690     except os.error:
    1691         onerror(os.rmdir, path, sys.exc_info())
    1692 
    1693 def bootstrap():
    1694     # This function is called when setuptools*.egg is run using /bin/sh
    1695     import setuptools; argv0 = os.path.dirname(setuptools.__path__[0])
    1696     sys.argv[0] = argv0; sys.argv.append(argv0); main()
    1697 
    1698 
    1699 def main(argv=None, **kw):
    1700     from setuptools import setup
    1701     from setuptools.dist import Distribution
    1702     import distutils.core
    1703 
    1704     USAGE = """\
    1705 usage: %(script)s [options] requirement_or_url ...
    1706    or: %(script)s --help
    1707 """
    1708 
    1709     def gen_usage (script_name):
    1710         script = os.path.basename(script_name)
    1711         return USAGE % vars()
    1712 
    1713     def with_ei_usage(f):
    1714         old_gen_usage = distutils.core.gen_usage
    1715         try:
    1716             distutils.core.gen_usage = gen_usage
    1717             return f()
    1718         finally:
    1719             distutils.core.gen_usage = old_gen_usage
    1720 
    1721     class DistributionWithoutHelpCommands(Distribution):
    1722         common_usage = ""
    1723         def _show_help(self,*args,**kw):
    1724             with_ei_usage(lambda: Distribution._show_help(self,*args,**kw))
    1725 
    1726     if argv is None:
    1727         argv = sys.argv[1:]
    1728 
    1729     with_ei_usage(lambda:
    1730         setup(
    1731             script_args = ['-q','easy_install', '-v']+argv,
    1732             script_name = sys.argv[0] or 'easy_install',
    1733             distclass=DistributionWithoutHelpCommands, **kw
    1734         )
    1735     )
    1736 
    1737 
    1738 
    1739 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/egg_info.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/egg_info.py b/setuptools-0.6c16dev4.egg/setuptools/command/egg_info.py
    deleted file mode 100644
    index 5a8b2db..0000000
    + -  
    1 """setuptools.command.egg_info
    2 
    3 Create a distribution's .egg-info directory and contents"""
    4 
    5 # This module should be kept compatible with Python 2.3
    6 import os, re
    7 from setuptools import Command
    8 from distutils.errors import *
    9 from distutils import log
    10 from setuptools.command.sdist import sdist
    11 from distutils.util import convert_path
    12 from distutils.filelist import FileList
    13 from pkg_resources import parse_requirements, safe_name, parse_version, \
    14     safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename
    15 from sdist import walk_revctrl
    16 
    17 class egg_info(Command):
    18     description = "create a distribution's .egg-info directory"
    19 
    20     user_options = [
    21         ('egg-base=', 'e', "directory containing .egg-info directories"
    22                            " (default: top of the source tree)"),
    23         ('tag-svn-revision', 'r',
    24             "Add subversion revision ID to version number"),
    25         ('tag-date', 'd', "Add date stamp (e.g. 20050528) to version number"),
    26         ('tag-build=', 'b', "Specify explicit tag to add to version number"),
    27         ('no-svn-revision', 'R',
    28             "Don't add subversion revision ID [default]"),
    29         ('no-date', 'D', "Don't include date stamp [default]"),
    30     ]
    31 
    32     boolean_options = ['tag-date', 'tag-svn-revision']
    33     negative_opt = {'no-svn-revision': 'tag-svn-revision',
    34                     'no-date': 'tag-date'}
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    42     def initialize_options(self):
    43         self.egg_name = None
    44         self.egg_version = None
    45         self.egg_base = None
    46         self.egg_info = None
    47         self.tag_build = None
    48         self.tag_svn_revision = 0
    49         self.tag_date = 0
    50         self.broken_egg_info = False
    51         self.vtags = None
    52 
    53     def save_version_info(self, filename):
    54         from setopt import edit_config
    55         edit_config(
    56             filename,
    57             {'egg_info':
    58                 {'tag_svn_revision':0, 'tag_date': 0, 'tag_build': self.tags()}
    59             }
    60         )
    61 
    62 
    63 
    64 
    65 
    66 
    67 
    68 
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    80 
    81 
    82 
    83     def finalize_options (self):
    84         self.egg_name = safe_name(self.distribution.get_name())
    85         self.vtags = self.tags()
    86         self.egg_version = self.tagged_version()
    87 
    88         try:
    89             list(
    90                 parse_requirements('%s==%s' % (self.egg_name,self.egg_version))
    91             )
    92         except ValueError:
    93             raise DistutilsOptionError(
    94                 "Invalid distribution name or version syntax: %s-%s" %
    95                 (self.egg_name,self.egg_version)
    96             )
    97 
    98         if self.egg_base is None:
    99             dirs = self.distribution.package_dir
    100             self.egg_base = (dirs or {}).get('',os.curdir)
    101 
    102         self.ensure_dirname('egg_base')
    103         self.egg_info = to_filename(self.egg_name)+'.egg-info'
    104         if self.egg_base != os.curdir:
    105             self.egg_info = os.path.join(self.egg_base, self.egg_info)
    106         if '-' in self.egg_name: self.check_broken_egg_info()
    107 
    108         # Set package version for the benefit of dumber commands
    109         # (e.g. sdist, bdist_wininst, etc.)
    110         #
    111         self.distribution.metadata.version = self.egg_version
    112 
    113         # If we bootstrapped around the lack of a PKG-INFO, as might be the
    114         # case in a fresh checkout, make sure that any special tags get added
    115         # to the version info
    116         #
    117         pd = self.distribution._patched_dist
    118         if pd is not None and pd.key==self.egg_name.lower():
    119             pd._version = self.egg_version
    120             pd._parsed_version = parse_version(self.egg_version)
    121             self.distribution._patched_dist = None
    122 
    123 
    124     def write_or_delete_file(self, what, filename, data, force=False):
    125         """Write `data` to `filename` or delete if empty
    126 
    127         If `data` is non-empty, this routine is the same as ``write_file()``.
    128         If `data` is empty but not ``None``, this is the same as calling
    129         ``delete_file(filename)`.  If `data` is ``None``, then this is a no-op
    130         unless `filename` exists, in which case a warning is issued about the
    131         orphaned file (if `force` is false), or deleted (if `force` is true).
    132         """
    133         if data:
    134             self.write_file(what, filename, data)
    135         elif os.path.exists(filename):
    136             if data is None and not force:
    137                 log.warn(
    138                     "%s not set in setup(), but %s exists", what, filename
    139                 )
    140                 return
    141             else:
    142                 self.delete_file(filename)
    143 
    144     def write_file(self, what, filename, data):
    145         """Write `data` to `filename` (if not a dry run) after announcing it
    146 
    147         `what` is used in a log message to identify what is being written
    148         to the file.
    149         """
    150         log.info("writing %s to %s", what, filename)
    151         if not self.dry_run:
    152             f = open(filename, 'wb')
    153             f.write(data)
    154             f.close()
    155 
    156     def delete_file(self, filename):
    157         """Delete `filename` (if not a dry run) after announcing it"""
    158         log.info("deleting %s", filename)
    159         if not self.dry_run:
    160             os.unlink(filename)
    161 
    162     def tagged_version(self):
    163         return safe_version(self.distribution.get_version() + self.vtags)
    164 
    165     def run(self):
    166         self.mkpath(self.egg_info)
    167         installer = self.distribution.fetch_build_egg
    168         for ep in iter_entry_points('egg_info.writers'):
    169             writer = ep.load(installer=installer)
    170             writer(self, ep.name, os.path.join(self.egg_info,ep.name))
    171 
    172         # Get rid of native_libs.txt if it was put there by older bdist_egg
    173         nl = os.path.join(self.egg_info, "native_libs.txt")
    174         if os.path.exists(nl):
    175             self.delete_file(nl)
    176 
    177         self.find_sources()
    178 
    179     def tags(self):
    180         version = ''
    181         if self.tag_build:
    182             version+=self.tag_build
    183         if self.tag_svn_revision and (
    184             os.path.exists('.svn') or os.path.exists('PKG-INFO')
    185         ):  version += '-r%s' % self.get_svn_revision()
    186         if self.tag_date:
    187             import time; version += time.strftime("-%Y%m%d")
    188         return version
    189 
    190 
    191 
    192 
    193 
    194 
    195 
    196 
    197 
    198 
    199 
    200 
    201 
    202 
    203 
    204 
    205 
    206     def get_svn_revision(self):
    207         revision = 0
    208         urlre = re.compile('url="([^"]+)"')
    209         revre = re.compile('committed-rev="(\d+)"')
    210 
    211         for base,dirs,files in os.walk(os.curdir):
    212             if '.svn' not in dirs:
    213                 dirs[:] = []
    214                 continue    # no sense walking uncontrolled subdirs
    215             dirs.remove('.svn')
    216             f = open(os.path.join(base,'.svn','entries'))
    217             data = f.read()
    218             f.close()
    219 
    220             if data.startswith('<?xml'):
    221                 dirurl = urlre.search(data).group(1)    # get repository URL
    222                 localrev = max([int(m.group(1)) for m in revre.finditer(data)]+[0])
    223             else:
    224                 try: svnver = int(data.splitlines()[0])
    225                 except: svnver=-1
    226                 if data<8:
    227                     log.warn("unrecognized .svn/entries format; skipping %s", base)
    228                     dirs[:] = []
    229                     continue
    230                    
    231                 data = map(str.splitlines,data.split('\n\x0c\n'))
    232                 del data[0][0]  # get rid of the '8' or '9'
    233                 dirurl = data[0][3]
    234                 localrev = max([int(d[9]) for d in data if len(d)>9 and d[9]]+[0])
    235             if base==os.curdir:
    236                 base_url = dirurl+'/'   # save the root url
    237             elif not dirurl.startswith(base_url):
    238                 dirs[:] = []
    239                 continue    # not part of the same svn tree, skip it
    240             revision = max(revision, localrev)
    241 
    242         return str(revision or get_pkg_info_revision())
    243 
    244 
    245 
    246 
    247     def find_sources(self):
    248         """Generate SOURCES.txt manifest file"""
    249         manifest_filename = os.path.join(self.egg_info,"SOURCES.txt")
    250         mm = manifest_maker(self.distribution)
    251         mm.manifest = manifest_filename
    252         mm.run()
    253         self.filelist = mm.filelist
    254 
    255     def check_broken_egg_info(self):
    256         bei = self.egg_name+'.egg-info'
    257         if self.egg_base != os.curdir:
    258             bei = os.path.join(self.egg_base, bei)
    259         if os.path.exists(bei):
    260             log.warn(
    261                 "-"*78+'\n'
    262                 "Note: Your current .egg-info directory has a '-' in its name;"
    263                 '\nthis will not work correctly with "setup.py develop".\n\n'
    264                 'Please rename %s to %s to correct this problem.\n'+'-'*78,
    265                 bei, self.egg_info
    266             )
    267             self.broken_egg_info = self.egg_info
    268             self.egg_info = bei     # make it work for now
    269 
    270 class FileList(FileList):
    271     """File list that accepts only existing, platform-independent paths"""
    272 
    273     def append(self, item):
    274         if item.endswith('\r'):     # Fix older sdists built on Windows
    275             item = item[:-1]
    276         path = convert_path(item)
    277         if os.path.exists(path):
    278             self.files.append(path)
    279 
    280 
    281 
    282 
    283 
    284 
    285 
    286 
    287 
    288 class manifest_maker(sdist):
    289 
    290     template = "MANIFEST.in"
    291 
    292     def initialize_options (self):
    293         self.use_defaults = 1
    294         self.prune = 1
    295         self.manifest_only = 1
    296         self.force_manifest = 1
    297 
    298     def finalize_options(self):
    299         pass
    300 
    301     def run(self):
    302         self.filelist = FileList()
    303         if not os.path.exists(self.manifest):
    304             self.write_manifest()   # it must exist so it'll get in the list
    305         self.filelist.findall()
    306         self.add_defaults()
    307         if os.path.exists(self.template):
    308             self.read_template()
    309         self.prune_file_list()
    310         self.filelist.sort()
    311         self.filelist.remove_duplicates()
    312         self.write_manifest()
    313 
    314     def write_manifest (self):
    315         """Write the file list in 'self.filelist' (presumably as filled in
    316         by 'add_defaults()' and 'read_template()') to the manifest file
    317         named by 'self.manifest'.
    318         """
    319         files = self.filelist.files
    320         if os.sep!='/':
    321             files = [f.replace(os.sep,'/') for f in files]
    322         self.execute(write_file, (self.manifest, files),
    323                      "writing manifest file '%s'" % self.manifest)
    324 
    325     def warn(self, msg):    # suppress missing-file warnings from sdist
    326         if not msg.startswith("standard file not found:"):
    327             sdist.warn(self, msg)
    328 
    329     def add_defaults(self):
    330         sdist.add_defaults(self)
    331         self.filelist.append(self.template)
    332         self.filelist.append(self.manifest)
    333         rcfiles = list(walk_revctrl())
    334         if rcfiles:
    335             self.filelist.extend(rcfiles)
    336         elif os.path.exists(self.manifest):
    337             self.read_manifest()
    338         ei_cmd = self.get_finalized_command('egg_info')
    339         self.filelist.include_pattern("*", prefix=ei_cmd.egg_info)
    340 
    341     def prune_file_list (self):
    342         build = self.get_finalized_command('build')
    343         base_dir = self.distribution.get_fullname()
    344         self.filelist.exclude_pattern(None, prefix=build.build_base)
    345         self.filelist.exclude_pattern(None, prefix=base_dir)
    346         sep = re.escape(os.sep)
    347         self.filelist.exclude_pattern(sep+r'(RCS|CVS|\.svn)'+sep, is_regex=1)
    348 
    349 
    350 def write_file (filename, contents):
    351     """Create a file with the specified name and write 'contents' (a
    352     sequence of strings without line terminators) to it.
    353     """
    354     f = open(filename, "wb")        # always write POSIX-style manifest
    355     f.write("\n".join(contents))
    356     f.close()
    357 
    358 
    359 
    360 
    361 
    362 
    363 
    364 
    365 
    366 
    367 
    368 
    369 
    370 def write_pkg_info(cmd, basename, filename):
    371     log.info("writing %s", filename)
    372     if not cmd.dry_run:
    373         metadata = cmd.distribution.metadata
    374         metadata.version, oldver = cmd.egg_version, metadata.version
    375         metadata.name, oldname   = cmd.egg_name, metadata.name
    376         try:
    377             # write unescaped data to PKG-INFO, so older pkg_resources
    378             # can still parse it
    379             metadata.write_pkg_info(cmd.egg_info)
    380         finally:
    381             metadata.name, metadata.version = oldname, oldver
    382 
    383         safe = getattr(cmd.distribution,'zip_safe',None)
    384         import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe)
    385 
    386 def warn_depends_obsolete(cmd, basename, filename):
    387     if os.path.exists(filename):
    388         log.warn(
    389             "WARNING: 'depends.txt' is not used by setuptools 0.6!\n"
    390             "Use the install_requires/extras_require setup() args instead."
    391         )
    392 
    393 
    394 def write_requirements(cmd, basename, filename):
    395     dist = cmd.distribution
    396     data = ['\n'.join(yield_lines(dist.install_requires or ()))]
    397     for extra,reqs in (dist.extras_require or {}).items():
    398         data.append('\n\n[%s]\n%s' % (extra, '\n'.join(yield_lines(reqs))))
    399     cmd.write_or_delete_file("requirements", filename, ''.join(data))
    400 
    401 def write_toplevel_names(cmd, basename, filename):
    402     pkgs = dict.fromkeys(
    403         [k.split('.',1)[0]
    404             for k in cmd.distribution.iter_distribution_names()
    405         ]
    406     )
    407     cmd.write_file("top-level names", filename, '\n'.join(pkgs)+'\n')
    408 
    409 
    410 
    411 def overwrite_arg(cmd, basename, filename):
    412     write_arg(cmd, basename, filename, True)
    413 
    414 def write_arg(cmd, basename, filename, force=False):
    415     argname = os.path.splitext(basename)[0]
    416     value = getattr(cmd.distribution, argname, None)
    417     if value is not None:
    418         value = '\n'.join(value)+'\n'
    419     cmd.write_or_delete_file(argname, filename, value, force)
    420 
    421 def write_entries(cmd, basename, filename):
    422     ep = cmd.distribution.entry_points
    423 
    424     if isinstance(ep,basestring) or ep is None:
    425         data = ep
    426     elif ep is not None:
    427         data = []
    428         for section, contents in ep.items():
    429             if not isinstance(contents,basestring):
    430                 contents = EntryPoint.parse_group(section, contents)
    431                 contents = '\n'.join(map(str,contents.values()))
    432             data.append('[%s]\n%s\n\n' % (section,contents))
    433         data = ''.join(data)
    434 
    435     cmd.write_or_delete_file('entry points', filename, data, True)
    436 
    437 def get_pkg_info_revision():
    438     # See if we can get a -r### off of PKG-INFO, in case this is an sdist of
    439     # a subversion revision
    440     #
    441     if os.path.exists('PKG-INFO'):
    442         f = open('PKG-INFO','rU')
    443         for line in f:
    444             match = re.match(r"Version:.*-r(\d+)\s*$", line)
    445             if match:
    446                 return int(match.group(1))
    447     return 0
    448 
    449 
    450 
    451 #
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/install.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/install.py b/setuptools-0.6c16dev4.egg/setuptools/command/install.py
    deleted file mode 100644
    index adaaeca..0000000
    + -  
    1 import setuptools, sys, glob
    2 from distutils.command.install import install as _install
    3 from distutils.errors import DistutilsArgError
    4 
    5 class install(_install):
    6     """Use easy_install to install the package, w/dependencies"""
    7 
    8     user_options = _install.user_options + [
    9         ('old-and-unmanageable', None, "Try not to use this!"),
    10         ('single-version-externally-managed', None,
    11             "used by system package builders to create 'flat' eggs"),
    12     ]
    13     boolean_options = _install.boolean_options + [
    14         'old-and-unmanageable', 'single-version-externally-managed',
    15     ]
    16     new_commands = [
    17         ('install_egg_info', lambda self: True),
    18         ('install_scripts',  lambda self: True),
    19     ]
    20     _nc = dict(new_commands)
    21     sub_commands = [
    22         cmd for cmd in _install.sub_commands if cmd[0] not in _nc
    23     ] + new_commands
    24 
    25     def initialize_options(self):
    26         _install.initialize_options(self)
    27         self.old_and_unmanageable = None
    28         self.single_version_externally_managed = None
    29         self.no_compile = None  # make DISTUTILS_DEBUG work right!
    30 
    31     def finalize_options(self):
    32         _install.finalize_options(self)
    33         if self.root:
    34             self.single_version_externally_managed = True
    35         elif self.single_version_externally_managed:
    36             if not self.root and not self.record:
    37                 raise DistutilsArgError(
    38                     "You must specify --record or --root when building system"
    39                     " packages"
    40                 )
    41 
    42     def handle_extra_path(self):
    43         if self.root or self.single_version_externally_managed:
    44             # explicit backward-compatibility mode, allow extra_path to work
    45             return _install.handle_extra_path(self)
    46 
    47         # Ignore extra_path when installing an egg (or being run by another
    48         # command without --root or --single-version-externally-managed
    49         self.path_file = None
    50         self.extra_dirs = ''
    51 
    52     def run(self):
    53         self.old_run()
    54         if sys.platform == "win32":
    55             from setuptools.command.scriptsetup import do_scriptsetup
    56             do_scriptsetup()
    57 
    58     def old_run(self):
    59         # Explicit request for old-style install?  Just do it
    60         if self.old_and_unmanageable or self.single_version_externally_managed:
    61             return _install.run(self)
    62 
    63         # Attempt to detect whether we were called from setup() or by another
    64         # command.  If we were called by setup(), our caller will be the
    65         # 'run_command' method in 'distutils.dist', and *its* caller will be
    66         # the 'run_commands' method.  If we were called any other way, our
    67         # immediate caller *might* be 'run_command', but it won't have been
    68         # called by 'run_commands'.  This is slightly kludgy, but seems to
    69         # work.
    70         #
    71         caller = sys._getframe(2)
    72         caller_module = caller.f_globals.get('__name__','')
    73         caller_name = caller.f_code.co_name
    74 
    75         if caller_module != 'distutils.dist' or caller_name!='run_commands':
    76             # We weren't called from the command line or setup(), so we
    77             # should run in backward-compatibility mode to support bdist_*
    78             # commands.
    79             _install.run(self)
    80         else:
    81             self.do_egg_install()
    82 
    83     def do_egg_install(self):
    84 
    85         easy_install = self.distribution.get_command_class('easy_install')
    86 
    87         cmd = easy_install(
    88             self.distribution, args="x", root=self.root, record=self.record,
    89         )
    90         cmd.ensure_finalized()  # finalize before bdist_egg munges install cmd
    91         cmd.always_copy_from = '.'  # make sure local-dir eggs get installed
    92 
    93         # pick up setup-dir .egg files only: no .egg-info
    94         cmd.package_index.scan(glob.glob('*.egg'))
    95 
    96         self.run_command('bdist_egg')
    97         args = [self.distribution.get_command_obj('bdist_egg').egg_output]
    98 
    99         if setuptools.bootstrap_install_from:
    100             # Bootstrap self-installation of setuptools
    101             args.insert(0, setuptools.bootstrap_install_from)
    102 
    103         cmd.args = args
    104         cmd.run()
    105         setuptools.bootstrap_install_from = None
    106 
    107 
    108 
    109 
    110 
    111 
    112 
    113 
    114 
    115 
    116 
    117 
    118 
    119 
    120 
    121 
    122 
    123 #
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/install_egg_info.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/install_egg_info.py b/setuptools-0.6c16dev4.egg/setuptools/command/install_egg_info.py
    deleted file mode 100644
    index 939340c..0000000
    + -  
    1 from setuptools import Command
    2 from setuptools.archive_util import unpack_archive
    3 from distutils import log, dir_util
    4 import os, shutil, pkg_resources
    5 
    6 class install_egg_info(Command):
    7     """Install an .egg-info directory for the package"""
    8 
    9     description = "Install an .egg-info directory for the package"
    10 
    11     user_options = [
    12         ('install-dir=', 'd', "directory to install to"),
    13     ]
    14 
    15     def initialize_options(self):
    16         self.install_dir = None
    17 
    18     def finalize_options(self):
    19         self.set_undefined_options('install_lib',('install_dir','install_dir'))
    20         ei_cmd = self.get_finalized_command("egg_info")
    21         basename = pkg_resources.Distribution(
    22             None, None, ei_cmd.egg_name, ei_cmd.egg_version
    23         ).egg_name()+'.egg-info'
    24         self.source = ei_cmd.egg_info
    25         self.target = os.path.join(self.install_dir, basename)
    26         self.outputs = [self.target]
    27 
    28     def run(self):
    29         self.run_command('egg_info')
    30         target = self.target
    31         if os.path.isdir(self.target) and not os.path.islink(self.target):
    32             dir_util.remove_tree(self.target, dry_run=self.dry_run)
    33         elif os.path.exists(self.target):
    34             self.execute(os.unlink,(self.target,),"Removing "+self.target)
    35         if not self.dry_run:
    36             pkg_resources.ensure_directory(self.target)
    37         self.execute(self.copytree, (),
    38             "Copying %s to %s" % (self.source, self.target)
    39         )
    40         self.install_namespaces()
    41 
    42     def get_outputs(self):
    43         return self.outputs
    44 
    45     def copytree(self):
    46         # Copy the .egg-info tree to site-packages
    47         def skimmer(src,dst):
    48             # filter out source-control directories; note that 'src' is always
    49             # a '/'-separated path, regardless of platform.  'dst' is a
    50             # platform-specific path.
    51             for skip in '.svn/','CVS/':
    52                 if src.startswith(skip) or '/'+skip in src:
    53                     return None
    54             self.outputs.append(dst)
    55             log.debug("Copying %s to %s", src, dst)
    56             return dst
    57         unpack_archive(self.source, self.target, skimmer)
    58 
    59 
    60 
    61 
    62 
    63 
    64 
    65 
    66 
    67 
    68 
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    80 
    81 
    82 
    83     def install_namespaces(self):
    84         nsp = self._get_all_ns_packages()
    85         if not nsp: return
    86         filename,ext = os.path.splitext(self.target)
    87         filename += '-nspkg.pth'; self.outputs.append(filename)
    88         log.info("Installing %s",filename)
    89         if not self.dry_run:
    90             f = open(filename,'wb')
    91             for pkg in nsp:
    92                 pth = tuple(pkg.split('.'))
    93                 trailer = '\n'
    94                 if '.' in pkg:
    95                     trailer = (
    96                         "; m and setattr(sys.modules[%r], %r, m)\n"
    97                         % ('.'.join(pth[:-1]), pth[-1])
    98                     )
    99                 f.write(
    100                     "import sys,new,os; "
    101                     "p = os.path.join(sys._getframe(1).f_locals['sitedir'], "
    102                         "*%(pth)r); "
    103                     "ie = os.path.exists(os.path.join(p,'__init__.py')); "
    104                     "m = not ie and "
    105                         "sys.modules.setdefault(%(pkg)r,new.module(%(pkg)r)); "
    106                     "mp = (m or []) and m.__dict__.setdefault('__path__',[]); "
    107                     "(p not in mp) and mp.append(p)%(trailer)s"
    108                     % locals()
    109                 )
    110             f.close()
    111 
    112     def _get_all_ns_packages(self):
    113         nsp = {}
    114         for pkg in self.distribution.namespace_packages or []:
    115             pkg = pkg.split('.')
    116             while pkg:
    117                 nsp['.'.join(pkg)] = 1
    118                 pkg.pop()
    119         nsp=list(nsp)
    120         nsp.sort()  # set up shorter names first
    121         return nsp
    122 
    123 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/install_lib.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/install_lib.py b/setuptools-0.6c16dev4.egg/setuptools/command/install_lib.py
    deleted file mode 100644
    index 96c8dfe..0000000
    + -  
    1 from distutils.command.install_lib import install_lib as _install_lib
    2 import os
    3 
    4 class install_lib(_install_lib):
    5     """Don't add compiled flags to filenames of non-Python files"""
    6 
    7     def _bytecode_filenames (self, py_filenames):
    8         bytecode_files = []
    9         for py_file in py_filenames:
    10             if not py_file.endswith('.py'):
    11                 continue
    12             if self.compile:
    13                 bytecode_files.append(py_file + "c")
    14             if self.optimize > 0:
    15                 bytecode_files.append(py_file + "o")
    16 
    17         return bytecode_files
    18 
    19     def run(self):
    20         self.build()
    21         outfiles = self.install()
    22         if outfiles is not None:
    23             # always compile, in case we have any extension stubs to deal with
    24             self.byte_compile(outfiles)
    25 
    26     def get_exclusions(self):
    27         exclude = {}
    28         nsp = self.distribution.namespace_packages
    29 
    30         if (nsp and self.get_finalized_command('install')
    31                .single_version_externally_managed
    32         ):
    33             for pkg in nsp:
    34                 parts = pkg.split('.')
    35                 while parts:
    36                     pkgdir = os.path.join(self.install_dir, *parts)
    37                     for f in '__init__.py', '__init__.pyc', '__init__.pyo':
    38                         exclude[os.path.join(pkgdir,f)] = 1
    39                     parts.pop()
    40         return exclude
    41 
    42     def copy_tree(
    43         self, infile, outfile,
    44         preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1
    45     ):
    46         assert preserve_mode and preserve_times and not preserve_symlinks
    47         exclude = self.get_exclusions()
    48 
    49         if not exclude:
    50             return _install_lib.copy_tree(self, infile, outfile)
    51 
    52         # Exclude namespace package __init__.py* files from the output
    53 
    54         from setuptools.archive_util import unpack_directory
    55         from distutils import log
    56 
    57         outfiles = []
    58 
    59         def pf(src, dst):
    60             if dst in exclude:
    61                 log.warn("Skipping installation of %s (namespace package)",dst)
    62                 return False
    63 
    64             log.info("copying %s -> %s", src, os.path.dirname(dst))
    65             outfiles.append(dst)
    66             return dst
    67 
    68         unpack_directory(infile, outfile, pf)
    69         return outfiles
    70 
    71     def get_outputs(self):
    72         outputs = _install_lib.get_outputs(self)
    73         exclude = self.get_exclusions()
    74         if exclude:
    75             return [f for f in outputs if f not in exclude]
    76         return outputs
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/install_scripts.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/install_scripts.py b/setuptools-0.6c16dev4.egg/setuptools/command/install_scripts.py
    deleted file mode 100644
    index 79fa375..0000000
    + -  
    1 from distutils.command.install_scripts import install_scripts \
    2      as _install_scripts
    3 from easy_install import get_script_args, sys_executable, chmod
    4 from pkg_resources import Distribution, PathMetadata, ensure_directory
    5 import os
    6 from distutils import log
    7 
    8 class install_scripts(_install_scripts):
    9     """Do normal script install, plus any egg_info wrapper scripts"""
    10 
    11     def initialize_options(self):
    12         _install_scripts.initialize_options(self)
    13         self.no_ep = False
    14 
    15     def run(self):
    16         self.run_command("egg_info")
    17         if self.distribution.scripts:
    18             _install_scripts.run(self)  # run first to set up self.outfiles
    19         else:
    20             self.outfiles = []
    21         if self.no_ep:
    22             # don't install entry point scripts into .egg file!
    23             return
    24 
    25         ei_cmd = self.get_finalized_command("egg_info")
    26         dist = Distribution(
    27             ei_cmd.egg_base, PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info),
    28             ei_cmd.egg_name, ei_cmd.egg_version,
    29         )
    30         bs_cmd = self.get_finalized_command('build_scripts')
    31         executable = getattr(bs_cmd,'executable',sys_executable)
    32         is_wininst = getattr(
    33             self.get_finalized_command("bdist_wininst"), '_is_running', False
    34         )
    35         for args in get_script_args(dist, executable, is_wininst):
    36             self.write_script(*args)
    37 
    38 
    39 
    40 
    41 
    42     def write_script(self, script_name, contents, mode="t", *ignored):
    43         """Write an executable file to the scripts directory"""
    44         log.info("Installing %s script to %s", script_name, self.install_dir)
    45         target = os.path.join(self.install_dir, script_name)
    46         self.outfiles.append(target)
    47 
    48         if not self.dry_run:
    49             ensure_directory(target)
    50             f = open(target,"w"+mode)
    51             f.write(contents)
    52             f.close()
    53             chmod(target,0755)
    54 
    55 
    56 
    57 
    58 
    59 
    60 
    61 
    62 
    63 
    64 
    65 
    66 
    67 
    68 
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    80 
    81 
    82 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/register.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/register.py b/setuptools-0.6c16dev4.egg/setuptools/command/register.py
    deleted file mode 100644
    index 3b2e085..0000000
    + -  
    1 from distutils.command.register import register as _register
    2 
    3 class register(_register):
    4     __doc__ = _register.__doc__
    5 
    6     def run(self):
    7         # Make sure that we are using valid current name/version info
    8         self.run_command('egg_info')
    9         _register.run(self)
    10 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/rotate.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/rotate.py b/setuptools-0.6c16dev4.egg/setuptools/command/rotate.py
    deleted file mode 100644
    index 8aab312..0000000
    + -  
    1 import distutils, os
    2 from setuptools import Command
    3 from distutils.util import convert_path
    4 from distutils import log
    5 from distutils.errors import *
    6 
    7 class rotate(Command):
    8     """Delete older distributions"""
    9 
    10     description = "delete older distributions, keeping N newest files"
    11     user_options = [
    12         ('match=',    'm', "patterns to match (required)"),
    13         ('dist-dir=', 'd', "directory where the distributions are"),
    14         ('keep=',     'k', "number of matching distributions to keep"),
    15     ]
    16 
    17     boolean_options = []
    18 
    19     def initialize_options(self):
    20         self.match = None
    21         self.dist_dir = None
    22         self.keep = None
    23 
    24     def finalize_options(self):
    25         if self.match is None:
    26             raise DistutilsOptionError(
    27                 "Must specify one or more (comma-separated) match patterns "
    28                 "(e.g. '.zip' or '.egg')"
    29             )
    30         if self.keep is None:
    31             raise DistutilsOptionError("Must specify number of files to keep")
    32         try:
    33             self.keep = int(self.keep)
    34         except ValueError:
    35             raise DistutilsOptionError("--keep must be an integer")
    36         if isinstance(self.match, basestring):
    37             self.match = [
    38                 convert_path(p.strip()) for p in self.match.split(',')
    39             ]
    40         self.set_undefined_options('bdist',('dist_dir', 'dist_dir'))
    41 
    42     def run(self):
    43         self.run_command("egg_info")
    44         from glob import glob
    45         for pattern in self.match:
    46             pattern = self.distribution.get_name()+'*'+pattern
    47             files = glob(os.path.join(self.dist_dir,pattern))
    48             files = [(os.path.getmtime(f),f) for f in files]
    49             files.sort()
    50             files.reverse()
    51 
    52             log.info("%d file(s) matching %s", len(files), pattern)
    53             files = files[self.keep:]
    54             for (t,f) in files:
    55                 log.info("Deleting %s", f)
    56                 if not self.dry_run:
    57                     os.unlink(f)
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/saveopts.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/saveopts.py b/setuptools-0.6c16dev4.egg/setuptools/command/saveopts.py
    deleted file mode 100644
    index 9c58d72..0000000
    + -  
    1 import distutils, os
    2 from setuptools import Command
    3 from setuptools.command.setopt import edit_config, option_base
    4 
    5 class saveopts(option_base):
    6     """Save command-line options to a file"""
    7 
    8     description = "save supplied options to setup.cfg or other config file"
    9 
    10     def run(self):
    11         dist = self.distribution
    12         commands = dist.command_options.keys()
    13         settings = {}
    14 
    15         for cmd in commands:
    16 
    17             if cmd=='saveopts':
    18                 continue    # don't save our own options!
    19 
    20             for opt,(src,val) in dist.get_option_dict(cmd).items():
    21                 if src=="command line":
    22                     settings.setdefault(cmd,{})[opt] = val
    23 
    24         edit_config(self.filename, settings, self.dry_run)
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/scriptsetup.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/scriptsetup.py b/setuptools-0.6c16dev4.egg/setuptools/command/scriptsetup.py
    deleted file mode 100644
    index db68c07..0000000
    + -  
    1 from distutils.errors import DistutilsSetupError
    2 from setuptools import Command
    3 import sys
    4 
    5 class scriptsetup(Command):
    6     action = (sys.platform == "win32"
    7                    and "set up .pyscript association and PATHEXT variable to run scripts"
    8                    or  "this does nothing on non-Windows platforms")
    9 
    10     user_options = [
    11         ('allusers', 'a',
    12          'make changes for all users of this Windows installation (requires Administrator privileges)'),
    13     ]
    14     boolean_options = ['allusers']
    15 
    16     def initialize_options(self):
    17         self.allusers = False
    18 
    19     def finalize_options(self):
    20         pass
    21 
    22     def run(self):
    23         if sys.platform != "win32":
    24             print "\n'scriptsetup' isn't needed on non-Windows platforms."
    25         else:
    26             do_scriptsetup(self.allusers)
    27 
    28 
    29 def do_scriptsetup(allusers=False):
    30     print "\nSetting up environment to run scripts for %s..." % (allusers and "all users" or "the current user")
    31 
    32     from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, \
    33         REG_SZ, REG_EXPAND_SZ, KEY_QUERY_VALUE, KEY_SET_VALUE, \
    34         OpenKey, CreateKey, QueryValueEx, SetValueEx, FlushKey, CloseKey
    35 
    36     USER_ENV = "Environment"
    37     try:
    38         user_env = OpenKey(HKEY_CURRENT_USER, USER_ENV, 0, KEY_QUERY_VALUE)
    39     except WindowsError, e:
    40         raise DistutilsSetupError("I could not read the user environment from the registry.\n%r" % (e,))
    41 
    42     SYSTEM_ENV = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
    43     try:
    44         system_env = OpenKey(HKEY_LOCAL_MACHINE, SYSTEM_ENV, 0, KEY_QUERY_VALUE)
    45     except WindowsError, e:
    46         raise DistutilsSetupError("I could not read the system environment from the registry.\n%r" % (e,))
    47 
    48 
    49     # HKEY_CLASSES_ROOT is a merged view that would only confuse us.
    50     # <http://technet.microsoft.com/en-us/library/cc739822(WS.10).aspx>
    51 
    52     USER_CLASSES = "SOFTWARE\\Classes"
    53     try:
    54         user_classes = OpenKey(HKEY_CURRENT_USER, USER_CLASSES, 0, KEY_QUERY_VALUE)
    55     except WindowsError, e:
    56         raise DistutilsSetupError("I could not read the user filetype associations from the registry.\n%r" % (e,))
    57 
    58     SYSTEM_CLASSES = "SOFTWARE\\Classes"
    59     try:
    60         system_classes = OpenKey(HKEY_LOCAL_MACHINE, SYSTEM_CLASSES, 0, KEY_QUERY_VALUE)
    61     except WindowsError, e:
    62         raise DistutilsSetupError("I could not read the system filetype associations from the registry.\n%r" % (e,))
    63 
    64 
    65     def query(key, subkey, what):
    66         try:
    67             (value, type) = QueryValueEx(key, subkey)
    68         except WindowsError, e:
    69             if e.winerror == 2:  # not found
    70                 return None
    71             raise DistutilsSetupError("I could not read %s from the registry.\n%r" % (what, e))
    72 
    73         # It does not matter that we don't expand environment strings, in fact it's better not to.
    74 
    75         if type != REG_SZ and type != REG_EXPAND_SZ:
    76             raise DistutilsSetupError("I expected the registry entry for %s to have a string type (REG_SZ or REG_EXPAND_SZ), "
    77                                       "and was flummoxed by it having type code %r." % (what, type))
    78         return (value, type)
    79 
    80 
    81     def open_and_query(key, path, subkey, what):
    82         try:
    83             read_key = OpenKey(key, path, 0, KEY_QUERY_VALUE)
    84         except WindowsError, e:
    85             if e.winerror == 2:  # not found
    86                 return None
    87             raise DistutilsSetupError("I could not read %s from the registry because I could not open "
    88                                       "the parent key.\n%r" % (what, e))
    89 
    90         try:
    91             return query(read_key, subkey, what)
    92         finally:
    93             CloseKey(read_key)
    94 
    95 
    96     def update(key_name_path, subkey, desired_value, desired_type, goal, what):
    97         (key, name, path) = key_name_path
    98 
    99         (old_value, old_type) = open_and_query(key, path, subkey, what) or (None, None)
    100         if (old_value, old_type) == (desired_value, desired_type):
    101             print "Already done: %s." % (goal,)
    102             return False
    103 
    104         try:
    105             update_key = OpenKey(key, path, 0, KEY_SET_VALUE|KEY_QUERY_VALUE)
    106         except WindowsError, e:
    107             if e.winerror != 2:
    108                 raise DistutilsSetupError("I tried to %s, but was not successful because I could not open "
    109                                           "the registry key %s\\%s for writing.\n%r"
    110                                           % (goal, name, path, e))
    111             try:
    112                 update_key = CreateKey(key, path)
    113             except WindowsError, e:
    114                 raise DistutilsSetupError("I tried to %s, but was not successful because the registry key %s\\%s "
    115                                           "did not exist, and I was unable to create it.\n%r"
    116                                           % (goal, name, path, e))
    117 
    118         (new_value, new_type) = (None, None)
    119         try:
    120             SetValueEx(update_key, subkey, 0, desired_type, desired_value)
    121         except WindowsError, e:
    122             raise DistutilsSetupError("I tried to %s, but was not able to set the subkey %r under %s\\%s to be %r.\n%r"
    123                                       % (goal, subkey, name, path, desired_value))
    124         else:
    125             (new_value, new_type) = query(update_key, subkey, what) or (None, None)
    126         finally:
    127             FlushKey(update_key)
    128             CloseKey(update_key)
    129 
    130         if (new_value, new_type) != (desired_value, desired_type):
    131             raise DistutilsSetupError("I tried to %s by setting the subkey %r under %s\\%s to be %r, "
    132                                       "and the call to SetValueEx succeeded, but the value ended up as "
    133                                       "%r instead (it was previously %r). Maybe the update was unexpectedly virtualized?"
    134                                       % (goal, subkey, name, path, desired_value, new_value, old_value))
    135 
    136         print "Done: %s." % (goal,)
    137         return True
    138 
    139 
    140     # Maintenance hazard: 'add_to_environment' and 'associate' use very similar, but not identical logic.
    141 
    142     def add_to_environment(varname, addition, change_allusers):
    143         changed = False
    144         what = "the %s environment variable %s" % (change_allusers and "system" or "user", varname)
    145         goal = "add %s to %s" % (addition, what)
    146 
    147         system_valueandtype = query(system_env, varname, "the system environment variable %s" % (varname,))
    148         user_valueandtype   = query(user_env,   varname, "the user environment variable %s" % (varname,))
    149 
    150         if change_allusers:
    151             (value, type) = system_valueandtype or (u'', REG_SZ)
    152             key_name_path = (HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE", SYSTEM_ENV)
    153         else:
    154             (value, type) = user_valueandtype or system_valueandtype or (u'', REG_SZ)
    155             key_name_path = (HKEY_CURRENT_USER, "HKEY_CURRENT_USER", USER_ENV)
    156 
    157         if addition.lower() in value.lower().split(u';'):
    158             print "Already done: %s." % (goal,)
    159         else:
    160             changed |= update(key_name_path, varname, value + u';' + addition, type, goal, what)
    161 
    162         if change_allusers:
    163             # Also change any overriding environment entry for the current user.
    164             (user_value, user_type) = user_valueandtype or (u'', REG_SZ)
    165             split_value = user_value.lower().split(u';')
    166 
    167             if not (addition.lower() in split_value or u'%'+varname.lower()+u'%' in split_value):
    168                 now_what = "the overriding user environment variable %s" % (varname,)
    169                 changed |= update((HKEY_CURRENT_USER, "HKEY_CURRENT_USER", USER_ENV),
    170                                   varname, user_value + u';' + addition, user_type,
    171                                   "add %s to %s" % (addition, now_what), now_what)
    172 
    173         return changed
    174 
    175 
    176     def associate(ext, target, change_allusers):
    177         changed = False
    178         what = "the %s association for %s" % (change_allusers and "system" or "user", ext)
    179         goal = "associate the filetype %s with %s for %s" % (ext, target, change_allusers and "all users" or "the current user")
    180 
    181         try:
    182             if change_allusers:
    183                 target_key = OpenKey(HKEY_LOCAL_MACHINE, "%s\\%s" % (SYSTEM_CLASSES, target), 0, KEY_QUERY_VALUE)
    184             else:
    185                 target_key = OpenKey(HKEY_CLASSES_ROOT, target, 0, KEY_QUERY_VALUE)
    186         except WindowsError, e:
    187             raise DistutilsSetupError("I was going to %s, but that won't work because the %s class does not exist in the registry, "
    188                                       "as far as I can tell.\n%r" % (goal, target, e))
    189         CloseKey(target_key)
    190 
    191         system_key_name_path = (HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE", "%s\\%s" % (SYSTEM_CLASSES, ext))
    192         user_key_name_path   = (HKEY_CURRENT_USER,  "HKEY_CURRENT_USER",  "%s\\%s" % (USER_CLASSES,   ext))
    193 
    194         system_valueandtype = open_and_query(system_classes, ext, "", "the system association for %s" % (ext,))
    195         user_valueandtype   = open_and_query(user_classes,   ext, "", "the user association for %s" % (ext,))
    196 
    197         if change_allusers:
    198             (value, type) = system_valueandtype or (u'', REG_SZ)
    199             key_name_path = system_key_name_path
    200         else:
    201             (value, type) = user_valueandtype or system_valueandtype or (u'', REG_SZ)
    202             key_name_path = user_key_name_path
    203 
    204         if value == target:
    205             print "Already done: %s." % (goal,)
    206         else:
    207             changed |= update(key_name_path, "", unicode(target), REG_SZ, goal, what)
    208 
    209         if change_allusers:
    210             # Also change any overriding association for the current user.
    211             (user_value, user_type) = user_valueandtype or (u'', REG_SZ)
    212 
    213             if user_value != target:
    214                 changed |= update(user_key_name_path, "", unicode(target), REG_SZ,
    215                                   "associate the filetype %s with %s for the current user " \
    216                                       "(because the system association is overridden)" % (ext, target),
    217                                   "the overriding user association for %s" % (ext,))
    218 
    219         return changed
    220 
    221 
    222     def broadcast_settingchange(change_allusers):
    223         print "Broadcasting that the environment has changed, please wait..."
    224 
    225         # <http://support.microsoft.com/kb/104011/en-us>
    226         # <http://msdn.microsoft.com/en-us/library/ms644952(VS.85).aspx>
    227         # LRESULT WINAPI SendMessageTimeoutW(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam,
    228         #                                    UINT fuFlags, UINT uTimeout, PDWORD_PTR lpdwResult);
    229 
    230         try:
    231             from ctypes import WINFUNCTYPE, POINTER, windll, addressof, c_wchar_p
    232             from ctypes.wintypes import LONG, HWND, UINT, WPARAM, LPARAM, DWORD
    233 
    234             SendMessageTimeout = WINFUNCTYPE(POINTER(LONG), HWND, UINT, WPARAM, LPARAM, UINT, UINT, POINTER(POINTER(DWORD))) \
    235                                      (("SendMessageTimeoutW", windll.user32))
    236             HWND_BROADCAST   = 0xFFFF
    237             WM_SETTINGCHANGE = 0x001A
    238             SMTO_ABORTIFHUNG = 0x0002
    239             SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, change_allusers and 1 or 0,
    240                                addressof(c_wchar_p(u"Environment")), SMTO_ABORTIFHUNG, 5000, None);
    241         except Exception, e:
    242             print "Warning: %r" % (e,)
    243 
    244 
    245     changed_assoc = associate(".pyscript", "Python.File", allusers)
    246 
    247     changed_env = False
    248     try:
    249         changed_env |= add_to_environment("PATHEXT", ".pyscript", allusers)
    250         changed_env |= add_to_environment("PATHEXT", ".pyw",      allusers)
    251     finally:
    252         CloseKey(user_env)
    253         CloseKey(system_env)
    254 
    255     if changed_assoc or changed_env:
    256         broadcast_settingchange(allusers)
    257 
    258     if changed_env:
    259         # whether logout is needed seems to randomly differ between installations
    260         # of XP, but it is not needed in Vista or later.
    261         try:
    262             import platform, re
    263             need_logout = not re.search(r'^[6-9]|([1-9][0-9]+)\.', platform.version())
    264         except Exception, e:
    265             e  # hush pyflakes
    266             need_logout = True
    267 
    268         if need_logout:
    269             print """
    270 ***********************************************************************
    271 Changes have been made to the persistent environment, but they may not
    272 take effect in this Windows session. Running installed Python scripts
    273 from a Command Prompt may only work after you have logged out and back
    274 in again, or rebooted.
    275 ***********************************************************************
    276 """
    277         else:
    278             print """
    279 ***********************************************************************
    280 Changes have been made to the persistent environment, but not in this
    281 Command Prompt. Running installed Python scripts will only work from
    282 new Command Prompts opened from now on.
    283 ***********************************************************************
    284 """
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/sdist.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/sdist.py b/setuptools-0.6c16dev4.egg/setuptools/command/sdist.py
    deleted file mode 100644
    index d84afdb..0000000
    + -  
    1 from distutils.command.sdist import sdist as _sdist
    2 from distutils.util import convert_path
    3 from distutils import log
    4 from glob import glob
    5 import os, re, sys, pkg_resources
    6 
    7 entities = [
    8     ("&lt;","<"), ("&gt;", ">"), ("&quot;", '"'), ("&apos;", "'"),
    9     ("&amp;", "&")
    10 ]
    11 
    12 def unescape(data):
    13     for old,new in entities:
    14         data = data.replace(old,new)
    15     return data
    16 
    17 def re_finder(pattern, postproc=None):
    18     def find(dirname, filename):
    19         f = open(filename,'rU')
    20         data = f.read()
    21         f.close()
    22         for match in pattern.finditer(data):
    23             path = match.group(1)
    24             if postproc:
    25                 path = postproc(path)
    26             yield joinpath(dirname,path)
    27     return find
    28 
    29 def joinpath(prefix,suffix):
    30     if not prefix:
    31         return suffix
    32     return os.path.join(prefix,suffix)
    33 
    34 
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    42 def walk_revctrl(dirname=''):
    43     """Find all files under revision control"""
    44     for ep in pkg_resources.iter_entry_points('setuptools.file_finders'):
    45         for item in ep.load()(dirname):
    46             yield item
    47 
    48 def _default_revctrl(dirname=''):
    49     for path, finder in finders:
    50         path = joinpath(dirname,path)
    51         if os.path.isfile(path):
    52             for path in finder(dirname,path):
    53                 if os.path.isfile(path):
    54                     yield path
    55                 elif os.path.isdir(path):
    56                     for item in _default_revctrl(path):
    57                         yield item
    58 
    59 def externals_finder(dirname, filename):
    60     """Find any 'svn:externals' directories"""
    61     found = False
    62     f = open(filename,'rb')
    63     for line in iter(f.readline, ''):    # can't use direct iter!
    64         parts = line.split()
    65         if len(parts)==2:
    66             kind,length = parts
    67             data = f.read(int(length))
    68             if kind=='K' and data=='svn:externals':
    69                 found = True
    70             elif kind=='V' and found:
    71                 f.close()
    72                 break
    73     else:
    74         f.close()
    75         return
    76 
    77     for line in data.splitlines():
    78         parts = line.split()
    79         if parts:
    80             yield joinpath(dirname, parts[0])
    81 
    82 
    83 entries_pattern = re.compile(r'name="([^"]+)"(?![^>]+deleted="true")', re.I)
    84 
    85 def entries_finder(dirname, filename):
    86     f = open(filename,'rU')
    87     data = f.read()
    88     f.close()
    89     if data.startswith('<?xml'):
    90         for match in entries_pattern.finditer(data):
    91             yield joinpath(dirname,unescape(match.group(1)))
    92     else:
    93         svnver=-1
    94         try: svnver = int(data.splitlines()[0])
    95         except: pass
    96         if svnver<8:
    97             log.warn("unrecognized .svn/entries format in %s", dirname)
    98             return           
    99         for record in map(str.splitlines, data.split('\n\x0c\n')[1:]):
    100             if not record or len(record)>=6 and record[5]=="delete":
    101                 continue    # skip deleted
    102             yield joinpath(dirname, record[0])
    103        
    104 
    105 finders = [
    106     (convert_path('CVS/Entries'),
    107         re_finder(re.compile(r"^\w?/([^/]+)/", re.M))),
    108     (convert_path('.svn/entries'), entries_finder),
    109     (convert_path('.svn/dir-props'), externals_finder),
    110     (convert_path('.svn/dir-prop-base'), externals_finder),  # svn 1.4
    111 ]
    112 
    113 
    114 
    115 
    116 
    117 
    118 
    119 
    120 
    121 
    122 
    123 
    124 class sdist(_sdist):
    125     """Smart sdist that finds anything supported by revision control"""
    126 
    127     user_options = [
    128         ('formats=', None,
    129          "formats for source distribution (comma-separated list)"),
    130         ('keep-temp', 'k',
    131          "keep the distribution tree around after creating " +
    132          "archive file(s)"),
    133         ('dist-dir=', 'd',
    134          "directory to put the source distribution archive(s) in "
    135          "[default: dist]"),
    136         ]
    137 
    138     negative_opt = {}
    139 
    140     def run(self):
    141         self.run_command('egg_info')
    142         ei_cmd = self.get_finalized_command('egg_info')
    143         self.filelist = ei_cmd.filelist
    144         self.filelist.append(os.path.join(ei_cmd.egg_info,'SOURCES.txt'))
    145         self.check_readme()
    146         self.check_metadata()
    147         self.make_distribution()
    148 
    149         dist_files = getattr(self.distribution,'dist_files',[])
    150         for file in self.archive_files:
    151             data = ('sdist', '', file)
    152             if data not in dist_files:
    153                 dist_files.append(data)
    154 
    155     def read_template(self):
    156         try:
    157             _sdist.read_template(self)
    158         except:
    159             # grody hack to close the template file (MANIFEST.in)
    160             # this prevents easy_install's attempt at deleting the file from
    161             # dying and thus masking the real error
    162             sys.exc_info()[2].tb_next.tb_frame.f_locals['template'].close()
    163             raise
    164 
    165     # Cribbed from old distutils code, to work around new distutils code
    166     # that tries to do some of the same stuff as we do, in a way that makes
    167     # us loop.
    168    
    169     def add_defaults (self):
    170         standards = [('README', 'README.txt'), self.distribution.script_name]
    171 
    172         for fn in standards:
    173             if type(fn) is tuple:
    174                 alts = fn
    175                 got_it = 0
    176                 for fn in alts:
    177                     if os.path.exists(fn):
    178                         got_it = 1
    179                         self.filelist.append(fn)
    180                         break
    181 
    182                 if not got_it:
    183                     self.warn("standard file not found: should have one of " +
    184                               ', '.join(alts))
    185             else:
    186                 if os.path.exists(fn):
    187                     self.filelist.append(fn)
    188                 else:
    189                     self.warn("standard file '%s' not found" % fn)
    190 
    191         optional = ['test/test*.py', 'setup.cfg']
    192        
    193         for pattern in optional:
    194             files = filter(os.path.isfile, glob(pattern))
    195             if files:
    196                 self.filelist.extend(files)
    197 
    198         if self.distribution.has_pure_modules():
    199             build_py = self.get_finalized_command('build_py')
    200             self.filelist.extend(build_py.get_source_files())
    201 
    202         if self.distribution.has_ext_modules():
    203             build_ext = self.get_finalized_command('build_ext')
    204             self.filelist.extend(build_ext.get_source_files())
    205 
    206         if self.distribution.has_c_libraries():
    207             build_clib = self.get_finalized_command('build_clib')
    208             self.filelist.extend(build_clib.get_source_files())
    209 
    210         if self.distribution.has_scripts():
    211             build_scripts = self.get_finalized_command('build_scripts')
    212             self.filelist.extend(build_scripts.get_source_files())
    213 
    214 
    215     def check_readme(self):
    216         alts = ("README", "README.txt")
    217         for f in alts:
    218             if os.path.exists(f):
    219                 return
    220         else:
    221             self.warn(
    222                 "standard file not found: should have one of " +', '.join(alts)
    223             )
    224 
    225 
    226     def make_release_tree(self, base_dir, files):
    227         _sdist.make_release_tree(self, base_dir, files)
    228 
    229         # Save any egg_info command line options used to create this sdist
    230         dest = os.path.join(base_dir, 'setup.cfg')
    231         if hasattr(os,'link') and os.path.exists(dest):
    232             # unlink and re-copy, since it might be hard-linked, and
    233             # we don't want to change the source version
    234             os.unlink(dest)
    235             self.copy_file('setup.cfg', dest)
    236 
    237         self.get_finalized_command('egg_info').save_version_info(dest)
    238 
    239 
    240 
    241 
    242 
    243 
    244 
    245 
    246 #
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/setopt.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/setopt.py b/setuptools-0.6c16dev4.egg/setuptools/command/setopt.py
    deleted file mode 100644
    index e0c1058..0000000
    + -  
    1 import distutils, os
    2 from setuptools import Command
    3 from distutils.util import convert_path
    4 from distutils import log
    5 from distutils.errors import *
    6 
    7 __all__ = ['config_file', 'edit_config', 'option_base', 'setopt']
    8 
    9 
    10 def config_file(kind="local"):
    11     """Get the filename of the distutils, local, global, or per-user config
    12 
    13     `kind` must be one of "local", "global", or "user"
    14     """
    15     if kind=='local':
    16         return 'setup.cfg'
    17     if kind=='global':
    18         return os.path.join(
    19             os.path.dirname(distutils.__file__),'distutils.cfg'
    20         )
    21     if kind=='user':
    22         dot = os.name=='posix' and '.' or ''
    23         return os.path.expanduser(convert_path("~/%spydistutils.cfg" % dot))
    24     raise ValueError(
    25         "config_file() type must be 'local', 'global', or 'user'", kind
    26     )
    27 
    28 
    29 
    30 
    31 
    32 
    33 
    34 
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    42 def edit_config(filename, settings, dry_run=False):
    43     """Edit a configuration file to include `settings`
    44 
    45     `settings` is a dictionary of dictionaries or ``None`` values, keyed by
    46     command/section name.  A ``None`` value means to delete the entire section,
    47     while a dictionary lists settings to be changed or deleted in that section.
    48     A setting of ``None`` means to delete that setting.
    49     """
    50     from ConfigParser import RawConfigParser
    51     log.debug("Reading configuration from %s", filename)
    52     opts = RawConfigParser()
    53     opts.read([filename])
    54     for section, options in settings.items():
    55         if options is None:
    56             log.info("Deleting section [%s] from %s", section, filename)
    57             opts.remove_section(section)
    58         else:
    59             if not opts.has_section(section):
    60                 log.debug("Adding new section [%s] to %s", section, filename)
    61                 opts.add_section(section)
    62             for option,value in options.items():
    63                 if value is None:
    64                     log.debug("Deleting %s.%s from %s",
    65                         section, option, filename
    66                     )
    67                     opts.remove_option(section,option)
    68                     if not opts.options(section):
    69                         log.info("Deleting empty [%s] section from %s",
    70                                   section, filename)
    71                         opts.remove_section(section)
    72                 else:
    73                     log.debug(
    74                         "Setting %s.%s to %r in %s",
    75                         section, option, value, filename
    76                     )
    77                     opts.set(section,option,value)
    78 
    79     log.info("Writing %s", filename)
    80     if not dry_run:
    81         f = open(filename,'w'); opts.write(f); f.close()
    82 
    83 class option_base(Command):
    84     """Abstract base class for commands that mess with config files"""
    85 
    86     user_options = [
    87         ('global-config', 'g',
    88                  "save options to the site-wide distutils.cfg file"),
    89         ('user-config', 'u',
    90                  "save options to the current user's pydistutils.cfg file"),
    91         ('filename=', 'f',
    92                  "configuration file to use (default=setup.cfg)"),
    93     ]
    94 
    95     boolean_options = [
    96         'global-config', 'user-config',
    97     ]
    98 
    99     def initialize_options(self):
    100         self.global_config = None
    101         self.user_config   = None
    102         self.filename = None
    103 
    104     def finalize_options(self):
    105         filenames = []
    106         if self.global_config:
    107             filenames.append(config_file('global'))
    108         if self.user_config:
    109             filenames.append(config_file('user'))
    110         if self.filename is not None:
    111             filenames.append(self.filename)
    112         if not filenames:
    113             filenames.append(config_file('local'))
    114         if len(filenames)>1:
    115             raise DistutilsOptionError(
    116                 "Must specify only one configuration file option",
    117                 filenames
    118             )
    119         self.filename, = filenames
    120 
    121 
    122 
    123 
    124 class setopt(option_base):
    125     """Save command-line options to a file"""
    126 
    127     description = "set an option in setup.cfg or another config file"
    128 
    129     user_options = [
    130         ('command=', 'c', 'command to set an option for'),
    131         ('option=',  'o',  'option to set'),
    132         ('set-value=',   's', 'value of the option'),
    133         ('remove',   'r', 'remove (unset) the value'),
    134     ] + option_base.user_options
    135 
    136     boolean_options = option_base.boolean_options + ['remove']
    137 
    138     def initialize_options(self):
    139         option_base.initialize_options(self)
    140         self.command = None
    141         self.option = None
    142         self.set_value = None
    143         self.remove = None
    144 
    145     def finalize_options(self):
    146         option_base.finalize_options(self)
    147         if self.command is None or self.option is None:
    148             raise DistutilsOptionError("Must specify --command *and* --option")
    149         if self.set_value is None and not self.remove:
    150             raise DistutilsOptionError("Must specify --set-value or --remove")
    151 
    152     def run(self):
    153         edit_config(
    154             self.filename, {
    155                 self.command: {self.option.replace('-','_'):self.set_value}
    156             },
    157             self.dry_run
    158         )
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/test.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/test.py b/setuptools-0.6c16dev4.egg/setuptools/command/test.py
    deleted file mode 100644
    index df5add5..0000000
    + -  
    1 from setuptools import Command
    2 from distutils.errors import DistutilsOptionError
    3 import sys
    4 from pkg_resources import *
    5 from unittest import TestLoader, main
    6 
    7 class ScanningLoader(TestLoader):
    8 
    9     def loadTestsFromModule(self, module):
    10         """Return a suite of all tests cases contained in the given module
    11 
    12         If the module is a package, load tests from all the modules in it.
    13         If the module has an ``additional_tests`` function, call it and add
    14         the return value to the tests.
    15         """
    16         tests = []
    17         if module.__name__!='setuptools.tests.doctest':  # ugh
    18             tests.append(TestLoader.loadTestsFromModule(self,module))
    19 
    20         if hasattr(module, "additional_tests"):
    21             tests.append(module.additional_tests())
    22 
    23         if hasattr(module, '__path__'):
    24             for file in resource_listdir(module.__name__, ''):
    25                 if file.endswith('.py') and file!='__init__.py':
    26                     submodule = module.__name__+'.'+file[:-3]
    27                 else:
    28                     if resource_exists(
    29                         module.__name__, file+'/__init__.py'
    30                     ):
    31                         submodule = module.__name__+'.'+file
    32                     else:
    33                         continue
    34                 tests.append(self.loadTestsFromName(submodule))
    35 
    36         if len(tests)!=1:
    37             return self.suiteClass(tests)
    38         else:
    39             return tests[0] # don't create a nested suite for only one return
    40 
    41 
    42 class test(Command):
    43     """Command to run unit tests after in-place build"""
    44 
    45     description = "run unit tests after in-place build"
    46 
    47     user_options = [
    48         ('test-module=','m', "Run 'test_suite' in specified module"),
    49         ('test-suite=','s',
    50             "Test suite to run (e.g. 'some_module.test_suite')"),
    51         ('test-runner=','r', "Test runner to use"),
    52     ]
    53 
    54     def initialize_options(self):
    55         self.test_runner = None
    56         self.test_suite = None
    57         self.test_module = None
    58         self.test_loader = None
    59 
    60     def finalize_options(self):
    61         if self.test_suite is None:
    62             if self.test_module is None:
    63                 self.test_suite = self.distribution.test_suite
    64             else:
    65                 self.test_suite = self.test_module+".test_suite"
    66         elif self.test_module:
    67             raise DistutilsOptionError(
    68                 "You may specify a module or a suite, but not both"
    69             )
    70 
    71         self.test_args = [self.test_suite]
    72 
    73         if self.verbose:
    74             self.test_args.insert(0,'--verbose')
    75         if self.test_loader is None:
    76             self.test_loader = getattr(self.distribution,'test_loader',None)
    77         if self.test_loader is None:
    78             self.test_loader = "setuptools.command.test:ScanningLoader"
    79         if self.test_runner is None:
    80             self.test_runner = getattr(self.distribution,'test_runner',None)
    81 
    82 
    83     def with_project_on_sys_path(self, func):
    84         # Ensure metadata is up-to-date
    85         self.run_command('egg_info')
    86 
    87         # Build extensions in-place
    88         self.reinitialize_command('build_ext', inplace=1)
    89         self.run_command('build_ext')
    90 
    91         ei_cmd = self.get_finalized_command("egg_info")
    92 
    93         old_path = sys.path[:]
    94         old_modules = sys.modules.copy()
    95 
    96         try:
    97             sys.path.insert(0, normalize_path(ei_cmd.egg_base))
    98             working_set.__init__()
    99             add_activation_listener(lambda dist: dist.activate())
    100             require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version))
    101             func()
    102         finally:
    103             sys.path[:] = old_path
    104             sys.modules.clear()
    105             sys.modules.update(old_modules)
    106             working_set.__init__()
    107 
    108 
    109     def run(self):
    110         if self.distribution.install_requires:
    111             self.distribution.fetch_build_eggs(self.distribution.install_requires)
    112         if self.distribution.tests_require:
    113             self.distribution.fetch_build_eggs(self.distribution.tests_require)
    114 
    115         if self.test_suite:
    116             cmd = ' '.join(self.test_args)
    117             if self.dry_run:
    118                 self.announce('skipping "unittest %s" (dry run)' % cmd)
    119             else:
    120                 self.announce('running "unittest %s"' % cmd)
    121                 self.with_project_on_sys_path(self.run_tests)
    122 
    123 
    124     def run_tests(self):
    125         import unittest
    126         loader_ep = EntryPoint.parse("x="+self.test_loader)
    127         loader_class = loader_ep.load(require=False)
    128         kw = {}
    129         if self.test_runner is not None:
    130             runner_ep = EntryPoint.parse("x="+self.test_runner)
    131             runner_class = runner_ep.load(require=False)
    132             kw['testRunner'] = runner_class()
    133         unittest.main(
    134             None, None, [unittest.__file__]+self.test_args,
    135             testLoader = loader_class(), **kw
    136         )
    137 
    138 
    139 
    140 
    141 
    142 
    143 
    144 
    145 
    146 
    147 
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
    156 
    157 
    158 
    159 
    160 
    161 
    162 
    163 
    164 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/command/upload.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/command/upload.py b/setuptools-0.6c16dev4.egg/setuptools/command/upload.py
    deleted file mode 100644
    index 7ac08c2..0000000
    + -  
    1 """distutils.command.upload
    2 
    3 Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
    4 
    5 from distutils.errors import *
    6 from distutils.core import Command
    7 from distutils.spawn import spawn
    8 from distutils import log
    9 try:
    10     from hashlib import md5
    11 except ImportError:
    12     from md5 import md5
    13 import os
    14 import socket
    15 import platform
    16 import ConfigParser
    17 import httplib
    18 import base64
    19 import urlparse
    20 import cStringIO as StringIO
    21 
    22 class upload(Command):
    23 
    24     description = "upload binary package to PyPI"
    25 
    26     DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi'
    27 
    28     user_options = [
    29         ('repository=', 'r',
    30          "url of repository [default: %s]" % DEFAULT_REPOSITORY),
    31         ('show-response', None,
    32          'display full response text from server'),
    33         ('sign', 's',
    34          'sign files to upload using gpg'),
    35         ('identity=', 'i', 'GPG identity used to sign files'),
    36         ]
    37     boolean_options = ['show-response', 'sign']
    38 
    39     def initialize_options(self):
    40         self.username = ''
    41         self.password = ''
    42         self.repository = ''
    43         self.show_response = 0
    44         self.sign = False
    45         self.identity = None
    46 
    47     def finalize_options(self):
    48         if self.identity and not self.sign:
    49             raise DistutilsOptionError(
    50                 "Must use --sign for --identity to have meaning"
    51             )
    52         if os.environ.has_key('HOME'):
    53             rc = os.path.join(os.environ['HOME'], '.pypirc')
    54             if os.path.exists(rc):
    55                 self.announce('Using PyPI login from %s' % rc)
    56                 config = ConfigParser.ConfigParser({
    57                         'username':'',
    58                         'password':'',
    59                         'repository':''})
    60                 config.read(rc)
    61                 if not self.repository:
    62                     self.repository = config.get('server-login', 'repository')
    63                 if not self.username:
    64                     self.username = config.get('server-login', 'username')
    65                 if not self.password:
    66                     self.password = config.get('server-login', 'password')
    67         if not self.repository:
    68             self.repository = self.DEFAULT_REPOSITORY
    69 
    70     def run(self):
    71         if not self.distribution.dist_files:
    72             raise DistutilsOptionError("No dist file created in earlier command")
    73         for command, pyversion, filename in self.distribution.dist_files:
    74             self.upload_file(command, pyversion, filename)
    75 
    76     def upload_file(self, command, pyversion, filename):
    77         # Sign if requested
    78         if self.sign:
    79             gpg_args = ["gpg", "--detach-sign", "-a", filename]
    80             if self.identity:
    81                 gpg_args[2:2] = ["--local-user", self.identity]
    82             spawn(gpg_args,
    83                   dry_run=self.dry_run)
    84 
    85         # Fill in the data
    86         content = open(filename,'rb').read()
    87         basename = os.path.basename(filename)
    88         comment = ''
    89         if command=='bdist_egg' and self.distribution.has_ext_modules():
    90             comment = "built on %s" % platform.platform(terse=1)
    91         data = {
    92             ':action':'file_upload',
    93             'protcol_version':'1',
    94             'name':self.distribution.get_name(),
    95             'version':self.distribution.get_version(),
    96             'content':(basename,content),
    97             'filetype':command,
    98             'pyversion':pyversion,
    99             'md5_digest':md5(content).hexdigest(),
    100             }
    101         if command == 'bdist_rpm':
    102             dist, version, id = platform.dist()
    103             if dist:
    104                 comment = 'built for %s %s' % (dist, version)
    105         elif command == 'bdist_dumb':
    106             comment = 'built for %s' % platform.platform(terse=1)
    107         data['comment'] = comment
    108 
    109         if self.sign:
    110             data['gpg_signature'] = (os.path.basename(filename) + ".asc",
    111                                      open(filename+".asc").read())
    112 
    113         # set up the authentication
    114         auth = "Basic " + base64.encodestring(self.username + ":" + self.password).strip()
    115 
    116         # Build up the MIME payload for the POST data
    117         boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
    118         sep_boundary = '\n--' + boundary
    119         end_boundary = sep_boundary + '--'
    120         body = StringIO.StringIO()
    121         for key, value in data.items():
    122             # handle multiple entries for the same name
    123             if type(value) != type([]):
    124                 value = [value]
    125             for value in value:
    126                 if type(value) is tuple:
    127                     fn = ';filename="%s"' % value[0]
    128                     value = value[1]
    129                 else:
    130                     fn = ""
    131                 value = str(value)
    132                 body.write(sep_boundary)
    133                 body.write('\nContent-Disposition: form-data; name="%s"'%key)
    134                 body.write(fn)
    135                 body.write("\n\n")
    136                 body.write(value)
    137                 if value and value[-1] == '\r':
    138                     body.write('\n')  # write an extra newline (lurve Macs)
    139         body.write(end_boundary)
    140         body.write("\n")
    141         body = body.getvalue()
    142 
    143         self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
    144 
    145         # build the Request
    146         # We can't use urllib2 since we need to send the Basic
    147         # auth right with the first request
    148         schema, netloc, url, params, query, fragments = \
    149             urlparse.urlparse(self.repository)
    150         assert not params and not query and not fragments
    151         if schema == 'http':
    152             http = httplib.HTTPConnection(netloc)
    153         elif schema == 'https':
    154             http = httplib.HTTPSConnection(netloc)
    155         else:
    156             raise AssertionError, "unsupported schema "+schema
    157 
    158         data = ''
    159         loglevel = log.INFO
    160         try:
    161             http.connect()
    162             http.putrequest("POST", url)
    163             http.putheader('Content-type',
    164                            'multipart/form-data; boundary=%s'%boundary)
    165             http.putheader('Content-length', str(len(body)))
    166             http.putheader('Authorization', auth)
    167             http.endheaders()
    168             http.send(body)
    169         except socket.error, e:
    170             self.announce(str(e), log.ERROR)
    171             return
    172 
    173         r = http.getresponse()
    174         if r.status == 200:
    175             self.announce('Server response (%s): %s' % (r.status, r.reason),
    176                           log.INFO)
    177         else:
    178             self.announce('Upload failed (%s): %s' % (r.status, r.reason),
    179                           log.ERROR)
    180         if self.show_response:
    181             print '-'*75, r.read(), '-'*75
  • deleted file setuptools-0.6c16dev4.egg/setuptools/depends.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/depends.py b/setuptools-0.6c16dev4.egg/setuptools/depends.py
    deleted file mode 100644
    index 5fdf2d7..0000000
    + -  
    1 from __future__ import generators
    2 import sys, imp, marshal
    3 from imp import PKG_DIRECTORY, PY_COMPILED, PY_SOURCE, PY_FROZEN
    4 from distutils.version import StrictVersion, LooseVersion
    5 
    6 __all__ = [
    7     'Require', 'find_module', 'get_module_constant', 'extract_constant'
    8 ]
    9 
    10 class Require:
    11     """A prerequisite to building or installing a distribution"""
    12 
    13     def __init__(self,name,requested_version,module,homepage='',
    14         attribute=None,format=None
    15     ):
    16 
    17         if format is None and requested_version is not None:
    18             format = StrictVersion
    19 
    20         if format is not None:
    21             requested_version = format(requested_version)
    22             if attribute is None:
    23                 attribute = '__version__'
    24 
    25         self.__dict__.update(locals())
    26         del self.self
    27 
    28 
    29     def full_name(self):
    30         """Return full package/distribution name, w/version"""
    31         if self.requested_version is not None:
    32             return '%s-%s' % (self.name,self.requested_version)
    33         return self.name
    34 
    35 
    36     def version_ok(self,version):
    37         """Is 'version' sufficiently up-to-date?"""
    38         return self.attribute is None or self.format is None or \
    39             str(version)!="unknown" and version >= self.requested_version
    40 
    41 
    42     def get_version(self, paths=None, default="unknown"):
    43 
    44         """Get version number of installed module, 'None', or 'default'
    45 
    46         Search 'paths' for module.  If not found, return 'None'.  If found,
    47         return the extracted version attribute, or 'default' if no version
    48         attribute was specified, or the value cannot be determined without
    49         importing the module.  The version is formatted according to the
    50         requirement's version format (if any), unless it is 'None' or the
    51         supplied 'default'.
    52         """
    53 
    54         if self.attribute is None:
    55             try:
    56                 f,p,i = find_module(self.module,paths)
    57                 if f: f.close()
    58                 return default
    59             except ImportError:
    60                 return None
    61 
    62         v = get_module_constant(self.module,self.attribute,default,paths)
    63 
    64         if v is not None and v is not default and self.format is not None:
    65             return self.format(v)
    66 
    67         return v
    68 
    69 
    70     def is_present(self,paths=None):
    71         """Return true if dependency is present on 'paths'"""
    72         return self.get_version(paths) is not None
    73 
    74 
    75     def is_current(self,paths=None):
    76         """Return true if dependency is present and up-to-date on 'paths'"""
    77         version = self.get_version(paths)
    78         if version is None:
    79             return False
    80         return self.version_ok(version)
    81 
    82 
    83 def _iter_code(code):
    84 
    85     """Yield '(op,arg)' pair for each operation in code object 'code'"""
    86 
    87     from array import array
    88     from dis import HAVE_ARGUMENT, EXTENDED_ARG
    89 
    90     bytes = array('b',code.co_code)
    91     eof = len(code.co_code)
    92 
    93     ptr = 0
    94     extended_arg = 0
    95 
    96     while ptr<eof:
    97 
    98         op = bytes[ptr]
    99 
    100         if op>=HAVE_ARGUMENT:
    101 
    102             arg = bytes[ptr+1] + bytes[ptr+2]*256 + extended_arg
    103             ptr += 3
    104 
    105             if op==EXTENDED_ARG:
    106                 extended_arg = arg * 65536L
    107                 continue
    108 
    109         else:
    110             arg = None
    111             ptr += 1
    112 
    113         yield op,arg
    114 
    115 
    116 
    117 
    118 
    119 
    120 
    121 
    122 
    123 
    124 def find_module(module, paths=None):
    125     """Just like 'imp.find_module()', but with package support"""
    126 
    127     parts = module.split('.')
    128 
    129     while parts:
    130         part = parts.pop(0)
    131         f, path, (suffix,mode,kind) = info = imp.find_module(part, paths)
    132 
    133         if kind==PKG_DIRECTORY:
    134             parts = parts or ['__init__']
    135             paths = [path]
    136 
    137         elif parts:
    138             raise ImportError("Can't find %r in %s" % (parts,module))
    139 
    140     return info
    141 
    142 
    143 
    144 
    145 
    146 
    147 
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
    156 
    157 
    158 
    159 
    160 
    161 
    162 
    163 
    164 
    165 def get_module_constant(module, symbol, default=-1, paths=None):
    166 
    167     """Find 'module' by searching 'paths', and extract 'symbol'
    168 
    169     Return 'None' if 'module' does not exist on 'paths', or it does not define
    170     'symbol'.  If the module defines 'symbol' as a constant, return the
    171     constant.  Otherwise, return 'default'."""
    172 
    173     try:
    174         f, path, (suffix,mode,kind) = find_module(module,paths)
    175     except ImportError:
    176         # Module doesn't exist
    177         return None
    178 
    179     try:
    180         if kind==PY_COMPILED:
    181             f.read(8)   # skip magic & date
    182             code = marshal.load(f)
    183         elif kind==PY_FROZEN:
    184             code = imp.get_frozen_object(module)
    185         elif kind==PY_SOURCE:
    186             code = compile(f.read(), path, 'exec')
    187         else:
    188             # Not something we can parse; we'll have to import it.  :(
    189             if module not in sys.modules:
    190                 imp.load_module(module,f,path,(suffix,mode,kind))
    191             return getattr(sys.modules[module],symbol,None)
    192 
    193     finally:
    194         if f:
    195             f.close()
    196 
    197     return extract_constant(code,symbol,default)
    198 
    199 
    200 
    201 
    202 
    203 
    204 
    205 
    206 def extract_constant(code,symbol,default=-1):
    207     """Extract the constant value of 'symbol' from 'code'
    208 
    209     If the name 'symbol' is bound to a constant value by the Python code
    210     object 'code', return that value.  If 'symbol' is bound to an expression,
    211     return 'default'.  Otherwise, return 'None'.
    212 
    213     Return value is based on the first assignment to 'symbol'.  'symbol' must
    214     be a global, or at least a non-"fast" local in the code block.  That is,
    215     only 'STORE_NAME' and 'STORE_GLOBAL' opcodes are checked, and 'symbol'
    216     must be present in 'code.co_names'.
    217     """
    218 
    219     if symbol not in code.co_names:
    220         # name's not there, can't possibly be an assigment
    221         return None
    222 
    223     name_idx = list(code.co_names).index(symbol)
    224 
    225     STORE_NAME = 90
    226     STORE_GLOBAL = 97
    227     LOAD_CONST = 100
    228 
    229     const = default
    230 
    231     for op, arg in _iter_code(code):
    232 
    233         if op==LOAD_CONST:
    234             const = code.co_consts[arg]
    235         elif arg==name_idx and (op==STORE_NAME or op==STORE_GLOBAL):
    236             return const
    237         else:
    238             const = default
    239            
    240 if sys.platform.startswith('java') or sys.platform == 'cli':
    241     # XXX it'd be better to test assertions about bytecode instead...
    242     del extract_constant, get_module_constant
    243     __all__.remove('extract_constant')
    244     __all__.remove('get_module_constant')
    245 
    246 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/dist.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/dist.py b/setuptools-0.6c16dev4.egg/setuptools/dist.py
    deleted file mode 100644
    index aff5b2a..0000000
    + -  
    1 __all__ = ['Distribution']
    2 
    3 from distutils.core import Distribution as _Distribution
    4 from setuptools.depends import Require
    5 from setuptools.command.install import install
    6 from setuptools.command.sdist import sdist
    7 from setuptools.command.install_lib import install_lib
    8 from distutils.errors import DistutilsOptionError, DistutilsPlatformError
    9 from distutils.errors import DistutilsSetupError
    10 import setuptools, pkg_resources, distutils.core, distutils.dist, distutils.cmd
    11 import os, distutils.log, re
    12 
    13 def _get_unpatched(cls):
    14     """Protect against re-patching the distutils if reloaded
    15 
    16     Also ensures that no other distutils extension monkeypatched the distutils
    17     first.
    18     """
    19     while cls.__module__.startswith('setuptools'):
    20         cls, = cls.__bases__
    21     if not cls.__module__.startswith('distutils'):
    22         raise AssertionError(
    23             "distutils has already been patched by %r" % cls
    24         )
    25     return cls
    26 
    27 _Distribution = _get_unpatched(_Distribution)
    28 
    29 sequence = tuple, list
    30 
    31 def check_importable(dist, attr, value):
    32     try:
    33         ep = pkg_resources.EntryPoint.parse('x='+value)
    34         assert not ep.extras
    35     except (TypeError,ValueError,AttributeError,AssertionError):
    36         raise DistutilsSetupError(
    37             "%r must be importable 'module:attrs' string (got %r)"
    38             % (attr,value)
    39         )
    40 
    41 
    42 def assert_string_list(dist, attr, value):
    43     """Verify that value is a string list or None"""
    44     try:
    45         assert ''.join(value)!=value
    46     except (TypeError,ValueError,AttributeError,AssertionError):
    47         raise DistutilsSetupError(
    48             "%r must be a list of strings (got %r)" % (attr,value)
    49         )
    50 
    51 def check_nsp(dist, attr, value):
    52     """Verify that namespace packages are valid"""
    53     assert_string_list(dist,attr,value)
    54     for nsp in value:
    55         if not dist.has_contents_for(nsp):
    56             raise DistutilsSetupError(
    57                 "Distribution contains no modules or packages for " +
    58                 "namespace package %r" % nsp
    59             )
    60         if '.' in nsp:
    61             parent = '.'.join(nsp.split('.')[:-1])
    62             if parent not in value:
    63                 distutils.log.warn(
    64                     "WARNING: %r is declared as a package namespace, but %r"
    65                     " is not: please correct this in setup.py", nsp, parent
    66                 )
    67 
    68 def check_extras(dist, attr, value):
    69     """Verify that extras_require mapping is valid"""
    70     try:
    71         for k,v in value.items():
    72             list(pkg_resources.parse_requirements(v))
    73     except (TypeError,ValueError,AttributeError):
    74         raise DistutilsSetupError(
    75             "'extras_require' must be a dictionary whose values are "
    76             "strings or lists of strings containing valid project/version "
    77             "requirement specifiers."
    78         )
    79 
    80 
    81 
    82 
    83 def assert_bool(dist, attr, value):
    84     """Verify that value is True, False, 0, or 1"""
    85     if bool(value) != value:
    86         raise DistutilsSetupError(
    87             "%r must be a boolean value (got %r)" % (attr,value)
    88         )
    89 def check_requirements(dist, attr, value):
    90     """Verify that install_requires is a valid requirements list"""
    91     try:
    92         list(pkg_resources.parse_requirements(value))
    93     except (TypeError,ValueError):
    94         raise DistutilsSetupError(
    95             "%r must be a string or list of strings "
    96             "containing valid project/version requirement specifiers" % (attr,)
    97         )
    98 def check_entry_points(dist, attr, value):
    99     """Verify that entry_points map is parseable"""
    100     try:
    101         pkg_resources.EntryPoint.parse_map(value)
    102     except ValueError, e:
    103         raise DistutilsSetupError(e)
    104 
    105 def check_test_suite(dist, attr, value):
    106     if not isinstance(value,basestring):
    107         raise DistutilsSetupError("test_suite must be a string")
    108 
    109 def check_package_data(dist, attr, value):
    110     """Verify that value is a dictionary of package names to glob lists"""
    111     if isinstance(value,dict):
    112         for k,v in value.items():
    113             if not isinstance(k,str): break
    114             try: iter(v)
    115             except TypeError:
    116                 break
    117         else:
    118             return
    119     raise DistutilsSetupError(
    120         attr+" must be a dictionary mapping package names to lists of "
    121         "wildcard patterns"
    122     )
    123 
    124 def check_packages(dist, attr, value):
    125     for pkgname in value:
    126         if not re.match(r'\w+(\.\w+)*', pkgname):
    127             distutils.log.warn(
    128                 "WARNING: %r not a valid package name; please use only"
    129                 ".-separated package names in setup.py", pkgname
    130             )
    131            
    132 
    133 
    134 
    135 
    136 
    137 
    138 
    139 
    140 
    141 
    142 
    143 
    144 
    145 
    146 
    147 
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
    156 
    157 
    158 
    159 
    160 
    161 
    162 
    163 
    164 
    165 class Distribution(_Distribution):
    166     """Distribution with support for features, tests, and package data
    167 
    168     This is an enhanced version of 'distutils.dist.Distribution' that
    169     effectively adds the following new optional keyword arguments to 'setup()':
    170 
    171      'install_requires' -- a string or sequence of strings specifying project
    172         versions that the distribution requires when installed, in the format
    173         used by 'pkg_resources.require()'.  They will be installed
    174         automatically when the package is installed.  If you wish to use
    175         packages that are not available in PyPI, or want to give your users an
    176         alternate download location, you can add a 'find_links' option to the
    177         '[easy_install]' section of your project's 'setup.cfg' file, and then
    178         setuptools will scan the listed web pages for links that satisfy the
    179         requirements.
    180 
    181      'extras_require' -- a dictionary mapping names of optional "extras" to the
    182         additional requirement(s) that using those extras incurs. For example,
    183         this::
    184 
    185             extras_require = dict(reST = ["docutils>=0.3", "reSTedit"])
    186 
    187         indicates that the distribution can optionally provide an extra
    188         capability called "reST", but it can only be used if docutils and
    189         reSTedit are installed.  If the user installs your package using
    190         EasyInstall and requests one of your extras, the corresponding
    191         additional requirements will be installed if needed.
    192 
    193      'features' -- a dictionary mapping option names to 'setuptools.Feature'
    194         objects.  Features are a portion of the distribution that can be
    195         included or excluded based on user options, inter-feature dependencies,
    196         and availability on the current system.  Excluded features are omitted
    197         from all setup commands, including source and binary distributions, so
    198         you can create multiple distributions from the same source tree.
    199         Feature names should be valid Python identifiers, except that they may
    200         contain the '-' (minus) sign.  Features can be included or excluded
    201         via the command line options '--with-X' and '--without-X', where 'X' is
    202         the name of the feature.  Whether a feature is included by default, and
    203         whether you are allowed to control this from the command line, is
    204         determined by the Feature object.  See the 'Feature' class for more
    205         information.
    206 
    207      'test_suite' -- the name of a test suite to run for the 'test' command.
    208         If the user runs 'python setup.py test', the package will be installed,
    209         and the named test suite will be run.  The format is the same as
    210         would be used on a 'unittest.py' command line.  That is, it is the
    211         dotted name of an object to import and call to generate a test suite.
    212 
    213      'package_data' -- a dictionary mapping package names to lists of filenames
    214         or globs to use to find data files contained in the named packages.
    215         If the dictionary has filenames or globs listed under '""' (the empty
    216         string), those names will be searched for in every package, in addition
    217         to any names for the specific package.  Data files found using these
    218         names/globs will be installed along with the package, in the same
    219         location as the package.  Note that globs are allowed to reference
    220         the contents of non-package subdirectories, as long as you use '/' as
    221         a path separator.  (Globs are automatically converted to
    222         platform-specific paths at runtime.)
    223 
    224     In addition to these new keywords, this class also has several new methods
    225     for manipulating the distribution's contents.  For example, the 'include()'
    226     and 'exclude()' methods can be thought of as in-place add and subtract
    227     commands that add or remove packages, modules, extensions, and so on from
    228     the distribution.  They are used by the feature subsystem to configure the
    229     distribution for the included and excluded features.
    230     """
    231 
    232     _patched_dist = None
    233 
    234     def patch_missing_pkg_info(self, attrs):
    235         # Fake up a replacement for the data that would normally come from
    236         # PKG-INFO, but which might not yet be built if this is a fresh
    237         # checkout.
    238         #
    239         if not attrs or 'name' not in attrs or 'version' not in attrs:
    240             return
    241         key = pkg_resources.safe_name(str(attrs['name'])).lower()
    242         dist = pkg_resources.working_set.by_key.get(key)
    243         if dist is not None and not dist.has_metadata('PKG-INFO'):
    244             dist._version = pkg_resources.safe_version(str(attrs['version']))
    245             self._patched_dist = dist
    246 
    247     def __init__ (self, attrs=None):
    248         have_package_data = hasattr(self, "package_data")
    249         if not have_package_data:
    250             self.package_data = {}
    251         self.require_features = []
    252         self.features = {}
    253         self.dist_files = []
    254         self.patch_missing_pkg_info(attrs)
    255         # Make sure we have any eggs needed to interpret 'attrs'
    256         if attrs is not None:
    257             self.dependency_links = attrs.pop('dependency_links', [])
    258             assert_string_list(self,'dependency_links',self.dependency_links)
    259         if attrs and 'setup_requires' in attrs:
    260             self.fetch_build_eggs(attrs.pop('setup_requires'))
    261         for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
    262             if not hasattr(self,ep.name):
    263                 setattr(self,ep.name,None)
    264         _Distribution.__init__(self,attrs)
    265         if isinstance(self.metadata.version, (int,long,float)):
    266             # Some people apparently take "version number" too literally :)
    267             self.metadata.version = str(self.metadata.version)
    268 
    269     def parse_command_line(self):
    270         """Process features after parsing command line options"""
    271         result = _Distribution.parse_command_line(self)
    272         if self.features:
    273             self._finalize_features()
    274         return result
    275 
    276     def _feature_attrname(self,name):
    277         """Convert feature name to corresponding option attribute name"""
    278         return 'with_'+name.replace('-','_')
    279 
    280     def fetch_build_eggs(self, requires):
    281         """Resolve pre-setup requirements"""
    282         from pkg_resources import working_set, parse_requirements
    283         for dist in working_set.resolve(
    284             parse_requirements(requires), installer=self.fetch_build_egg
    285         ):
    286             working_set.add(dist)
    287 
    288     def finalize_options(self):
    289         _Distribution.finalize_options(self)
    290         if self.features:
    291             self._set_global_opts_from_features()
    292 
    293         for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
    294             value = getattr(self,ep.name,None)
    295             if value is not None:
    296                 ep.require(installer=self.fetch_build_egg)
    297                 ep.load()(self, ep.name, value)
    298 
    299     def fetch_build_egg(self, req):
    300         """Fetch an egg needed for building"""
    301         try:
    302             cmd = self._egg_fetcher
    303         except AttributeError:
    304             from setuptools.command.easy_install import easy_install
    305             dist = self.__class__({'script_args':['easy_install']})
    306             dist.parse_config_files()
    307             opts = dist.get_option_dict('easy_install')
    308             keep = (
    309                 'find_links', 'site_dirs', 'index_url', 'optimize',
    310                 'site_dirs', 'allow_hosts'
    311             )
    312             for key in opts.keys():
    313                 if key not in keep:
    314                     del opts[key]   # don't use any other settings
    315             if self.dependency_links:
    316                 links = self.dependency_links[:]
    317                 if 'find_links' in opts:
    318                     links = opts['find_links'][1].split() + links
    319                 opts['find_links'] = ('setup', links)
    320             cmd = easy_install(
    321                 dist, args=["x"], install_dir=os.curdir, exclude_scripts=True,
    322                 always_copy=False, build_directory=None, editable=False,
    323                 upgrade=False, multi_version=True, no_report = True
    324             )
    325             cmd.ensure_finalized()
    326             self._egg_fetcher = cmd
    327         return cmd.easy_install(req)
    328 
    329     def _set_global_opts_from_features(self):
    330         """Add --with-X/--without-X options based on optional features"""
    331 
    332         go = []
    333         no = self.negative_opt.copy()
    334 
    335         for name,feature in self.features.items():
    336             self._set_feature(name,None)
    337             feature.validate(self)
    338 
    339             if feature.optional:
    340                 descr = feature.description
    341                 incdef = ' (default)'
    342                 excdef=''
    343                 if not feature.include_by_default():
    344                     excdef, incdef = incdef, excdef
    345 
    346                 go.append(('with-'+name, None, 'include '+descr+incdef))
    347                 go.append(('without-'+name, None, 'exclude '+descr+excdef))
    348                 no['without-'+name] = 'with-'+name
    349 
    350         self.global_options = self.feature_options = go + self.global_options
    351         self.negative_opt = self.feature_negopt = no
    352 
    353 
    354 
    355 
    356 
    357 
    358 
    359 
    360 
    361 
    362 
    363 
    364 
    365 
    366 
    367 
    368 
    369 
    370     def _finalize_features(self):
    371         """Add/remove features and resolve dependencies between them"""
    372 
    373         # First, flag all the enabled items (and thus their dependencies)
    374         for name,feature in self.features.items():
    375             enabled = self.feature_is_included(name)
    376             if enabled or (enabled is None and feature.include_by_default()):
    377                 feature.include_in(self)
    378                 self._set_feature(name,1)
    379 
    380         # Then disable the rest, so that off-by-default features don't
    381         # get flagged as errors when they're required by an enabled feature
    382         for name,feature in self.features.items():
    383             if not self.feature_is_included(name):
    384                 feature.exclude_from(self)
    385                 self._set_feature(name,0)
    386 
    387 
    388     def get_command_class(self, command):
    389         """Pluggable version of get_command_class()"""
    390         if command in self.cmdclass:
    391             return self.cmdclass[command]
    392 
    393         for ep in pkg_resources.iter_entry_points('distutils.commands',command):
    394             ep.require(installer=self.fetch_build_egg)
    395             self.cmdclass[command] = cmdclass = ep.load()
    396             return cmdclass
    397         else:
    398             return _Distribution.get_command_class(self, command)
    399 
    400     def print_commands(self):
    401         for ep in pkg_resources.iter_entry_points('distutils.commands'):
    402             if ep.name not in self.cmdclass:
    403                 try:
    404                     cmdclass = ep.load(False) # don't require extras, we're not running
    405                     self.cmdclass[ep.name] = cmdclass
    406                 except ImportError:
    407                     pass # see https://tahoe-lafs.org/trac/tahoe-lafs/ticket/1405
    408         return _Distribution.print_commands(self)
    409 
    410 
    411     def _set_feature(self,name,status):
    412         """Set feature's inclusion status"""
    413         setattr(self,self._feature_attrname(name),status)
    414 
    415     def feature_is_included(self,name):
    416         """Return 1 if feature is included, 0 if excluded, 'None' if unknown"""
    417         return getattr(self,self._feature_attrname(name))
    418 
    419     def include_feature(self,name):
    420         """Request inclusion of feature named 'name'"""
    421 
    422         if self.feature_is_included(name)==0:
    423             descr = self.features[name].description
    424             raise DistutilsOptionError(
    425                descr + " is required, but was excluded or is not available"
    426            )
    427         self.features[name].include_in(self)
    428         self._set_feature(name,1)
    429 
    430     def include(self,**attrs):
    431         """Add items to distribution that are named in keyword arguments
    432 
    433         For example, 'dist.exclude(py_modules=["x"])' would add 'x' to
    434         the distribution's 'py_modules' attribute, if it was not already
    435         there.
    436 
    437         Currently, this method only supports inclusion for attributes that are
    438         lists or tuples.  If you need to add support for adding to other
    439         attributes in this or a subclass, you can add an '_include_X' method,
    440         where 'X' is the name of the attribute.  The method will be called with
    441         the value passed to 'include()'.  So, 'dist.include(foo={"bar":"baz"})'
    442         will try to call 'dist._include_foo({"bar":"baz"})', which can then
    443         handle whatever special inclusion logic is needed.
    444         """
    445         for k,v in attrs.items():
    446             include = getattr(self, '_include_'+k, None)
    447             if include:
    448                 include(v)
    449             else:
    450                 self._include_misc(k,v)
    451 
    452     def exclude_package(self,package):
    453         """Remove packages, modules, and extensions in named package"""
    454 
    455         pfx = package+'.'
    456         if self.packages:
    457             self.packages = [
    458                 p for p in self.packages
    459                     if p!=package and not p.startswith(pfx)
    460             ]
    461 
    462         if self.py_modules:
    463             self.py_modules = [
    464                 p for p in self.py_modules
    465                     if p!=package and not p.startswith(pfx)
    466             ]
    467 
    468         if self.ext_modules:
    469             self.ext_modules = [
    470                 p for p in self.ext_modules
    471                     if p.name!=package and not p.name.startswith(pfx)
    472             ]
    473 
    474 
    475     def has_contents_for(self,package):
    476         """Return true if 'exclude_package(package)' would do something"""
    477 
    478         pfx = package+'.'
    479 
    480         for p in self.iter_distribution_names():
    481             if p==package or p.startswith(pfx):
    482                 return True
    483 
    484 
    485 
    486 
    487 
    488 
    489 
    490 
    491 
    492 
    493     def _exclude_misc(self,name,value):
    494         """Handle 'exclude()' for list/tuple attrs without a special handler"""
    495         if not isinstance(value,sequence):
    496             raise DistutilsSetupError(
    497                 "%s: setting must be a list or tuple (%r)" % (name, value)
    498             )
    499         try:
    500             old = getattr(self,name)
    501         except AttributeError:
    502             raise DistutilsSetupError(
    503                 "%s: No such distribution setting" % name
    504             )
    505         if old is not None and not isinstance(old,sequence):
    506             raise DistutilsSetupError(
    507                 name+": this setting cannot be changed via include/exclude"
    508             )
    509         elif old:
    510             setattr(self,name,[item for item in old if item not in value])
    511 
    512     def _include_misc(self,name,value):
    513         """Handle 'include()' for list/tuple attrs without a special handler"""
    514 
    515         if not isinstance(value,sequence):
    516             raise DistutilsSetupError(
    517                 "%s: setting must be a list (%r)" % (name, value)
    518             )
    519         try:
    520             old = getattr(self,name)
    521         except AttributeError:
    522             raise DistutilsSetupError(
    523                 "%s: No such distribution setting" % name
    524             )
    525         if old is None:
    526             setattr(self,name,value)
    527         elif not isinstance(old,sequence):
    528             raise DistutilsSetupError(
    529                 name+": this setting cannot be changed via include/exclude"
    530             )
    531         else:
    532             setattr(self,name,old+[item for item in value if item not in old])
    533 
    534     def exclude(self,**attrs):
    535         """Remove items from distribution that are named in keyword arguments
    536 
    537         For example, 'dist.exclude(py_modules=["x"])' would remove 'x' from
    538         the distribution's 'py_modules' attribute.  Excluding packages uses
    539         the 'exclude_package()' method, so all of the package's contained
    540         packages, modules, and extensions are also excluded.
    541 
    542         Currently, this method only supports exclusion from attributes that are
    543         lists or tuples.  If you need to add support for excluding from other
    544         attributes in this or a subclass, you can add an '_exclude_X' method,
    545         where 'X' is the name of the attribute.  The method will be called with
    546         the value passed to 'exclude()'.  So, 'dist.exclude(foo={"bar":"baz"})'
    547         will try to call 'dist._exclude_foo({"bar":"baz"})', which can then
    548         handle whatever special exclusion logic is needed.
    549         """
    550         for k,v in attrs.items():
    551             exclude = getattr(self, '_exclude_'+k, None)
    552             if exclude:
    553                 exclude(v)
    554             else:
    555                 self._exclude_misc(k,v)
    556 
    557     def _exclude_packages(self,packages):
    558         if not isinstance(packages,sequence):
    559             raise DistutilsSetupError(
    560                 "packages: setting must be a list or tuple (%r)" % (packages,)
    561             )
    562         map(self.exclude_package, packages)
    563 
    564 
    565 
    566 
    567 
    568 
    569 
    570 
    571 
    572 
    573 
    574 
    575     def _parse_command_opts(self, parser, args):
    576         # Remove --with-X/--without-X options when processing command args
    577         self.global_options = self.__class__.global_options
    578         self.negative_opt = self.__class__.negative_opt
    579 
    580         # First, expand any aliases
    581         command = args[0]
    582         aliases = self.get_option_dict('aliases')
    583         while command in aliases:
    584             src,alias = aliases[command]
    585             del aliases[command]    # ensure each alias can expand only once!
    586             import shlex
    587             args[:1] = shlex.split(alias,True)
    588             command = args[0]
    589 
    590         nargs = _Distribution._parse_command_opts(self, parser, args)
    591 
    592         # Handle commands that want to consume all remaining arguments
    593         cmd_class = self.get_command_class(command)
    594         if getattr(cmd_class,'command_consumes_arguments',None):
    595             self.get_option_dict(command)['args'] = ("command line", nargs)
    596             if nargs is not None:
    597                 return []
    598 
    599         return nargs
    600 
    601 
    602 
    603 
    604 
    605 
    606 
    607 
    608 
    609 
    610 
    611 
    612 
    613 
    614 
    615 
    616     def get_cmdline_options(self):
    617         """Return a '{cmd: {opt:val}}' map of all command-line options
    618 
    619         Option names are all long, but do not include the leading '--', and
    620         contain dashes rather than underscores.  If the option doesn't take
    621         an argument (e.g. '--quiet'), the 'val' is 'None'.
    622 
    623         Note that options provided by config files are intentionally excluded.
    624         """
    625 
    626         d = {}
    627 
    628         for cmd,opts in self.command_options.items():
    629 
    630             for opt,(src,val) in opts.items():
    631 
    632                 if src != "command line":
    633                     continue
    634 
    635                 opt = opt.replace('_','-')
    636 
    637                 if val==0:
    638                     cmdobj = self.get_command_obj(cmd)
    639                     neg_opt = self.negative_opt.copy()
    640                     neg_opt.update(getattr(cmdobj,'negative_opt',{}))
    641                     for neg,pos in neg_opt.items():
    642                         if pos==opt:
    643                             opt=neg
    644                             val=None
    645                             break
    646                     else:
    647                         raise AssertionError("Shouldn't be able to get here")
    648 
    649                 elif val==1:
    650                     val = None
    651 
    652                 d.setdefault(cmd,{})[opt] = val
    653 
    654         return d
    655 
    656 
    657     def iter_distribution_names(self):
    658         """Yield all packages, modules, and extension names in distribution"""
    659 
    660         for pkg in self.packages or ():
    661             yield pkg
    662 
    663         for module in self.py_modules or ():
    664             yield module
    665 
    666         for ext in self.ext_modules or ():
    667             if isinstance(ext,tuple):
    668                 name, buildinfo = ext
    669             else:
    670                 name = ext.name
    671             if name.endswith('module'):
    672                 name = name[:-6]
    673             yield name
    674 
    675 # Install it throughout the distutils
    676 for module in distutils.dist, distutils.core, distutils.cmd:
    677     module.Distribution = Distribution
    678 
    679 
    680 
    681 
    682 
    683 
    684 
    685 
    686 
    687 
    688 
    689 
    690 
    691 
    692 
    693 
    694 
    695 
    696 
    697 
    698 class Feature:
    699     """A subset of the distribution that can be excluded if unneeded/wanted
    700 
    701     Features are created using these keyword arguments:
    702 
    703       'description' -- a short, human readable description of the feature, to
    704          be used in error messages, and option help messages.
    705 
    706       'standard' -- if true, the feature is included by default if it is
    707          available on the current system.  Otherwise, the feature is only
    708          included if requested via a command line '--with-X' option, or if
    709          another included feature requires it.  The default setting is 'False'.
    710 
    711       'available' -- if true, the feature is available for installation on the
    712          current system.  The default setting is 'True'.
    713 
    714       'optional' -- if true, the feature's inclusion can be controlled from the
    715          command line, using the '--with-X' or '--without-X' options.  If
    716          false, the feature's inclusion status is determined automatically,
    717          based on 'availabile', 'standard', and whether any other feature
    718          requires it.  The default setting is 'True'.
    719 
    720       'require_features' -- a string or sequence of strings naming features
    721          that should also be included if this feature is included.  Defaults to
    722          empty list.  May also contain 'Require' objects that should be
    723          added/removed from the distribution.
    724 
    725       'remove' -- a string or list of strings naming packages to be removed
    726          from the distribution if this feature is *not* included.  If the
    727          feature *is* included, this argument is ignored.  This argument exists
    728          to support removing features that "crosscut" a distribution, such as
    729          defining a 'tests' feature that removes all the 'tests' subpackages
    730          provided by other features.  The default for this argument is an empty
    731          list.  (Note: the named package(s) or modules must exist in the base
    732          distribution when the 'setup()' function is initially called.)
    733 
    734       other keywords -- any other keyword arguments are saved, and passed to
    735          the distribution's 'include()' and 'exclude()' methods when the
    736          feature is included or excluded, respectively.  So, for example, you
    737          could pass 'packages=["a","b"]' to cause packages 'a' and 'b' to be
    738          added or removed from the distribution as appropriate.
    739 
    740     A feature must include at least one 'requires', 'remove', or other
    741     keyword argument.  Otherwise, it can't affect the distribution in any way.
    742     Note also that you can subclass 'Feature' to create your own specialized
    743     feature types that modify the distribution in other ways when included or
    744     excluded.  See the docstrings for the various methods here for more detail.
    745     Aside from the methods, the only feature attributes that distributions look
    746     at are 'description' and 'optional'.
    747     """
    748     def __init__(self, description, standard=False, available=True,
    749         optional=True, require_features=(), remove=(), **extras
    750     ):
    751 
    752         self.description = description
    753         self.standard = standard
    754         self.available = available
    755         self.optional = optional
    756         if isinstance(require_features,(str,Require)):
    757             require_features = require_features,
    758 
    759         self.require_features = [
    760             r for r in require_features if isinstance(r,str)
    761         ]
    762         er = [r for r in require_features if not isinstance(r,str)]
    763         if er: extras['require_features'] = er
    764 
    765         if isinstance(remove,str):
    766             remove = remove,
    767         self.remove = remove
    768         self.extras = extras
    769 
    770         if not remove and not require_features and not extras:
    771             raise DistutilsSetupError(
    772                 "Feature %s: must define 'require_features', 'remove', or at least one"
    773                 " of 'packages', 'py_modules', etc."
    774             )
    775 
    776     def include_by_default(self):
    777         """Should this feature be included by default?"""
    778         return self.available and self.standard
    779 
    780     def include_in(self,dist):
    781 
    782         """Ensure feature and its requirements are included in distribution
    783 
    784         You may override this in a subclass to perform additional operations on
    785         the distribution.  Note that this method may be called more than once
    786         per feature, and so should be idempotent.
    787 
    788         """
    789 
    790         if not self.available:
    791             raise DistutilsPlatformError(
    792                 self.description+" is required,"
    793                 "but is not available on this platform"
    794             )
    795 
    796         dist.include(**self.extras)
    797 
    798         for f in self.require_features:
    799             dist.include_feature(f)
    800 
    801 
    802 
    803     def exclude_from(self,dist):
    804 
    805         """Ensure feature is excluded from distribution
    806 
    807         You may override this in a subclass to perform additional operations on
    808         the distribution.  This method will be called at most once per
    809         feature, and only after all included features have been asked to
    810         include themselves.
    811         """
    812 
    813         dist.exclude(**self.extras)
    814 
    815         if self.remove:
    816             for item in self.remove:
    817                 dist.exclude_package(item)
    818 
    819 
    820 
    821     def validate(self,dist):
    822 
    823         """Verify that feature makes sense in context of distribution
    824 
    825         This method is called by the distribution just before it parses its
    826         command line.  It checks to ensure that the 'remove' attribute, if any,
    827         contains only valid package/module names that are present in the base
    828         distribution when 'setup()' is called.  You may override it in a
    829         subclass to perform any other required validation of the feature
    830         against a target distribution.
    831         """
    832 
    833         for item in self.remove:
    834             if not dist.has_contents_for(item):
    835                 raise DistutilsSetupError(
    836                     "%s wants to be able to remove %s, but the distribution"
    837                     " doesn't contain any packages or modules under %s"
    838                     % (self.description, item, item)
    839                 )
    840                
    841 
    842 
    843 
    844 
    845 
    846 
    847 
    848 
    849 
    850 
    851 
    852 
    853 
    854 
    855 
    856 
    857 
    858 
    859 
    860 
    861 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/extension.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/extension.py b/setuptools-0.6c16dev4.egg/setuptools/extension.py
    deleted file mode 100644
    index cfcf55b..0000000
    + -  
    1 from distutils.core import Extension as _Extension
    2 from dist import _get_unpatched
    3 _Extension = _get_unpatched(_Extension)
    4 
    5 try:
    6     from Pyrex.Distutils.build_ext import build_ext
    7 except ImportError:
    8     have_pyrex = False
    9 else:
    10     have_pyrex = True
    11 
    12 
    13 class Extension(_Extension):
    14     """Extension that uses '.c' files in place of '.pyx' files"""
    15 
    16     if not have_pyrex:
    17         # convert .pyx extensions to .c
    18         def __init__(self,*args,**kw):
    19             _Extension.__init__(self,*args,**kw)
    20             sources = []
    21             for s in self.sources:
    22                 if s.endswith('.pyx'):
    23                     sources.append(s[:-3]+'c')
    24                 else:
    25                     sources.append(s)
    26             self.sources = sources
    27 
    28 class Library(Extension):
    29     """Just like a regular Extension, but built as a library instead"""
    30 
    31 import sys, distutils.core, distutils.extension
    32 distutils.core.Extension = Extension
    33 distutils.extension.Extension = Extension
    34 if 'distutils.command.build_ext' in sys.modules:
    35     sys.modules['distutils.command.build_ext'].Extension = Extension
  • deleted file setuptools-0.6c16dev4.egg/setuptools/package_index.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/package_index.py b/setuptools-0.6c16dev4.egg/setuptools/package_index.py
    deleted file mode 100644
    index 3d82d93..0000000
    + -  
    1 """PyPI and direct package downloading"""
    2 import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO
    3 import httplib, urllib
    4 from pkg_resources import *
    5 from distutils import log
    6 from distutils.errors import DistutilsError
    7 try:
    8     from hashlib import md5
    9 except ImportError:
    10     from md5 import md5
    11 from fnmatch import translate
    12 EGG_FRAGMENT = re.compile(r'^egg=([-A-Za-z0-9_.]+)$')
    13 HREF = re.compile("""href\\s*=\\s*['"]?([^'"> ]+)""", re.I)
    14 # this is here to fix emacs' cruddy broken syntax highlighting
    15 PYPI_MD5 = re.compile(
    16     '<a href="([^"#]+)">([^<]+)</a>\n\s+\\(<a (?:title="MD5 hash"\n\s+)'
    17     'href="[^?]+\?:action=show_md5&amp;digest=([0-9a-f]{32})">md5</a>\\)'
    18 )
    19 URL_SCHEME = re.compile('([-+.a-z0-9]{2,}):',re.I).match
    20 EXTENSIONS = ".tar.gz .tar.bz2 .tar .zip .tgz".split()
    21 
    22 def is_local(url_or_fname):
    23     """ Return True if url_or_fname is a "file:" url or if it is a schemaless thing (which is presumably a filename). """
    24     mo = URL_SCHEME(url_or_fname)
    25     return not (mo and mo.group(1).lower()!='file')
    26 
    27 def url_or_fname_to_fname(url_or_fname):
    28     """ Assert that is_local(url_or_fname) then if it is a "file:" url, parse it and run url2pathname on it, else just return it. """
    29     assert is_local(url_or_fname)
    30 
    31     mo = URL_SCHEME(url_or_fname)
    32     if mo:
    33         return urllib2.url2pathname(urlparse.urlparse(url)[2])
    34     else:
    35         return url_or_fname
    36 
    37 __all__ = [
    38     'PackageIndex', 'distros_for_url', 'parse_bdist_wininst',
    39     'interpret_distro_name',
    40 ]
    41 
    42 def parse_bdist_wininst(name):
    43     """Return (base,pyversion) or (None,None) for possible .exe name"""
    44 
    45     lower = name.lower()
    46     base, py_ver = None, None
    47 
    48     if lower.endswith('.exe'):
    49         if lower.endswith('.win32.exe'):
    50             base = name[:-10]
    51         elif lower.startswith('.win32-py',-16):
    52             py_ver = name[-7:-4]
    53             base = name[:-16]
    54 
    55     return base,py_ver
    56 
    57 def egg_info_for_url(url):
    58     scheme, server, path, parameters, query, fragment = urlparse.urlparse(url)
    59     base = urllib2.unquote(path.split('/')[-1])
    60     if server=='sourceforge.net' and base=='download':    # XXX Yuck
    61         base = urllib2.unquote(path.split('/')[-2])
    62     if '#' in base: base, fragment = base.split('#',1)
    63     return base,fragment
    64 
    65 def distros_for_url(url, metadata=None):
    66     """Yield egg or source distribution objects that might be found at a URL"""
    67     base, fragment = egg_info_for_url(url)
    68     for dist in distros_for_location(url, base, metadata): yield dist
    69     if fragment:
    70         match = EGG_FRAGMENT.match(fragment)
    71         if match:
    72             for dist in interpret_distro_name(
    73                 url, match.group(1), metadata, precedence = CHECKOUT_DIST
    74             ):
    75                 yield dist
    76 
    77 def distros_for_location(location, basename, metadata=None):
    78     """Yield egg or source distribution objects based on basename"""
    79     if basename.endswith('.egg.zip'):
    80         basename = basename[:-4]    # strip the .zip
    81     if basename.endswith('.egg') and '-' in basename:
    82         # only one, unambiguous interpretation
    83         return [Distribution.from_location(location, basename, metadata)]
    84     if basename.endswith('.exe'):
    85         win_base, py_ver = parse_bdist_wininst(basename)
    86         if win_base is not None:
    87             return interpret_distro_name(
    88                 location, win_base, metadata, py_ver, BINARY_DIST, "win32"
    89             )
    90     # Try source distro extensions (.zip, .tgz, etc.)
    91     #
    92     for ext in EXTENSIONS:
    93         if basename.endswith(ext):
    94             basename = basename[:-len(ext)]
    95             return interpret_distro_name(location, basename, metadata)
    96     return []  # no extension matched
    97 
    98 def distros_for_filename(filename, metadata=None):
    99     """Yield possible egg or source distribution objects based on a filename"""
    100     return distros_for_location(
    101         normalize_path(filename), os.path.basename(filename), metadata
    102     )
    103 
    104 
    105 def interpret_distro_name(location, basename, metadata,
    106     py_version=None, precedence=SOURCE_DIST, platform=None
    107 ):
    108     """Generate alternative interpretations of a source distro name
    109 
    110     Note: if `location` is a filesystem filename, you should call
    111     ``pkg_resources.normalize_path()`` on it before passing it to this
    112     routine!
    113     """
    114     # Generate alternative interpretations of a source distro name
    115     # Because some packages are ambiguous as to name/versions split
    116     # e.g. "adns-python-1.1.0", "egenix-mx-commercial", etc.
    117     # So, we generate each possible interepretation (e.g. "adns, python-1.1.0"
    118     # "adns-python, 1.1.0", and "adns-python-1.1.0, no version").  In practice,
    119     # the spurious interpretations should be ignored, because in the event
    120     # there's also an "adns" package, the spurious "python-1.1.0" version will
    121     # compare lower than any numeric version number, and is therefore unlikely
    122     # to match a request for it.  It's still a potential problem, though, and
    123     # in the long run PyPI and the distutils should go for "safe" names and
    124     # versions in distribution archive names (sdist and bdist).
    125 
    126     parts = basename.split('-')
    127     if not py_version:
    128         for i,p in enumerate(parts[2:]):
    129             if len(p)==5 and p.startswith('py2.'):
    130                 return # It's a bdist_dumb, not an sdist -- bail out
    131 
    132     for p in range(1,len(parts)+1):
    133         yield Distribution(
    134             location, metadata, '-'.join(parts[:p]), '-'.join(parts[p:]),
    135             py_version=py_version, precedence = precedence,
    136             platform = platform
    137         )
    138 
    139 REL = re.compile("""<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>""", re.I)
    140 # this line is here to fix emacs' cruddy broken syntax highlighting
    141 
    142 def find_external_links(url, page):
    143     """Find rel="homepage" and rel="download" links in `page`, yielding URLs"""
    144 
    145     for match in REL.finditer(page):
    146         tag, rel = match.groups()
    147         rels = map(str.strip, rel.lower().split(','))
    148         if 'homepage' in rels or 'download' in rels:
    149             for match in HREF.finditer(tag):
    150                 yield urlparse.urljoin(url, htmldecode(match.group(1)))
    151 
    152     for tag in ("<th>Home Page", "<th>Download URL"):
    153         pos = page.find(tag)
    154         if pos!=-1:
    155             match = HREF.search(page,pos)
    156             if match:
    157                 yield urlparse.urljoin(url, htmldecode(match.group(1)))
    158 
    159 user_agent = "Python-urllib/%s setuptools/%s" % (
    160     urllib2.__version__, require('setuptools')[0].version
    161 )
    162 
    163 
    164 class PackageIndex(Environment):
    165     """A distribution index that scans web pages for download URLs"""
    166 
    167     def __init__(self, index_url="http://pypi.python.org/simple", hosts=('*',),
    168         *args, **kw
    169     ):
    170         Environment.__init__(self,*args,**kw)
    171         self.index_url = index_url + "/"[:not index_url.endswith('/')]
    172         self.scanned_urls = {}
    173         self.fetched_urls = {}
    174         self.package_pages = {}
    175         self.allows = re.compile('|'.join(map(translate,hosts))).match
    176         self.to_scan = []
    177 
    178 
    179 
    180     def process_url(self, url, retrieve=False):
    181         """Evaluate a URL as a possible download, and maybe retrieve it"""
    182         if url in self.scanned_urls and not retrieve:
    183             return
    184         self.scanned_urls[url] = True
    185         if not URL_SCHEME(url):
    186             self.process_filename(url)
    187             return
    188         else:
    189             dists = list(distros_for_url(url))
    190             if dists:
    191                 if not self.url_ok(url):
    192                     return
    193                 self.debug("Found link: %s", url)
    194 
    195         if dists or not retrieve or url in self.fetched_urls:
    196             map(self.add, dists)
    197             return  # don't need the actual page
    198 
    199         if not self.url_ok(url):
    200             self.fetched_urls[url] = True
    201             return
    202 
    203         self.info("Reading %s", url)
    204         self.fetched_urls[url] = True   # prevent multiple fetch attempts
    205         f = self.open_url(url, "Download error: %s -- Some packages may not be found!")
    206         if f is None: return
    207         self.fetched_urls[f.url] = True
    208         if 'html' not in f.headers.get('content-type', '').lower():
    209             f.close()   # not html, we can't process it
    210             return
    211 
    212         base = f.url     # handle redirects
    213         page = f.read()
    214         f.close()
    215         if url.startswith(self.index_url) and getattr(f,'code',None)!=404:
    216             page = self.process_index(url, page)
    217         for match in HREF.finditer(page):
    218             link = urlparse.urljoin(base, htmldecode(match.group(1)))
    219             self.process_url(link)
    220 
    221     def process_filename(self, fn, nested=False):
    222         # process filenames or directories
    223         if not os.path.exists(fn):
    224             self.warn("Not found: %s", fn)
    225             return
    226 
    227         if os.path.isdir(fn) and not nested:
    228             path = os.path.realpath(fn)
    229             for item in os.listdir(path):
    230                 self.process_filename(os.path.join(path,item), True)
    231 
    232         dists = distros_for_filename(fn)
    233         if dists:
    234             self.debug("Found: %s", fn)
    235             map(self.add, dists)
    236 
    237     def url_ok(self, url, fatal=False):
    238         s = URL_SCHEME(url)
    239         if (s and s.group(1).lower()=='file') or self.allows(urlparse.urlparse(url)[1]):
    240             return True
    241         msg = "\nLink to % s ***BLOCKED*** by --allow-hosts\n"
    242         if fatal:
    243             raise DistutilsError(msg % url)
    244         else:
    245             self.warn(msg, url)
    246 
    247     def scan_egg_links(self, search_path):
    248         for item in search_path:
    249             if os.path.isdir(item):
    250                 for entry in os.listdir(item):
    251                     if entry.endswith('.egg-link'):
    252                         self.scan_egg_link(item, entry)
    253 
    254     def scan_egg_link(self, path, entry):
    255         lines = filter(None, map(str.strip, file(os.path.join(path, entry))))
    256         if len(lines)==2:
    257             for dist in find_distributions(os.path.join(path, lines[0])):
    258                 dist.location = os.path.join(path, *lines)
    259                 dist.precedence = SOURCE_DIST
    260                 self.add(dist)
    261 
    262     def process_index(self,url,page):
    263         """Process the contents of a PyPI page"""
    264         def scan(link):
    265             # Process a URL to see if it's for a package page
    266             if link.startswith(self.index_url):
    267                 parts = map(
    268                     urllib2.unquote, link[len(self.index_url):].split('/')
    269                 )
    270                 if len(parts)==2 and '#' not in parts[1]:
    271                     # it's a package page, sanitize and index it
    272                     pkg = safe_name(parts[0])
    273                     ver = safe_version(parts[1])
    274                     self.package_pages.setdefault(pkg.lower(),{})[link] = True
    275                     return to_filename(pkg), to_filename(ver)
    276             return None, None
    277 
    278         # process an index page into the package-page index
    279         for match in HREF.finditer(page):
    280             scan( urlparse.urljoin(url, htmldecode(match.group(1))) )
    281 
    282         pkg, ver = scan(url)   # ensure this page is in the page index
    283         if pkg:
    284             # process individual package page
    285             for new_url in find_external_links(url, page):
    286                 # Process the found URL
    287                 base, frag = egg_info_for_url(new_url)
    288                 if base.endswith('.py') and not frag:
    289                     if ver:
    290                         new_url+='#egg=%s-%s' % (pkg,ver)
    291                     else:
    292                         self.need_version_info(url)
    293                 self.scan_url(new_url)
    294 
    295             return PYPI_MD5.sub(
    296                 lambda m: '<a href="%s#md5=%s">%s</a>' % m.group(1,3,2), page
    297             )
    298         else:
    299             return ""   # no sense double-scanning non-package pages
    300 
    301 
    302 
    303     def need_version_info(self, url):
    304         self.scan_all(
    305             "Page at %s links to .py file(s) without version info; an index "
    306             "scan is required.", url
    307         )
    308 
    309     def scan_all(self, msg=None, *args):
    310         if self.index_url not in self.fetched_urls:
    311             if msg: self.warn(msg,*args)
    312             self.info(
    313                 "Scanning index of all packages (this may take a while)"
    314             )
    315         self.scan_url(self.index_url)
    316 
    317     def find_packages(self, requirement):
    318         self.scan_url(self.index_url + requirement.unsafe_name+'/')
    319 
    320         if not self.package_pages.get(requirement.key):
    321             # Fall back to safe version of the name
    322             self.scan_url(self.index_url + requirement.project_name+'/')
    323 
    324         if not self.package_pages.get(requirement.key):
    325             # We couldn't find the target package, so search the index page too
    326             self.not_found_in_index(requirement)
    327 
    328         for url in list(self.package_pages.get(requirement.key,())):
    329             # scan each page that might be related to the desired package
    330             self.scan_url(url)
    331 
    332     def obtain(self, requirement, installer=None):
    333         self.prescan(); self.find_packages(requirement)
    334         for dist in self[requirement.key]:
    335             if dist in requirement:
    336                 return dist
    337             self.debug("%s does not match %s", requirement, dist)
    338         return super(PackageIndex, self).obtain(requirement,installer)
    339 
    340 
    341 
    342 
    343 
    344     def check_md5(self, cs, info, filename, tfp):
    345         if re.match('md5=[0-9a-f]{32}$', info):
    346             self.debug("Validating md5 checksum for %s", filename)
    347             if cs.hexdigest()!=info[4:]:
    348                 tfp.close()
    349                 os.unlink(filename)
    350                 raise DistutilsError(
    351                     "MD5 validation failed for "+os.path.basename(filename)+
    352                     "; possible download problem?"
    353                 )
    354 
    355     def add_find_links(self, urls):
    356         """Add `urls` to the list that will be prescanned for searches"""
    357         for url in urls:
    358             if (
    359                 self.to_scan is None        # if we have already "gone online"
    360                 or not URL_SCHEME(url)      # or it's a local file/directory
    361                 or url.startswith('file:')
    362                 or list(distros_for_url(url))   # or a direct package link
    363             ):
    364                 # then go ahead and process it now
    365                 self.scan_url(url)
    366             else:
    367                 # otherwise, defer retrieval till later
    368                 self.to_scan.append(url)
    369 
    370     def prescan(self):
    371         """Scan urls scheduled for prescanning (e.g. --find-links)"""
    372         if self.to_scan:
    373             map(self.scan_url, self.to_scan)
    374         self.to_scan = None     # from now on, go ahead and process immediately
    375 
    376     def not_found_in_index(self, requirement):
    377         if self[requirement.key]:   # we've seen at least one distro
    378             meth, msg = self.info, "Couldn't retrieve index page for %r"
    379         else:   # no distros seen for this name, might be misspelled
    380             meth, msg = (self.warn,
    381                 "Couldn't find index page for %r (maybe misspelled?)")
    382         meth(msg, requirement.unsafe_name)
    383         self.scan_all()
    384 
    385     def download(self, spec, tmpdir):
    386         """Locate and/or download `spec` to `tmpdir`, returning a local path
    387 
    388         `spec` may be a ``Requirement`` object, or a string containing a URL,
    389         an existing local filename, or a project/version requirement spec
    390         (i.e. the string form of a ``Requirement`` object).  If it is the URL
    391         of a .py file with an unambiguous ``#egg=name-version`` tag (i.e., one
    392         that escapes ``-`` as ``_`` throughout), a trivial ``setup.py`` is
    393         automatically created alongside the downloaded file.
    394 
    395         If `spec` is a ``Requirement`` object or a string containing a
    396         project/version requirement spec, this method returns the location of
    397         a matching distribution (possibly after downloading it to `tmpdir`).
    398         If `spec` is a locally existing file or directory name, it is simply
    399         returned unchanged.  If `spec` is a URL, it is downloaded to a subpath
    400         of `tmpdir`, and the local filename is returned.  Various errors may be
    401         raised if a problem occurs during downloading.
    402         """
    403         if not isinstance(spec,Requirement):
    404             scheme = URL_SCHEME(spec)
    405             if scheme:
    406                 # It's a url, download it to tmpdir
    407                 found = self._download_url(scheme.group(1), spec, tmpdir)
    408                 base, fragment = egg_info_for_url(spec)
    409                 if base.endswith('.py'):
    410                     found = self.gen_setup(found,fragment,tmpdir)
    411                 return found
    412             elif os.path.exists(spec):
    413                 # Existing file or directory, just return it
    414                 return spec
    415             else:
    416                 try:
    417                     spec = Requirement.parse(spec)
    418                 except ValueError:
    419                     raise DistutilsError(
    420                         "Not a URL, existing file, or requirement spec: %r" %
    421                         (spec,)
    422                     )
    423         return getattr(self.fetch_distribution(spec, tmpdir),'location',None)
    424 
    425 
    426     def fetch_distribution(self,
    427         requirement, tmpdir, force_scan=False, source=False, develop_ok=False,
    428         local_index=None,
    429     ):
    430         """Obtain a distribution suitable for fulfilling `requirement`
    431 
    432         `requirement` must be a ``pkg_resources.Requirement`` instance.
    433         If necessary, or if the `force_scan` flag is set, the requirement is
    434         searched for in the (online) package index as well as the locally
    435         installed packages.  If a distribution matching `requirement` is found,
    436         the returned distribution's ``location`` is the value you would have
    437         gotten from calling the ``download()`` method with the matching
    438         distribution's URL or filename.  If no matching distribution is found,
    439         ``None`` is returned.
    440 
    441         If the `source` flag is set, only source distributions and source
    442         checkout links will be considered.  Unless the `develop_ok` flag is
    443         set, development and system eggs (i.e., those using the ``.egg-info``
    444         format) will be ignored.
    445         """
    446         # process a Requirement
    447         self.info("Searching for %s", requirement)
    448         skipped = {}
    449         dist = None
    450 
    451         def find(env, req):
    452             # Find a matching distribution; may be called more than once
    453 
    454             # first try to find a local dist
    455             for allow_remote in (False, True):
    456                 # then try to find a platform-dependent dist
    457                 for allow_platform_independent in (False, True):
    458                     for dist in env[req.key]:
    459                         if dist.precedence==DEVELOP_DIST and not develop_ok:
    460                             if dist not in skipped:
    461                                 self.warn("Skipping development or system egg: %s",dist)
    462                                 skipped[dist] = 1
    463                             continue
    464 
    465                         if ((is_local(dist.location) or allow_remote) and
    466                             (dist in req) and
    467                             ((allow_platform_independent or dist.platform is not None) and
    468                              (dist.precedence<=SOURCE_DIST or not source))):
    469                             return dist
    470 
    471         if force_scan:
    472             self.prescan()
    473             self.find_packages(requirement)
    474             dist = find(self, requirement)
    475            
    476         if local_index is not None:
    477             dist = dist or find(local_index, requirement)
    478 
    479         if dist is None and self.to_scan is not None:
    480             self.prescan()
    481             dist = find(self, requirement)
    482 
    483         if dist is None and not force_scan:
    484             self.find_packages(requirement)
    485             dist = find(self, requirement)
    486 
    487         if dist is None:
    488             self.warn(
    489                 "No local packages or download links found for %s%s",
    490                 (source and "a source distribution of " or ""),
    491                 requirement,
    492             )
    493         else:
    494             self.info("Best match: %s", dist)
    495             return dist.clone(location=self.download(dist.location, tmpdir))
    496 
    497 
    498     def fetch(self, requirement, tmpdir, force_scan=False, source=False):
    499         """Obtain a file suitable for fulfilling `requirement`
    500 
    501         DEPRECATED; use the ``fetch_distribution()`` method now instead.  For
    502         backward compatibility, this routine is identical but returns the
    503         ``location`` of the downloaded distribution instead of a distribution
    504         object.
    505         """
    506         dist = self.fetch_distribution(requirement,tmpdir,force_scan,source)
    507         if dist is not None:
    508             return dist.location
    509         return None
    510 
    511 
    512     def gen_setup(self, filename, fragment, tmpdir):
    513         match = EGG_FRAGMENT.match(fragment)
    514         dists = match and [d for d in
    515             interpret_distro_name(filename, match.group(1), None) if d.version
    516         ] or []
    517 
    518         if len(dists)==1:   # unambiguous ``#egg`` fragment
    519             basename = os.path.basename(filename)
    520 
    521             # Make sure the file has been downloaded to the temp dir.
    522             if os.path.dirname(filename) != tmpdir:
    523                 dst = os.path.join(tmpdir, basename)
    524                 from setuptools.command.easy_install import samefile
    525                 if not samefile(filename, dst):
    526                     shutil.copy2(filename, dst)
    527                     filename=dst
    528 
    529             file = open(os.path.join(tmpdir, 'setup.py'), 'w')
    530             file.write(
    531                 "from setuptools import setup\n"
    532                 "setup(name=%r, version=%r, py_modules=[%r])\n"
    533                 % (
    534                     dists[0].project_name, dists[0].version,
    535                     os.path.splitext(basename)[0]
    536                 )
    537             )
    538             file.close()
    539             return filename
    540 
    541         elif match:
    542             raise DistutilsError(
    543                 "Can't unambiguously interpret project/version identifier %r; "
    544                 "any dashes in the name or version should be escaped using "
    545                 "underscores. %r" % (fragment,dists)
    546             )
    547         else:
    548             raise DistutilsError(
    549                 "Can't process plain .py files without an '#egg=name-version'"
    550                 " suffix to enable automatic setup script generation."
    551             )
    552 
    553     dl_blocksize = 8192
    554     def _download_to(self, url, filename):
    555         self.info("Downloading %s", url)
    556         # Download the file
    557         fp, tfp, info = None, None, None
    558         try:
    559             if '#' in url:
    560                 url, info = url.split('#', 1)
    561             fp = self.open_url(url)
    562             if isinstance(fp, urllib2.HTTPError):
    563                 raise DistutilsError(
    564                     "Can't download %s: %s %s" % (url, fp.code,fp.msg)
    565                 )
    566             cs = md5()
    567             headers = fp.info()
    568             blocknum = 0
    569             bs = self.dl_blocksize
    570             size = -1
    571             if "content-length" in headers:
    572                 size = int(headers["Content-Length"])
    573                 self.reporthook(url, filename, blocknum, bs, size)
    574             tfp = open(filename,'wb')
    575             while True:
    576                 block = fp.read(bs)
    577                 if block:
    578                     cs.update(block)
    579                     tfp.write(block)
    580                     blocknum += 1
    581                     self.reporthook(url, filename, blocknum, bs, size)
    582                 else:
    583                     break
    584             if info: self.check_md5(cs, info, filename, tfp)
    585             return headers
    586         finally:
    587             if fp: fp.close()
    588             if tfp: tfp.close()
    589 
    590     def reporthook(self, url, filename, blocknum, blksize, size):
    591         pass    # no-op
    592 
    593 
    594     def open_url(self, url, warning=None):
    595         if url.startswith('file:'): return local_open(url)
    596         try:
    597             return open_with_auth(url)
    598         except urllib2.HTTPError, v:
    599             return v
    600         except urllib2.URLError, v:
    601             reason = v.reason
    602         except httplib.HTTPException, v:
    603             reason = "%s: %s" % (v.__doc__ or v.__class__.__name__, v)
    604         if warning:
    605             self.warn(warning, reason)
    606         else:
    607             raise DistutilsError("Download error for %s: %s" % (url, reason))
    608 
    609     def _download_url(self, scheme, url, tmpdir):
    610         # Determine download filename
    611         #
    612         name, fragment = egg_info_for_url(url)
    613         if name:
    614             while '..' in name:
    615                 name = name.replace('..','.').replace('\\','_')
    616         else:
    617             name = "__downloaded__"    # default if URL has no path contents
    618 
    619         if name.endswith('.egg.zip'):
    620             name = name[:-4]    # strip the extra .zip before download
    621 
    622         filename = os.path.join(tmpdir,name)
    623 
    624         # Download the file
    625         #
    626         if scheme=='svn' or scheme.startswith('svn+'):
    627             return self._download_svn(url, filename)
    628         elif scheme=='file':
    629             return urllib2.url2pathname(urlparse.urlparse(url)[2])
    630         else:
    631             self.url_ok(url, True)   # raises error if not allowed
    632             return self._attempt_download(url, filename)
    633 
    634 
    635     def scan_url(self, url):
    636         self.process_url(url, True)
    637 
    638 
    639     def _attempt_download(self, url, filename):
    640         headers = self._download_to(url, filename)
    641         if 'html' in headers.get('content-type','').lower():
    642             return self._download_html(url, headers, filename)
    643         else:
    644             return filename
    645 
    646     def _download_html(self, url, headers, filename):
    647         file = open(filename)
    648         for line in file:
    649             if line.strip():
    650                 # Check for a subversion index page
    651                 if re.search(r'<title>([^- ]+ - )?Revision \d+:', line):
    652                     # it's a subversion index page:
    653                     file.close()
    654                     os.unlink(filename)
    655                     return self._download_svn(url, filename)
    656                 break   # not an index page
    657         file.close()
    658         os.unlink(filename)
    659         raise DistutilsError("Unexpected HTML page found at "+url)
    660 
    661     def _download_svn(self, url, filename):
    662         url = url.split('#',1)[0]   # remove any fragment for svn's sake
    663         self.info("Doing subversion checkout from %s to %s", url, filename)
    664         os.system("svn checkout -q %s %s" % (url, filename))
    665         return filename
    666 
    667     def debug(self, msg, *args):
    668         log.debug(msg, *args)
    669 
    670     def info(self, msg, *args):
    671         log.info(msg, *args)
    672 
    673     def warn(self, msg, *args):
    674         log.warn(msg, *args)
    675 
    676 # This pattern matches a character entity reference (a decimal numeric
    677 # references, a hexadecimal numeric reference, or a named reference).
    678 entity_sub = re.compile(r'&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?').sub
    679 
    680 def uchr(c):
    681     if not isinstance(c, int):
    682         return c
    683     if c>255: return unichr(c)
    684     return chr(c)
    685 
    686 def decode_entity(match):
    687     what = match.group(1)
    688     if what.startswith('#x'):
    689         what = int(what[2:], 16)
    690     elif what.startswith('#'):
    691         what = int(what[1:])
    692     else:
    693         from htmlentitydefs import name2codepoint
    694         what = name2codepoint.get(what, match.group(0))
    695     return uchr(what)
    696 
    697 def htmldecode(text):
    698     """Decode HTML entities in the given text."""
    699     return entity_sub(decode_entity, text)
    700 
    701 
    702 
    703 
    704 
    705 
    706 
    707 
    708 
    709 
    710 
    711 
    712 
    713 
    714 
    715 
    716 
    717 def open_with_auth(url):
    718     """Open a urllib2 request, handling HTTP authentication"""
    719 
    720     scheme, netloc, path, params, query, frag = urlparse.urlparse(url)
    721 
    722     if scheme in ('http', 'https'):
    723         auth, host = urllib.splituser(netloc)
    724     else:
    725         auth = None
    726 
    727     if auth:
    728         auth = "Basic " + urllib2.unquote(auth).encode('base64').strip()
    729         new_url = urlparse.urlunparse((scheme,host,path,params,query,frag))
    730         request = urllib2.Request(new_url)
    731         request.add_header("Authorization", auth)
    732     else:
    733         request = urllib2.Request(url)
    734 
    735     request.add_header('User-Agent', user_agent)
    736     fp = urllib2.urlopen(request)
    737 
    738     if auth:
    739         # Put authentication info back into request URL if same host,
    740         # so that links found on the page will work
    741         s2, h2, path2, param2, query2, frag2 = urlparse.urlparse(fp.url)
    742         if s2==scheme and h2==host:
    743             fp.url = urlparse.urlunparse((s2,netloc,path2,param2,query2,frag2))
    744 
    745     return fp
    746 
    747 
    748 
    749 
    750 
    751 
    752 
    753 
    754 
    755 
    756 
    757 
    758 def fix_sf_url(url):
    759     return url      # backward compatibility
    760 
    761 def local_open(url):
    762     """Read a local path, with special support for directories"""
    763     scheme, server, path, param, query, frag = urlparse.urlparse(url)
    764     filename = urllib2.url2pathname(path)
    765     if os.path.isfile(filename):
    766         return urllib2.urlopen(url)
    767     elif path.endswith('/') and os.path.isdir(filename):
    768         files = []
    769         for f in os.listdir(filename):
    770             if f=='index.html':
    771                 body = open(os.path.join(filename,f),'rb').read()
    772                 break
    773             elif os.path.isdir(os.path.join(filename,f)):
    774                 f+='/'
    775             files.append("<a href=%r>%s</a>" % (f,f))
    776         else:
    777             body = ("<html><head><title>%s</title>" % url) + \
    778                 "</head><body>%s</body></html>" % '\n'.join(files)
    779         status, message = 200, "OK"
    780     else:
    781         status, message, body = 404, "Path not found", "Not found"
    782 
    783     return urllib2.HTTPError(url, status, message,
    784             {'content-type':'text/html'}, cStringIO.StringIO(body))
    785 
    786 
    787 
    788 
    789 
    790 
    791 
    792 
    793 
    794 
    795 
    796 
    797 
    798 # this line is a kludge to keep the trailing blank lines for pje's editor
  • deleted file setuptools-0.6c16dev4.egg/setuptools/sandbox.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/sandbox.py b/setuptools-0.6c16dev4.egg/setuptools/sandbox.py
    deleted file mode 100644
    index 4c5e712..0000000
    + -  
    1 import os, sys, __builtin__, tempfile, operator, pkg_resources
    2 _os = sys.modules[os.name]
    3 _open = open
    4 _file = file
    5 
    6 from distutils.errors import DistutilsError
    7 from pkg_resources import working_set
    8 
    9 __all__ = [
    10     "AbstractSandbox", "DirectorySandbox", "SandboxViolation", "run_setup",
    11 ]
    12 
    13 
    14 
    15 
    16 
    17 
    18 
    19 
    20 
    21 
    22 
    23 
    24 
    25 
    26 
    27 
    28 
    29 
    30 
    31 
    32 
    33 
    34 
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    42 def run_setup(setup_script, args):
    43     """Run a distutils setup script, sandboxed in its directory"""
    44     old_dir = os.getcwd()
    45     save_argv = sys.argv[:]
    46     save_path = sys.path[:]
    47     setup_dir = os.path.abspath(os.path.dirname(setup_script))
    48     temp_dir = os.path.join(setup_dir,'temp')
    49     if not os.path.isdir(temp_dir): os.makedirs(temp_dir)
    50     save_tmp = tempfile.tempdir
    51     save_modules = sys.modules.copy()
    52     pr_state = pkg_resources.__getstate__()
    53     try:
    54         tempfile.tempdir = temp_dir; os.chdir(setup_dir)
    55         try:
    56             sys.argv[:] = [setup_script]+list(args)
    57             sys.path.insert(0, setup_dir)
    58             # reset to include setup dir, w/clean callback list
    59             working_set.__init__() 
    60             working_set.callbacks.append(lambda dist:dist.activate())
    61             DirectorySandbox(setup_dir).run(
    62                 lambda: execfile(
    63                     "setup.py",
    64                     {'__file__':setup_script, '__name__':'__main__'}
    65                 )
    66             )
    67         except SystemExit, v:
    68             if v.args and v.args[0]:
    69                 raise
    70             # Normal exit, just return
    71     finally:
    72         pkg_resources.__setstate__(pr_state)
    73         sys.modules.update(save_modules)
    74         for key in list(sys.modules):
    75             if key not in save_modules: del sys.modules[key]
    76         os.chdir(old_dir)
    77         sys.path[:] = save_path
    78         sys.argv[:] = save_argv
    79         tempfile.tempdir = save_tmp
    80 
    81 
    82 
    83 class AbstractSandbox:
    84     """Wrap 'os' module and 'open()' builtin for virtualizing setup scripts"""
    85 
    86     _active = False
    87 
    88     def __init__(self):
    89         self._attrs = [
    90             name for name in dir(_os)
    91                 if not name.startswith('_') and hasattr(self,name)
    92         ]
    93 
    94     def _copy(self, source):
    95         for name in self._attrs:
    96             setattr(os, name, getattr(source,name))
    97 
    98     def run(self, func):
    99         """Run 'func' under os sandboxing"""
    100         try:
    101             self._copy(self)
    102             __builtin__.file = self._file
    103             __builtin__.open = self._open
    104             self._active = True
    105             return func()
    106         finally:
    107             self._active = False
    108             __builtin__.open = _open
    109             __builtin__.file = _file
    110             self._copy(_os)
    111 
    112     def _mk_dual_path_wrapper(name):
    113         original = getattr(_os,name)
    114         def wrap(self,src,dst,*args,**kw):
    115             if self._active:
    116                 src,dst = self._remap_pair(name,src,dst,*args,**kw)
    117             return original(src,dst,*args,**kw)
    118         return wrap
    119 
    120     for name in ["rename", "link", "symlink"]:
    121         if hasattr(_os,name): locals()[name] = _mk_dual_path_wrapper(name)
    122 
    123 
    124     def _mk_single_path_wrapper(name, original=None):
    125         original = original or getattr(_os,name)
    126         def wrap(self,path,*args,**kw):
    127             if self._active:
    128                 path = self._remap_input(name,path,*args,**kw)
    129             return original(path,*args,**kw)
    130         return wrap
    131 
    132     _open = _mk_single_path_wrapper('open', _open)
    133     _file = _mk_single_path_wrapper('file', _file)
    134     for name in [
    135         "stat", "listdir", "chdir", "open", "chmod", "chown", "mkdir",
    136         "remove", "unlink", "rmdir", "utime", "lchown", "chroot", "lstat",
    137         "startfile", "mkfifo", "mknod", "pathconf", "access"
    138     ]:
    139         if hasattr(_os,name): locals()[name] = _mk_single_path_wrapper(name)
    140 
    141     def _mk_single_with_return(name):
    142         original = getattr(_os,name)
    143         def wrap(self,path,*args,**kw):
    144             if self._active:
    145                 path = self._remap_input(name,path,*args,**kw)
    146                 return self._remap_output(name, original(path,*args,**kw))
    147             return original(path,*args,**kw)
    148         return wrap
    149 
    150     for name in ['readlink', 'tempnam']:
    151         if hasattr(_os,name): locals()[name] = _mk_single_with_return(name)
    152 
    153     def _mk_query(name):
    154         original = getattr(_os,name)
    155         def wrap(self,*args,**kw):
    156             retval = original(*args,**kw)
    157             if self._active:
    158                 return self._remap_output(name, retval)
    159             return retval
    160         return wrap
    161 
    162     for name in ['getcwd', 'tmpnam']:
    163         if hasattr(_os,name): locals()[name] = _mk_query(name)
    164 
    165     def _validate_path(self,path):
    166         """Called to remap or validate any path, whether input or output"""
    167         return path
    168 
    169     def _remap_input(self,operation,path,*args,**kw):
    170         """Called for path inputs"""
    171         return self._validate_path(path)
    172 
    173     def _remap_output(self,operation,path):
    174         """Called for path outputs"""
    175         return self._validate_path(path)
    176 
    177     def _remap_pair(self,operation,src,dst,*args,**kw):
    178         """Called for path pairs like rename, link, and symlink operations"""
    179         return (
    180             self._remap_input(operation+'-from',src,*args,**kw),
    181             self._remap_input(operation+'-to',dst,*args,**kw)
    182         )
    183 
    184 
    185 class DirectorySandbox(AbstractSandbox):
    186     """Restrict operations to a single subdirectory - pseudo-chroot"""
    187 
    188     write_ops = dict.fromkeys([
    189         "open", "chmod", "chown", "mkdir", "remove", "unlink", "rmdir",
    190         "utime", "lchown", "chroot", "mkfifo", "mknod", "tempnam",
    191     ])
    192 
    193     def __init__(self,sandbox):
    194         self._sandbox = os.path.normcase(os.path.realpath(sandbox))
    195         self._prefix = os.path.join(self._sandbox,'')
    196         AbstractSandbox.__init__(self)
    197 
    198     def _violation(self, operation, *args, **kw):
    199         raise SandboxViolation(operation, args, kw)
    200 
    201     def _open(self, path, mode='r', *args, **kw):
    202         if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
    203             self._violation("open", path, mode, *args, **kw)
    204         return _open(path,mode,*args,**kw)
    205 
    206     def tmpnam(self): self._violation("tmpnam")
    207 
    208     def _ok(self,path):
    209         if hasattr(_os,'devnull') and path==_os.devnull: return True
    210         active = self._active
    211         try:
    212             self._active = False
    213             realpath = os.path.normcase(os.path.realpath(path))
    214             if realpath==self._sandbox or realpath.startswith(self._prefix):
    215                 return True
    216         finally:
    217             self._active = active
    218 
    219     def _remap_input(self,operation,path,*args,**kw):
    220         """Called for path inputs"""
    221         if operation in self.write_ops and not self._ok(path):
    222             self._violation(operation, os.path.realpath(path), *args, **kw)
    223         return path
    224 
    225     def _remap_pair(self,operation,src,dst,*args,**kw):
    226         """Called for path pairs like rename, link, and symlink operations"""
    227         if not self._ok(src) or not self._ok(dst):
    228             self._violation(operation, src, dst, *args, **kw)
    229         return (src,dst)
    230 
    231     def _file(self, path, mode='r', *args, **kw):
    232         if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
    233             self._violation("file", path, mode, *args, **kw)
    234         return _file(path,mode,*args,**kw)
    235 
    236     def open(self, file, flags, mode=0777):
    237         """Called for low-level os.open()"""
    238         if flags & WRITE_FLAGS and not self._ok(file):
    239             self._violation("os.open", file, flags, mode)
    240         return _os.open(file,flags,mode)
    241 
    242 WRITE_FLAGS = reduce(
    243     operator.or_, [getattr(_os, a, 0) for a in
    244         "O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARY".split()]
    245 )
    246 
    247 class SandboxViolation(DistutilsError):
    248     """A setup script attempted to modify the filesystem outside the sandbox"""
    249 
    250     def __str__(self):
    251         return """SandboxViolation: %s%r %s
    252 
    253 The package setup script has attempted to modify files on your system
    254 that are not within the EasyInstall build area, and has been aborted.
    255 
    256 This package cannot be safely installed by EasyInstall, and may not
    257 support alternate installation locations even if you run its setup
    258 script by hand.  Please inform the package's author and the EasyInstall
    259 maintainers to find out if a fix or workaround is available.""" % self.args
    260 
    261 
    262 
    263 
    264 
    265 
    266 
    267 
    268 
    269 
    270 
    271 
    272 
    273 
    274 
    275 
    276 
    277 
    278 
    279 
    280 
    281 
    282 
    283 
    284 
    285 
    286 
    287 #
  • deleted file setuptools-0.6c16dev4.egg/setuptools/site-patch.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/site-patch.py b/setuptools-0.6c16dev4.egg/setuptools/site-patch.py
    deleted file mode 100644
    index b1b27b9..0000000
    + -  
    1 def __boot():
    2     import sys, imp, os, os.path
    3     PYTHONPATH = os.environ.get('PYTHONPATH')
    4     if PYTHONPATH is None or (sys.platform=='win32' and not PYTHONPATH):
    5         PYTHONPATH = []
    6     else:
    7         PYTHONPATH = PYTHONPATH.split(os.pathsep)
    8 
    9     pic = getattr(sys,'path_importer_cache',{})
    10     stdpath = sys.path[len(PYTHONPATH):]
    11     mydir = os.path.dirname(__file__)
    12     #print "searching",stdpath,sys.path
    13 
    14     for item in stdpath:
    15         if item==mydir or not item:
    16             continue    # skip if current dir. on Windows, or my own directory
    17         importer = pic.get(item)
    18         if importer is not None:
    19             loader = importer.find_module('site')
    20             if loader is not None:
    21                 # This should actually reload the current module
    22                 loader.load_module('site')
    23                 break
    24         else:
    25             try:
    26                 stream, path, descr = imp.find_module('site',[item])
    27             except ImportError:
    28                 continue
    29             if stream is None:
    30                 continue
    31             try:
    32                 # This should actually reload the current module
    33                 imp.load_module('site',stream,path,descr)
    34             finally:
    35                 stream.close()
    36             break
    37     else:
    38         raise ImportError("Couldn't find the real 'site' module")
    39 
    40     #print "loaded", __file__
    41 
    42     known_paths = dict([(makepath(item)[1],1) for item in sys.path]) # 2.2 comp
    43 
    44     oldpos = getattr(sys,'__egginsert',0)   # save old insertion position
    45     sys.__egginsert = 0                     # and reset the current one
    46 
    47     for item in PYTHONPATH:
    48         addsitedir(item)
    49 
    50     sys.__egginsert += oldpos           # restore effective old position
    51 
    52     d,nd = makepath(stdpath[0])
    53     insert_at = None
    54     new_path = []
    55 
    56     for item in sys.path:
    57         p,np = makepath(item)
    58 
    59         if np==nd and insert_at is None:
    60             # We've hit the first 'system' path entry, so added entries go here
    61             insert_at = len(new_path)
    62 
    63         if np in known_paths or insert_at is None:
    64             new_path.append(item)
    65         else:
    66             # new path after the insert point, back-insert it
    67             new_path.insert(insert_at, item)
    68             insert_at += 1
    69 
    70     sys.path[:] = new_path
    71 
    72 if __name__=='site':
    73     __boot()
    74     del __boot
  • deleted file setuptools-0.6c16dev4.egg/setuptools/tests/__init__.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/tests/__init__.py b/setuptools-0.6c16dev4.egg/setuptools/tests/__init__.py
    deleted file mode 100644
    index 3c4f3cb..0000000
    + -  
    1 """Tests for the 'setuptools' package"""
    2 from unittest import TestSuite, TestCase, makeSuite, defaultTestLoader
    3 import distutils.core, distutils.cmd
    4 from distutils.errors import DistutilsOptionError, DistutilsPlatformError
    5 from distutils.errors import DistutilsSetupError
    6 import setuptools, setuptools.dist
    7 from setuptools import Feature
    8 from distutils.core import Extension
    9 extract_constant, get_module_constant = None, None
    10 from setuptools.depends import *
    11 from distutils.version import StrictVersion, LooseVersion
    12 from distutils.util import convert_path
    13 import sys, os.path
    14 
    15 def additional_tests():
    16     import doctest, unittest
    17     suite = unittest.TestSuite((
    18         doctest.DocFileSuite('api_tests.txt',
    19                              optionflags=doctest.ELLIPSIS, package=__name__,
    20                              ),
    21         ))
    22     if sys.platform == 'win32':
    23         suite.addTest(doctest.DocFileSuite('win_script_wrapper.txt'))
    24     return suite
    25 
    26 def makeSetup(**args):
    27     """Return distribution from 'setup(**args)', without executing commands"""
    28 
    29     distutils.core._setup_stop_after = "commandline"
    30 
    31     # Don't let system command line leak into tests!
    32     args.setdefault('script_args',['install'])
    33 
    34     try:
    35         return setuptools.setup(**args)
    36     finally:
    37         distutils.core_setup_stop_after = None
    38 
    39 
    40 
    41 
    42 class DependsTests(TestCase):
    43 
    44     def testExtractConst(self):
    45         if not extract_constant: return  # skip on non-bytecode platforms
    46 
    47         def f1():
    48             global x,y,z
    49             x = "test"
    50             y = z
    51 
    52         # unrecognized name
    53         self.assertEqual(extract_constant(f1.func_code,'q', -1), None)
    54 
    55         # constant assigned
    56         self.assertEqual(extract_constant(f1.func_code,'x', -1), "test")
    57 
    58         # expression assigned
    59         self.assertEqual(extract_constant(f1.func_code,'y', -1), -1)
    60 
    61         # recognized name, not assigned
    62         self.assertEqual(extract_constant(f1.func_code,'z', -1), None)
    63 
    64 
    65     def testFindModule(self):
    66         self.assertRaises(ImportError, find_module, 'no-such.-thing')
    67         self.assertRaises(ImportError, find_module, 'setuptools.non-existent')
    68         f,p,i = find_module('setuptools.tests'); f.close()
    69 
    70     def testModuleExtract(self):
    71         if not get_module_constant: return  # skip on non-bytecode platforms
    72         from distutils import __version__
    73         self.assertEqual(
    74             get_module_constant('distutils','__version__'), __version__
    75         )
    76         self.assertEqual(
    77             get_module_constant('sys','version'), sys.version
    78         )
    79         self.assertEqual(
    80             get_module_constant('setuptools.tests','__doc__'),__doc__
    81         )
    82 
    83     def testRequire(self):
    84         if not extract_constant: return  # skip on non-bytecode platforms
    85 
    86         req = Require('Distutils','1.0.3','distutils')
    87 
    88         self.assertEqual(req.name, 'Distutils')
    89         self.assertEqual(req.module, 'distutils')
    90         self.assertEqual(req.requested_version, '1.0.3')
    91         self.assertEqual(req.attribute, '__version__')
    92         self.assertEqual(req.full_name(), 'Distutils-1.0.3')
    93 
    94         from distutils import __version__
    95         self.assertEqual(req.get_version(), __version__)
    96         self.failUnless(req.version_ok('1.0.9'))
    97         self.failIf(req.version_ok('0.9.1'))
    98         self.failIf(req.version_ok('unknown'))
    99 
    100         self.failUnless(req.is_present())
    101         self.failUnless(req.is_current())
    102 
    103         req = Require('Distutils 3000','03000','distutils',format=LooseVersion)
    104         self.failUnless(req.is_present())
    105         self.failIf(req.is_current())
    106         self.failIf(req.version_ok('unknown'))
    107 
    108         req = Require('Do-what-I-mean','1.0','d-w-i-m')
    109         self.failIf(req.is_present())
    110         self.failIf(req.is_current())
    111 
    112         req = Require('Tests', None, 'tests', homepage="http://example.com")
    113         self.assertEqual(req.format, None)
    114         self.assertEqual(req.attribute, None)
    115         self.assertEqual(req.requested_version, None)
    116         self.assertEqual(req.full_name(), 'Tests')
    117         self.assertEqual(req.homepage, 'http://example.com')
    118 
    119         paths = [os.path.dirname(p) for p in __path__]
    120         self.failUnless(req.is_present(paths))
    121         self.failUnless(req.is_current(paths))
    122 
    123 
    124 class DistroTests(TestCase):
    125 
    126     def setUp(self):
    127         self.e1 = Extension('bar.ext',['bar.c'])
    128         self.e2 = Extension('c.y', ['y.c'])
    129 
    130         self.dist = makeSetup(
    131             packages=['a', 'a.b', 'a.b.c', 'b', 'c'],
    132             py_modules=['b.d','x'],
    133             ext_modules = (self.e1, self.e2),
    134             package_dir = {},
    135         )
    136 
    137 
    138     def testDistroType(self):
    139         self.failUnless(isinstance(self.dist,setuptools.dist.Distribution))
    140 
    141 
    142     def testExcludePackage(self):
    143         self.dist.exclude_package('a')
    144         self.assertEqual(self.dist.packages, ['b','c'])
    145 
    146         self.dist.exclude_package('b')
    147         self.assertEqual(self.dist.packages, ['c'])
    148         self.assertEqual(self.dist.py_modules, ['x'])
    149         self.assertEqual(self.dist.ext_modules, [self.e1, self.e2])
    150 
    151         self.dist.exclude_package('c')
    152         self.assertEqual(self.dist.packages, [])
    153         self.assertEqual(self.dist.py_modules, ['x'])
    154         self.assertEqual(self.dist.ext_modules, [self.e1])
    155 
    156         # test removals from unspecified options
    157         makeSetup().exclude_package('x')
    158 
    159 
    160 
    161 
    162 
    163 
    164 
    165     def testIncludeExclude(self):
    166         # remove an extension
    167         self.dist.exclude(ext_modules=[self.e1])
    168         self.assertEqual(self.dist.ext_modules, [self.e2])
    169 
    170         # add it back in
    171         self.dist.include(ext_modules=[self.e1])
    172         self.assertEqual(self.dist.ext_modules, [self.e2, self.e1])
    173 
    174         # should not add duplicate
    175         self.dist.include(ext_modules=[self.e1])
    176         self.assertEqual(self.dist.ext_modules, [self.e2, self.e1])
    177 
    178     def testExcludePackages(self):
    179         self.dist.exclude(packages=['c','b','a'])
    180         self.assertEqual(self.dist.packages, [])
    181         self.assertEqual(self.dist.py_modules, ['x'])
    182         self.assertEqual(self.dist.ext_modules, [self.e1])
    183 
    184     def testEmpty(self):
    185         dist = makeSetup()
    186         dist.include(packages=['a'], py_modules=['b'], ext_modules=[self.e2])
    187         dist = makeSetup()
    188         dist.exclude(packages=['a'], py_modules=['b'], ext_modules=[self.e2])
    189 
    190     def testContents(self):
    191         self.failUnless(self.dist.has_contents_for('a'))
    192         self.dist.exclude_package('a')
    193         self.failIf(self.dist.has_contents_for('a'))
    194 
    195         self.failUnless(self.dist.has_contents_for('b'))
    196         self.dist.exclude_package('b')
    197         self.failIf(self.dist.has_contents_for('b'))
    198 
    199         self.failUnless(self.dist.has_contents_for('c'))
    200         self.dist.exclude_package('c')
    201         self.failIf(self.dist.has_contents_for('c'))
    202 
    203 
    204 
    205 
    206     def testInvalidIncludeExclude(self):
    207         self.assertRaises(DistutilsSetupError,
    208             self.dist.include, nonexistent_option='x'
    209         )
    210         self.assertRaises(DistutilsSetupError,
    211             self.dist.exclude, nonexistent_option='x'
    212         )
    213         self.assertRaises(DistutilsSetupError,
    214             self.dist.include, packages={'x':'y'}
    215         )
    216         self.assertRaises(DistutilsSetupError,
    217             self.dist.exclude, packages={'x':'y'}
    218         )
    219         self.assertRaises(DistutilsSetupError,
    220             self.dist.include, ext_modules={'x':'y'}
    221         )
    222         self.assertRaises(DistutilsSetupError,
    223             self.dist.exclude, ext_modules={'x':'y'}
    224         )
    225 
    226         self.assertRaises(DistutilsSetupError,
    227             self.dist.include, package_dir=['q']
    228         )
    229         self.assertRaises(DistutilsSetupError,
    230             self.dist.exclude, package_dir=['q']
    231         )
    232 
    233 
    234 
    235 
    236 
    237 
    238 
    239 
    240 
    241 
    242 
    243 
    244 
    245 
    246 
    247 class FeatureTests(TestCase):
    248 
    249     def setUp(self):
    250         self.req = Require('Distutils','1.0.3','distutils')
    251         self.dist = makeSetup(
    252             features={
    253                 'foo': Feature("foo",standard=True,require_features=['baz',self.req]),
    254                 'bar': Feature("bar",  standard=True, packages=['pkg.bar'],
    255                                py_modules=['bar_et'], remove=['bar.ext'],
    256                        ),
    257                 'baz': Feature(
    258                         "baz", optional=False, packages=['pkg.baz'],
    259                         scripts = ['scripts/baz_it'],
    260                         libraries=[('libfoo','foo/foofoo.c')]
    261                        ),
    262                 'dwim': Feature("DWIM", available=False, remove='bazish'),
    263             },
    264             script_args=['--without-bar', 'install'],
    265             packages = ['pkg.bar', 'pkg.foo'],
    266             py_modules = ['bar_et', 'bazish'],
    267             ext_modules = [Extension('bar.ext',['bar.c'])]
    268         )
    269 
    270     def testDefaults(self):
    271         self.failIf(
    272             Feature(
    273                 "test",standard=True,remove='x',available=False
    274             ).include_by_default()
    275         )
    276         self.failUnless(
    277             Feature("test",standard=True,remove='x').include_by_default()
    278         )
    279         # Feature must have either kwargs, removes, or require_features
    280         self.assertRaises(DistutilsSetupError, Feature, "test")
    281 
    282     def testAvailability(self):
    283         self.assertRaises(
    284             DistutilsPlatformError,
    285             self.dist.features['dwim'].include_in, self.dist
    286         )
    287 
    288     def testFeatureOptions(self):
    289         dist = self.dist
    290         self.failUnless(
    291             ('with-dwim',None,'include DWIM') in dist.feature_options
    292         )
    293         self.failUnless(
    294             ('without-dwim',None,'exclude DWIM (default)') in dist.feature_options
    295         )
    296         self.failUnless(
    297             ('with-bar',None,'include bar (default)') in dist.feature_options
    298         )
    299         self.failUnless(
    300             ('without-bar',None,'exclude bar') in dist.feature_options
    301         )
    302         self.assertEqual(dist.feature_negopt['without-foo'],'with-foo')
    303         self.assertEqual(dist.feature_negopt['without-bar'],'with-bar')
    304         self.assertEqual(dist.feature_negopt['without-dwim'],'with-dwim')
    305         self.failIf('without-baz' in dist.feature_negopt)
    306 
    307     def testUseFeatures(self):
    308         dist = self.dist
    309         self.assertEqual(dist.with_foo,1)
    310         self.assertEqual(dist.with_bar,0)
    311         self.assertEqual(dist.with_baz,1)
    312         self.failIf('bar_et' in dist.py_modules)
    313         self.failIf('pkg.bar' in dist.packages)
    314         self.failUnless('pkg.baz' in dist.packages)
    315         self.failUnless('scripts/baz_it' in dist.scripts)
    316         self.failUnless(('libfoo','foo/foofoo.c') in dist.libraries)
    317         self.assertEqual(dist.ext_modules,[])
    318         self.assertEqual(dist.require_features, [self.req])
    319 
    320         # If we ask for bar, it should fail because we explicitly disabled
    321         # it on the command line
    322         self.assertRaises(DistutilsOptionError, dist.include_feature, 'bar')
    323 
    324     def testFeatureWithInvalidRemove(self):
    325         self.assertRaises(
    326             SystemExit, makeSetup, features = {'x':Feature('x', remove='y')}
    327         )
    328 
    329 class TestCommandTests(TestCase):
    330 
    331     def testTestIsCommand(self):
    332         test_cmd = makeSetup().get_command_obj('test')
    333         self.failUnless(isinstance(test_cmd, distutils.cmd.Command))
    334 
    335     def testLongOptSuiteWNoDefault(self):
    336         ts1 = makeSetup(script_args=['test','--test-suite=foo.tests.suite'])
    337         ts1 = ts1.get_command_obj('test')
    338         ts1.ensure_finalized()
    339         self.assertEqual(ts1.test_suite, 'foo.tests.suite')
    340 
    341     def testDefaultSuite(self):
    342         ts2 = makeSetup(test_suite='bar.tests.suite').get_command_obj('test')
    343         ts2.ensure_finalized()
    344         self.assertEqual(ts2.test_suite, 'bar.tests.suite')
    345 
    346     def testDefaultWModuleOnCmdLine(self):
    347         ts3 = makeSetup(
    348             test_suite='bar.tests',
    349             script_args=['test','-m','foo.tests']
    350         ).get_command_obj('test')
    351         ts3.ensure_finalized()
    352         self.assertEqual(ts3.test_module, 'foo.tests')
    353         self.assertEqual(ts3.test_suite,  'foo.tests.test_suite')
    354 
    355     def testConflictingOptions(self):
    356         ts4 = makeSetup(
    357             script_args=['test','-m','bar.tests', '-s','foo.tests.suite']
    358         ).get_command_obj('test')
    359         self.assertRaises(DistutilsOptionError, ts4.ensure_finalized)
    360 
    361     def testNoSuite(self):
    362         ts5 = makeSetup().get_command_obj('test')
    363         ts5.ensure_finalized()
    364         self.assertEqual(ts5.test_suite, None)
    365        
    366 
    367 
    368 
    369 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/tests/test_packageindex.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/tests/test_packageindex.py b/setuptools-0.6c16dev4.egg/setuptools/tests/test_packageindex.py
    deleted file mode 100644
    index 0231eda..0000000
    + -  
    1 """Package Index Tests
    2 """
    3 # More would be better!
    4 
    5 import os, shutil, tempfile, unittest, urllib2
    6 import pkg_resources
    7 import setuptools.package_index
    8 
    9 class TestPackageIndex(unittest.TestCase):
    10 
    11     def test_bad_urls(self):
    12         index = setuptools.package_index.PackageIndex()
    13         url = 'http://127.0.0.1/nonesuch/test_package_index'
    14         try:
    15             v = index.open_url(url)
    16         except Exception, v:
    17             self.assert_(url in str(v))
    18         else:
    19             self.assert_(isinstance(v,urllib2.HTTPError))
    20 
    21     def test_url_ok(self):
    22         index = setuptools.package_index.PackageIndex(
    23             hosts=('www.example.com',)
    24         )
    25         url = 'file:///tmp/test_package_index'
    26         self.assert_(index.url_ok(url, True))
    27 
  • deleted file setuptools-0.6c16dev4.egg/setuptools/tests/test_resources.py

    diff --git a/setuptools-0.6c16dev4.egg/setuptools/tests/test_resources.py b/setuptools-0.6c16dev4.egg/setuptools/tests/test_resources.py
    deleted file mode 100644
    index 1c010e7..0000000
    + -  
    1 #!/usr/bin/python
    2 # -*- coding: utf-8 -*-
    3 # NOTE: the shebang and encoding lines are for ScriptHeaderTests; do not remove
    4 from unittest import TestCase, makeSuite; from pkg_resources import *
    5 from setuptools.command.easy_install import get_script_header, is_sh
    6 import os, pkg_resources, sys, StringIO
    7 try: frozenset
    8 except NameError:
    9     from sets import ImmutableSet as frozenset
    10 
    11 class Metadata(EmptyProvider):
    12     """Mock object to return metadata as if from an on-disk distribution"""
    13 
    14     def __init__(self,*pairs):
    15         self.metadata = dict(pairs)
    16 
    17     def has_metadata(self,name):
    18         return name in self.metadata
    19 
    20     def get_metadata(self,name):
    21         return self.metadata[name]
    22 
    23     def get_metadata_lines(self,name):
    24         return yield_lines(self.get_metadata(name))
    25 
    26 class DistroTests(TestCase):
    27 
    28     def testCollection(self):
    29         # empty path should produce no distributions
    30         ad = Environment([], platform=None, python=None)
    31         self.assertEqual(list(ad), [])
    32         self.assertEqual(ad['FooPkg'],[])
    33         ad.add(Distribution.from_filename("FooPkg-1.3_1.egg"))
    34         ad.add(Distribution.from_filename("FooPkg-1.4-py2.4-win32.egg"))
    35         ad.add(Distribution.from_filename("FooPkg-1.2-py2.4.egg"))
    36 
    37         # Name is in there now
    38         self.failUnless(ad['FooPkg'])
    39         # But only 1 package
    40         self.assertEqual(list(ad), ['foopkg'])
    41 
    42         # Distributions sort by version
    43         self.assertEqual(
    44             [dist.version for dist in ad['FooPkg']], ['1.4','1.3-1','1.2']
    45         )
    46         # Removing a distribution leaves sequence alone
    47         ad.remove(ad['FooPkg'][1])
    48         self.assertEqual(
    49             [dist.version for dist in ad['FooPkg']], ['1.4','1.2']
    50         )
    51         # And inserting adds them in order
    52         ad.add(Distribution.from_filename("FooPkg-1.9.egg"))
    53         self.assertEqual(
    54             [dist.version for dist in ad['FooPkg']], ['1.9','1.4','1.2']
    55         )
    56 
    57         ws = WorkingSet([])
    58         foo12 = Distribution.from_filename("FooPkg-1.2-py2.4.egg")
    59         foo14 = Distribution.from_filename("FooPkg-1.4-py2.4-win32.egg")
    60         req, = parse_requirements("FooPkg>=1.3")
    61 
    62         # Nominal case: no distros on path, should yield all applicable
    63         self.assertEqual(ad.best_match(req,ws).version, '1.9')
    64         # If a matching distro is already installed, should return only that
    65         ws.add(foo14); self.assertEqual(ad.best_match(req,ws).version, '1.4')
    66 
    67         # If the first matching distro is unsuitable, it's a version conflict
    68         ws = WorkingSet([]); ws.add(foo12); ws.add(foo14)
    69         self.assertRaises(VersionConflict, ad.best_match, req, ws)
    70 
    71         # If more than one match on the path, the first one takes precedence
    72         ws = WorkingSet([]); ws.add(foo14); ws.add(foo12); ws.add(foo14);
    73         self.assertEqual(ad.best_match(req,ws).version, '1.4')
    74 
    75     def checkFooPkg(self,d):
    76         self.assertEqual(d.project_name, "FooPkg")
    77         self.assertEqual(d.key, "foopkg")
    78         self.assertEqual(d.version, "1.3-1")
    79         self.assertEqual(d.py_version, "2.4")
    80         self.assertEqual(d.platform, "win32")
    81         self.assertEqual(d.parsed_version, parse_version("1.3-1"))
    82 
    83     def testDistroBasics(self):
    84         d = Distribution(
    85             "/some/path",
    86             project_name="FooPkg",version="1.3-1",py_version="2.4",platform="win32"
    87         )
    88         self.checkFooPkg(d)
    89 
    90         d = Distribution("/some/path")
    91         self.assertEqual(d.py_version, sys.version[:3])
    92         self.assertEqual(d.platform, None)
    93 
    94     def testDistroParse(self):
    95         d = Distribution.from_filename("FooPkg-1.3_1-py2.4-win32.egg")
    96         self.checkFooPkg(d)
    97         d = Distribution.from_filename("FooPkg-1.3_1-py2.4-win32.egg-info")
    98         self.checkFooPkg(d)
    99 
    100     def testDistroMetadata(self):
    101         d = Distribution(
    102             "/some/path", project_name="FooPkg", py_version="2.4", platform="win32",
    103             metadata = Metadata(
    104                 ('PKG-INFO',"Metadata-Version: 1.0\nVersion: 1.3-1\n")
    105             )
    106         )
    107         self.checkFooPkg(d)
    108 
    109 
    110     def distRequires(self, txt):
    111         return Distribution("/foo", metadata=Metadata(('depends.txt', txt)))
    112 
    113     def checkRequires(self, dist, txt, extras=()):
    114         self.assertEqual(
    115             list(dist.requires(extras)),
    116             list(parse_requirements(txt))
    117         )
    118 
    119     def testDistroDependsSimple(self):
    120         for v in "Twisted>=1.5", "Twisted>=1.5\nZConfig>=2.0":
    121             self.checkRequires(self.distRequires(v), v)
    122 
    123 
    124     def testResolve(self):
    125         ad = Environment([]); ws = WorkingSet([])
    126         # Resolving no requirements -> nothing to install
    127         self.assertEqual( list(ws.resolve([],ad)), [] )
    128         # Request something not in the collection -> DistributionNotFound
    129         self.assertRaises(
    130             DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad
    131         )
    132         Foo = Distribution.from_filename(
    133             "/foo_dir/Foo-1.2.egg",
    134             metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
    135         )
    136         ad.add(Foo); ad.add(Distribution.from_filename("Foo-0.9.egg"))
    137 
    138         # Request thing(s) that are available -> list to activate
    139         for i in range(3):
    140             targets = list(ws.resolve(parse_requirements("Foo"), ad))
    141             self.assertEqual(targets, [Foo])
    142             map(ws.add,targets)
    143         self.assertRaises(VersionConflict, ws.resolve,
    144             parse_requirements("Foo==0.9"), ad)
    145         ws = WorkingSet([]) # reset
    146 
    147         # Request an extra that causes an unresolved dependency for "Baz"
    148         self.assertRaises(
    149             DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad
    150         )
    151         Baz = Distribution.from_filename(
    152             "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
    153         )
    154         ad.add(Baz)
    155 
    156         # Activation list now includes resolved dependency
    157         self.assertEqual(
    158             list(ws.resolve(parse_requirements("Foo[bar]"), ad)), [Foo,Baz]
    159         )
    160         # Requests for conflicting versions produce VersionConflict
    161         self.assertRaises( VersionConflict,
    162             ws.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), ad
    163         )
    164 
    165     def testDistroDependsOptions(self):
    166         d = self.distRequires("""
    167             Twisted>=1.5
    168             [docgen]
    169             ZConfig>=2.0
    170             docutils>=0.3
    171             [fastcgi]
    172             fcgiapp>=0.1""")
    173         self.checkRequires(d,"Twisted>=1.5")
    174         self.checkRequires(
    175             d,"Twisted>=1.5 ZConfig>=2.0 docutils>=0.3".split(), ["docgen"]
    176         )
    177         self.checkRequires(
    178             d,"Twisted>=1.5 fcgiapp>=0.1".split(), ["fastcgi"]
    179         )
    180         self.checkRequires(
    181             d,"Twisted>=1.5 ZConfig>=2.0 docutils>=0.3 fcgiapp>=0.1".split(),
    182             ["docgen","fastcgi"]
    183         )
    184         self.checkRequires(
    185             d,"Twisted>=1.5 fcgiapp>=0.1 ZConfig>=2.0 docutils>=0.3".split(),
    186             ["fastcgi", "docgen"]
    187         )
    188         self.assertRaises(UnknownExtra, d.requires, ["foo"])
    189 
    190 
    191 
    192 
    193 
    194 
    195 
    196 
    197 
    198 
    199 
    200 
    201 
    202 
    203 
    204 
    205 
    206 class EntryPointTests(TestCase):
    207 
    208     def assertfields(self, ep):
    209         self.assertEqual(ep.name,"foo")
    210         self.assertEqual(ep.module_name,"setuptools.tests.test_resources")
    211         self.assertEqual(ep.attrs, ("EntryPointTests",))
    212         self.assertEqual(ep.extras, ("x",))
    213         self.failUnless(ep.load() is EntryPointTests)
    214         self.assertEqual(
    215             str(ep),
    216             "foo = setuptools.tests.test_resources:EntryPointTests [x]"
    217         )
    218 
    219     def setUp(self):
    220         self.dist = Distribution.from_filename(
    221             "FooPkg-1.2-py2.4.egg", metadata=Metadata(('requires.txt','[x]')))
    222 
    223     def testBasics(self):
    224         ep = EntryPoint(
    225             "foo", "setuptools.tests.test_resources", ["EntryPointTests"],
    226             ["x"], self.dist
    227         )
    228         self.assertfields(ep)
    229 
    230     def testParse(self):
    231         s = "foo = setuptools.tests.test_resources:EntryPointTests [x]"
    232         ep = EntryPoint.parse(s, self.dist)
    233         self.assertfields(ep)
    234 
    235         ep = EntryPoint.parse("bar baz=  spammity[PING]")
    236         self.assertEqual(ep.name,"bar baz")
    237         self.assertEqual(ep.module_name,"spammity")
    238         self.assertEqual(ep.attrs, ())
    239         self.assertEqual(ep.extras, ("ping",))
    240 
    241         ep = EntryPoint.parse(" fizzly =  wocka:foo")
    242         self.assertEqual(ep.name,"fizzly")
    243         self.assertEqual(ep.module_name,"wocka")
    244         self.assertEqual(ep.attrs, ("foo",))
    245         self.assertEqual(ep.extras, ())
    246 
    247     def testRejects(self):
    248         for ep in [
    249             "foo", "x=1=2", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2",
    250         ]:
    251             try: EntryPoint.parse(ep)
    252             except ValueError: pass
    253             else: raise AssertionError("Should've been bad", ep)
    254 
    255     def checkSubMap(self, m):
    256         self.assertEqual(len(m), len(self.submap_expect))
    257         for key, ep in self.submap_expect.iteritems():
    258             self.assertEqual(repr(m.get(key)), repr(ep))
    259 
    260     submap_expect = dict(
    261         feature1=EntryPoint('feature1', 'somemodule', ['somefunction']),
    262         feature2=EntryPoint('feature2', 'another.module', ['SomeClass'], ['extra1','extra2']),
    263         feature3=EntryPoint('feature3', 'this.module', extras=['something'])
    264     )
    265     submap_str = """
    266             # define features for blah blah
    267             feature1 = somemodule:somefunction
    268             feature2 = another.module:SomeClass [extra1,extra2]
    269             feature3 = this.module [something]
    270     """
    271 
    272     def testParseList(self):
    273         self.checkSubMap(EntryPoint.parse_group("xyz", self.submap_str))
    274         self.assertRaises(ValueError, EntryPoint.parse_group, "x a", "foo=bar")
    275         self.assertRaises(ValueError, EntryPoint.parse_group, "x",
    276             ["foo=baz", "foo=bar"])
    277 
    278     def testParseMap(self):
    279         m = EntryPoint.parse_map({'xyz':self.submap_str})
    280         self.checkSubMap(m['xyz'])
    281         self.assertEqual(m.keys(),['xyz'])
    282         m = EntryPoint.parse_map("[xyz]\n"+self.submap_str)
    283         self.checkSubMap(m['xyz'])
    284         self.assertEqual(m.keys(),['xyz'])
    285         self.assertRaises(ValueError, EntryPoint.parse_map, ["[xyz]", "[xyz]"])
    286         self.assertRaises(ValueError, EntryPoint.parse_map, self.submap_str)
    287 
    288 class RequirementsTests(TestCase):
    289 
    290     def testBasics(self):
    291         r = Requirement.parse("Twisted>=1.2")
    292         self.assertEqual(str(r),"Twisted>=1.2")
    293         self.assertEqual(repr(r),"Requirement.parse('Twisted>=1.2')")
    294         self.assertEqual(r, Requirement("Twisted", [('>=','1.2')], ()))
    295         self.assertEqual(r, Requirement("twisTed", [('>=','1.2')], ()))
    296         self.assertNotEqual(r, Requirement("Twisted", [('>=','2.0')], ()))
    297         self.assertNotEqual(r, Requirement("Zope", [('>=','1.2')], ()))
    298         self.assertNotEqual(r, Requirement("Zope", [('>=','3.0')], ()))
    299         self.assertNotEqual(r, Requirement.parse("Twisted[extras]>=1.2"))
    300 
    301     def testOrdering(self):
    302         r1 = Requirement("Twisted", [('==','1.2c1'),('>=','1.2')], ())
    303         r2 = Requirement("Twisted", [('>=','1.2'),('==','1.2c1')], ())
    304         self.assertEqual(r1,r2)
    305         self.assertEqual(str(r1),str(r2))
    306         self.assertEqual(str(r2),"Twisted==1.2c1,>=1.2")
    307 
    308     def testBasicContains(self):
    309         r = Requirement("Twisted", [('>=','1.2')], ())
    310         foo_dist = Distribution.from_filename("FooPkg-1.3_1.egg")
    311         twist11  = Distribution.from_filename("Twisted-1.1.egg")
    312         twist12  = Distribution.from_filename("Twisted-1.2.egg")
    313         self.failUnless(parse_version('1.2') in r)
    314         self.failUnless(parse_version('1.1') not in r)
    315         self.failUnless('1.2' in r)
    316         self.failUnless('1.1' not in r)
    317         self.failUnless(foo_dist not in r)
    318         self.failUnless(twist11 not in r)
    319         self.failUnless(twist12 in r)
    320 
    321     def testAdvancedContains(self):
    322         r, = parse_requirements("Foo>=1.2,<=1.3,==1.9,>2.0,!=2.5,<3.0,==4.5")
    323         for v in ('1.2','1.2.2','1.3','1.9','2.0.1','2.3','2.6','3.0c1','4.5'):
    324             self.failUnless(v in r, (v,r))
    325         for v in ('1.2c1','1.3.1','1.5','1.9.1','2.0','2.5','3.0','4.0'):
    326             self.failUnless(v not in r, (v,r))
    327 
    328 
    329     def testOptionsAndHashing(self):
    330         r1 = Requirement.parse("Twisted[foo,bar]>=1.2")
    331         r2 = Requirement.parse("Twisted[bar,FOO]>=1.2")
    332         r3 = Requirement.parse("Twisted[BAR,FOO]>=1.2.0")
    333         self.assertEqual(r1,r2)
    334         self.assertEqual(r1,r3)
    335         self.assertEqual(r1.extras, ("foo","bar"))
    336         self.assertEqual(r2.extras, ("bar","foo"))  # extras are normalized
    337         self.assertEqual(hash(r1), hash(r2))
    338         self.assertEqual(
    339             hash(r1), hash(("twisted", ((">=",parse_version("1.2")),),
    340                             frozenset(["foo","bar"])))
    341         )
    342 
    343     def testVersionEquality(self):
    344         r1 = Requirement.parse("setuptools==0.3a2")
    345         r2 = Requirement.parse("setuptools!=0.3a4")
    346         d = Distribution.from_filename
    347 
    348         self.failIf(d("setuptools-0.3a4.egg") in r1)
    349         self.failIf(d("setuptools-0.3a1.egg") in r1)
    350         self.failIf(d("setuptools-0.3a4.egg") in r2)
    351 
    352         self.failUnless(d("setuptools-0.3a2.egg") in r1)
    353         self.failUnless(d("setuptools-0.3a2.egg") in r2)
    354         self.failUnless(d("setuptools-0.3a3.egg") in r2)
    355         self.failUnless(d("setuptools-0.3a5.egg") in r2)
    356 
    357 
    358 
    359 
    360 
    361 
    362 
    363 
    364 
    365 
    366 
    367 
    368 
    369 
    370 class ParseTests(TestCase):
    371 
    372     def testEmptyParse(self):
    373         self.assertEqual(list(parse_requirements('')), [])
    374 
    375     def testYielding(self):
    376         for inp,out in [
    377             ([], []), ('x',['x']), ([[]],[]), (' x\n y', ['x','y']),
    378             (['x\n\n','y'], ['x','y']),
    379         ]:
    380             self.assertEqual(list(pkg_resources.yield_lines(inp)),out)
    381 
    382     def testSplitting(self):
    383         self.assertEqual(
    384             list(
    385                 pkg_resources.split_sections("""
    386                     x
    387                     [Y]
    388                     z
    389 
    390                     a
    391                     [b ]
    392                     # foo
    393                     c
    394                     [ d]
    395                     [q]
    396                     v
    397                     """
    398                 )
    399             ),
    400             [(None,["x"]), ("Y",["z","a"]), ("b",["c"]), ("d",[]), ("q",["v"])]
    401         )
    402         self.assertRaises(ValueError,list,pkg_resources.split_sections("[foo"))
    403 
    404     def testSafeName(self):
    405         self.assertEqual(safe_name("adns-python"), "adns-python")
    406         self.assertEqual(safe_name("WSGI Utils"),  "WSGI-Utils")
    407         self.assertEqual(safe_name("WSGI  Utils"), "WSGI-Utils")
    408         self.assertEqual(safe_name("Money$$$Maker"), "Money-Maker")
    409         self.assertNotEqual(safe_name("peak.web"), "peak-web")
    410 
    411     def testSafeVersion(self):
    412         self.assertEqual(safe_version("1.2-1"), "1.2-1")
    413         self.assertEqual(safe_version("1.2 alpha"),  "1.2.alpha")
    414         self.assertEqual(safe_version("2.3.4 20050521"), "2.3.4.20050521")
    415         self.assertEqual(safe_version("Money$$$Maker"), "Money-Maker")
    416         self.assertEqual(safe_version("peak.web"), "peak.web")
    417 
    418     def testSimpleRequirements(self):
    419         self.assertEqual(
    420             list(parse_requirements('Twis-Ted>=1.2-1')),
    421             [Requirement('Twis-Ted',[('>=','1.2-1')], ())]
    422         )
    423         self.assertEqual(
    424             list(parse_requirements('Twisted >=1.2, \ # more\n<2.0')),
    425             [Requirement('Twisted',[('>=','1.2'),('<','2.0')], ())]
    426         )
    427         self.assertEqual(
    428             Requirement.parse("FooBar==1.99a3"),
    429             Requirement("FooBar", [('==','1.99a3')], ())
    430         )
    431         self.assertRaises(ValueError,Requirement.parse,">=2.3")
    432         self.assertRaises(ValueError,Requirement.parse,"x\\")
    433         self.assertRaises(ValueError,Requirement.parse,"x==2 q")
    434         self.assertRaises(ValueError,Requirement.parse,"X==1\nY==2")
    435         self.assertRaises(ValueError,Requirement.parse,"#")
    436 
    437     def testVersionEquality(self):
    438         def c(s1,s2):
    439             p1, p2 = parse_version(s1),parse_version(s2)
    440             self.assertEqual(p1,p2, (s1,s2,p1,p2))
    441 
    442         c('1.2-rc1', '1.2rc1')
    443         c('0.4', '0.4.0')
    444         c('0.4.0.0', '0.4.0')
    445         c('0.4.0-0', '0.4-0')
    446         c('0pl1', '0.0pl1')
    447         c('0pre1', '0.0c1')
    448         c('0.0.0preview1', '0c1')
    449         c('0.0c1', '0-rc1')
    450         c('1.2a1', '1.2.a.1'); c('1.2...a', '1.2a')
    451 
    452     def testVersionOrdering(self):
    453         def c(s1,s2):
    454             p1, p2 = parse_version(s1),parse_version(s2)
    455             self.failUnless(p1<p2, (s1,s2,p1,p2))
    456 
    457         c('2.1','2.1.1')
    458         c('2a1','2b0')
    459         c('2a1','2.1')
    460         c('2.3a1', '2.3')
    461         c('2.1-1', '2.1-2')
    462         c('2.1-1', '2.1.1')
    463         c('2.1', '2.1pl4')
    464         c('2.1a0-20040501', '2.1')
    465         c('1.1', '02.1')
    466         c('A56','B27')
    467         c('3.2', '3.2.pl0')
    468         c('3.2-1', '3.2pl1')
    469         c('3.2pl1', '3.2pl1-1')
    470         c('0.4', '4.0')
    471         c('0.0.4', '0.4.0')
    472         c('0pl1', '0.4pl1')
    473         c('2.1.0-rc1','2.1.0')
    474         c('2.1dev','2.1a0')
    475 
    476         torture ="""
    477         0.80.1-3 0.80.1-2 0.80.1-1 0.79.9999+0.80.0pre4-1
    478         0.79.9999+0.80.0pre2-3 0.79.9999+0.80.0pre2-2
    479         0.77.2-1 0.77.1-1 0.77.0-1
    480         """.split()
    481 
    482         for p,v1 in enumerate(torture):
    483             for v2 in torture[p+1:]:
    484                 c(v2,v1)
    485 
    486 
    487 
    488 
    489 
    490 
    491 
    492 
    493 class ScriptHeaderTests(TestCase):
    494     non_ascii_exe = '/Users/José/bin/python'
    495 
    496     def test_get_script_header(self):
    497         if not sys.platform.startswith('java') or not is_sh(sys.executable):
    498             # This test is for non-Jython platforms
    499             self.assertEqual(get_script_header('#!/usr/local/bin/python'),
    500                              '#!%s\n' % os.path.normpath(sys.executable))
    501             self.assertEqual(get_script_header('#!/usr/bin/python -x'),
    502                              '#!%s  -x\n' % os.path.normpath(sys.executable))
    503             self.assertEqual(get_script_header('#!/usr/bin/python',
    504                                                executable=self.non_ascii_exe),
    505                              '#!%s -x\n' % self.non_ascii_exe)
    506 
    507     def test_get_script_header_jython_workaround(self):
    508         platform = sys.platform
    509         sys.platform = 'java1.5.0_13'
    510         stdout = sys.stdout
    511         try:
    512             # A mock sys.executable that uses a shebang line (this file)
    513             exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py')
    514             self.assertEqual(
    515                 get_script_header('#!/usr/local/bin/python', executable=exe),
    516                 '#!/usr/bin/env %s\n' % exe)
    517 
    518             # Ensure we generate what is basically a broken shebang line
    519             # when there's options, with a warning emitted
    520             sys.stdout = StringIO.StringIO()
    521             self.assertEqual(get_script_header('#!/usr/bin/python -x',
    522                                                executable=exe),
    523                              '#!%s  -x\n' % exe)
    524             self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
    525             sys.stdout = StringIO.StringIO()
    526             self.assertEqual(get_script_header('#!/usr/bin/python',
    527                                                executable=self.non_ascii_exe),
    528                              '#!%s -x\n' % self.non_ascii_exe)
    529             self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
    530         finally:
    531             sys.platform = platform
    532             sys.stdout = stdout
    533 
  • deleted file setuptools-0.6c16dev4.egg/zetuptoolz.txt

    diff --git a/setuptools-0.6c16dev4.egg/zetuptoolz.txt b/setuptools-0.6c16dev4.egg/zetuptoolz.txt
    deleted file mode 100644
    index b4729c7..0000000
    + -  
    1 This is the "zetuptoolz" fork of setuptools. This version is forked from
    2 setuptools trunk r80621 (which is current as of 2010-08-31), with the following
    3 differences:
    4 
    5 
    6  * Zooko's and David-Sarah's patches for the following bugs and features have been applied:
    7  
    8      <http://bugs.python.org/setuptools/issue17>
    9      "easy_install will install a package that is already there"
    10 
    11      <http://bugs.python.org/setuptools/issue54>
    12      "be more like distutils with regard to --prefix="
    13 
    14      <http://bugs.python.org/setuptools/issue53>
    15      "respect the PYTHONPATH"
    16      (Note: this patch does not work as intended when site.py has been modified.
    17      This will be fixed in a future version.)
    18 
    19      <https://tahoe-lafs.org/trac/zetuptoolz/ticket/4>
    20      "python setup.py --help-commands raises exception due to conflict with distribute"
    21 
    22 
    23  * The following patch to setuptools introduced bugs, and has been reverted
    24    in zetuptoolz:
    25 
    26     $ svn log -r 45514
    27     ------------------------------------------------------------------------
    28     r45514 | phillip.eby | 2006-04-18 04:03:16 +0100 (Tue, 18 Apr 2006) | 9 lines
    29 
    30     Backport pkgutil, pydoc, and doctest from the 2.5 trunk to setuptools
    31     0.7 trunk.  (Sideport?)  Setuptools 0.7 will install these in place of
    32     the 2.3/2.4 versions (at least of pydoc and doctest) to let them work
    33     properly with eggs.  pkg_resources now depends on the 2.5 pkgutil, which
    34     is included here as _pkgutil, to work around the fact that some system
    35     packagers will install setuptools without overriding the stdlib modules.
    36     But users who install their own setuptools will get them, and the system
    37     packaged people probably don't need them.
    38     ------------------------------------------------------------------------
    39 
    40 
    41  * If unpatched setuptools decides that it needs to change an existing site.py
    42    file that appears not to have been written by it (because the file does not
    43    start with "def __boot():"), it aborts the installation.
    44    zetuptoolz leaves the file alone and outputs a warning, but continues with
    45    the installation.
    46 
    47 
    48  * The scripts written by zetuptoolz have the following extra line:
    49 
    50      # generated by zetuptoolz <version number>
    51 
    52    after the header.
    53 
    54 
    55  * Windows-specific changes (native Python):
    56 
    57    Python distributions may have command-line or GUI scripts.
    58    On Windows, setuptools creates an executable wrapper to run each
    59    script. zetuptools uses a different approach that does not require
    60    an .exe wrapper. It writes approximately the same script file that
    61    is used on other platforms, but with a .pyscript extension.
    62    It also writes a shell-script wrapper (without any extension) that
    63    is only used when the command is run from a Cygwin shell.
    64 
    65    Some of the advantages of this approach are:
    66 
    67     * Unicode arguments are preserved (although the program will
    68       need to use some Windows-specific code to get at them in
    69       current versions of Python);
    70     * it works correctly on 64-bit Windows;
    71     * the zetuptoolz distribution need not contain either any
    72       binary executables, or any C code that needs to be compiled.
    73 
    74    See setuptools\tests\win_script_wrapper.txt for further details.
    75 
    76    Installing or building any distribution on Windows will automatically
    77    associate .pyscript with the native Python interpreter for the current
    78    user. It will also add .pyscript and .pyw to the PATHEXT variable for
    79    the current user, which is needed to allow scripts to be run without
    80    typing any extension.
    81 
    82    There is an additional setup.py command that can be used to perform
    83    these steps separately (which isn't normally needed, but might be
    84    useful for debugging):
    85 
    86      python setup.py scriptsetup
    87 
    88    Adding the --allusers option, i.e.
    89 
    90      python setup.py scriptsetup --allusers
    91 
    92    will make the .pyscript association and changes to the PATHEXT variable
    93    for all users of this Windows installation, except those that have it
    94    overridden in their per-user environment. In this case setup.py must be
    95    run with Administrator privileges, e.g. from a Command Prompt whose
    96    shortcut has been set to run as Administrator.