Commit 57f7bd7e authored by PJ Eby's avatar PJ Eby

Renamed AvailableDistributions -> Environment. Add sketch of pkg_resources

manual outline.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041184
parent 899e59ff
...@@ -52,7 +52,7 @@ __all__ = [ ...@@ -52,7 +52,7 @@ __all__ = [
'get_default_cache', 'get_default_cache',
# Primary implementation classes # Primary implementation classes
'AvailableDistributions', 'WorkingSet', 'ResourceManager', 'Environment', 'WorkingSet', 'ResourceManager',
'Distribution', 'Requirement', 'EntryPoint', 'Distribution', 'Requirement', 'EntryPoint',
# Exceptions # Exceptions
...@@ -76,7 +76,7 @@ __all__ = [ ...@@ -76,7 +76,7 @@ __all__ = [
'fixup_namespace_packages', 'get_importer', 'fixup_namespace_packages', 'get_importer',
# Deprecated/backward compatibility only # Deprecated/backward compatibility only
'run_main', 'run_main', 'AvailableDistributions',
] ]
...@@ -453,7 +453,7 @@ class WorkingSet(object): ...@@ -453,7 +453,7 @@ class WorkingSet(object):
"""List all distributions needed to (recursively) meet `requirements` """List all distributions needed to (recursively) meet `requirements`
`requirements` must be a sequence of ``Requirement`` objects. `env`, `requirements` must be a sequence of ``Requirement`` objects. `env`,
if supplied, should be an ``AvailableDistributions`` instance. If if supplied, should be an ``Environment`` instance. If
not supplied, it defaults to all distributions available within any not supplied, it defaults to all distributions available within any
entry or distribution in the working set. `installer`, if supplied, entry or distribution in the working set. `installer`, if supplied,
will be invoked with each requirement that cannot be met by an will be invoked with each requirement that cannot be met by an
...@@ -476,7 +476,7 @@ class WorkingSet(object): ...@@ -476,7 +476,7 @@ class WorkingSet(object):
if dist is None: if dist is None:
# Find the best distribution and add it to the map # Find the best distribution and add it to the map
if env is None: if env is None:
env = AvailableDistributions(self.entries) env = Environment(self.entries)
dist = best[req.key] = env.best_match(req, self, installer) dist = best[req.key] = env.best_match(req, self, installer)
if dist is None: if dist is None:
raise DistributionNotFound(req) # XXX put more info here raise DistributionNotFound(req) # XXX put more info here
...@@ -531,7 +531,7 @@ class WorkingSet(object): ...@@ -531,7 +531,7 @@ class WorkingSet(object):
class AvailableDistributions(object): class Environment(object):
"""Searchable snapshot of distributions on a search path""" """Searchable snapshot of distributions on a search path"""
def __init__(self,search_path=None,platform=get_platform(),python=PY_MAJOR): def __init__(self,search_path=None,platform=get_platform(),python=PY_MAJOR):
...@@ -645,7 +645,6 @@ class AvailableDistributions(object): ...@@ -645,7 +645,6 @@ class AvailableDistributions(object):
return self.obtain(req, installer) # try and download/install return self.obtain(req, installer) # try and download/install
def obtain(self, requirement, installer=None): def obtain(self, requirement, installer=None):
"""Obtain a distro that matches requirement (e.g. via download)""" """Obtain a distro that matches requirement (e.g. via download)"""
if installer is not None: if installer is not None:
...@@ -653,6 +652,7 @@ class AvailableDistributions(object): ...@@ -653,6 +652,7 @@ class AvailableDistributions(object):
def __len__(self): return len(self._distmap) def __len__(self): return len(self._distmap)
AvailableDistributions = Environment # XXX backward compatibility
class ResourceManager: class ResourceManager:
"""Manage resource extraction and packages""" """Manage resource extraction and packages"""
......
=============================================================
Package Discovery and Resource Access using ``pkg_resources``
=============================================================
The ``pkg_resources`` module, distributed with ``setuptools``, provides
features for Python libraries to access resource files, and for extensible
applications and frameworks to automatically discover plugins. It also
provides runtime support for using C extensions that are inside zipfile
eggs, support for merging packages that have separately-distributed modules or
subpackages, and APIs for managing Python's current "working set" of active
packages.
.. contents:: **Table of Contents**
--------
Overview
--------
XXX
-----------------
Developer's Guide
-----------------
Accessing Resources
Finding and Activating Package Distributions
get_provider()
require()
WorkingSet
iter_distributions
Running Scripts
Configuration
Namespace Packages
Extensible Applications and Frameworks
Locating entry points
Activation listeners
Metadata access
Extended Discovery and Installation
Supporting Custom PEP 302 Implementations
-------------
API Reference
-------------
``WorkingSet`` Objects
======================
Listeners
``Environment`` Objects
=======================
XXX
``EntryPoint`` Objects
======================
XXX
``Requirement`` Objects
=======================
XXX Syntax, parse_requirments, Requirement.parse, etc.
``Distribution`` Objects
========================
XXX
``ResourceManager`` Objects
===========================
XXX
Exceptions
==========
XXX ResolutionError, VersionConflict, DistributionNotFound, UnknownExtra
Utility Functions
=================
Parsing Utilities
-----------------
yield_lines
XXX
split_sections
XXX
parse_version
XXX
safe_name
XXX
safe_version
XXX
Platform Utilities
------------------
get_platform
XXX
compatible_platforms
XXX
File/Path Utilities
-------------------
ensure_directory
XXX
normalize_path
XXX
...@@ -51,6 +51,12 @@ Feature Highlights: ...@@ -51,6 +51,12 @@ Feature Highlights:
* Deploy your project in "development mode", such that it's available on * Deploy your project in "development mode", such that it's available on
``sys.path``, yet can still be edited directly from its source checkout. ``sys.path``, yet can still be edited directly from its source checkout.
* Easily extend the distutils with new commands or ``setup()`` arguments, and
distribute/reuse your extensions for multiple projects, without copying code.
* Create extensible applications and frameworks that automatically discover
extensions, using simple "entry points" declared in a project's setup script.
.. contents:: **Table of Contents** .. contents:: **Table of Contents**
...@@ -1846,7 +1852,9 @@ Release Notes/Change History ...@@ -1846,7 +1852,9 @@ Release Notes/Change History
that tells it to only yield distributions whose location is the passed-in that tells it to only yield distributions whose location is the passed-in
path. (It defaults to False, so that the default behavior is unchanged.) path. (It defaults to False, so that the default behavior is unchanged.)
* The ``resolve()`` method of ``AvailableDistributions`` is now a method of * ``AvailableDistributions`` is now called ``Environment``
* The ``resolve()`` method of ``Environment`` is now a method of
``WorkingSet`` instead, and the ``best_match()`` method now uses a working ``WorkingSet`` instead, and the ``best_match()`` method now uses a working
set instead of a path list as its second argument. set instead of a path list as its second argument.
......
...@@ -181,7 +181,7 @@ class easy_install(Command): ...@@ -181,7 +181,7 @@ class easy_install(Command):
self.package_index = self.create_index( self.package_index = self.create_index(
self.index_url, search_path = self.shadow_path self.index_url, search_path = self.shadow_path
) )
self.local_index = AvailableDistributions(self.shadow_path) self.local_index = Environment(self.shadow_path)
if self.find_links is not None: if self.find_links is not None:
if isinstance(self.find_links, basestring): if isinstance(self.find_links, basestring):
...@@ -805,7 +805,7 @@ See the setuptools documentation for the "develop" command for more info. ...@@ -805,7 +805,7 @@ See the setuptools documentation for the "develop" command for more info.
try: try:
args.append(dist_dir) args.append(dist_dir)
self.run_setup(setup_script, setup_base, args) self.run_setup(setup_script, setup_base, args)
all_eggs = AvailableDistributions([dist_dir]) all_eggs = Environment([dist_dir])
eggs = [] eggs = []
for key in all_eggs: for key in all_eggs:
for dist in all_eggs[key]: for dist in all_eggs[key]:
...@@ -1064,14 +1064,14 @@ def parse_requirement_arg(spec): ...@@ -1064,14 +1064,14 @@ def parse_requirement_arg(spec):
class PthDistributions(AvailableDistributions): class PthDistributions(Environment):
"""A .pth file with Distribution paths in it""" """A .pth file with Distribution paths in it"""
dirty = False dirty = False
def __init__(self, filename): def __init__(self, filename):
self.filename = filename; self._load() self.filename = filename; self._load()
AvailableDistributions.__init__( Environment.__init__(
self, list(yield_lines(self.paths)), None, None self, list(yield_lines(self.paths)), None, None
) )
...@@ -1109,13 +1109,13 @@ class PthDistributions(AvailableDistributions): ...@@ -1109,13 +1109,13 @@ class PthDistributions(AvailableDistributions):
"""Add `dist` to the distribution map""" """Add `dist` to the distribution map"""
if dist.location not in self.paths: if dist.location not in self.paths:
self.paths.append(dist.location); self.dirty = True self.paths.append(dist.location); self.dirty = True
AvailableDistributions.add(self,dist) Environment.add(self,dist)
def remove(self,dist): def remove(self,dist):
"""Remove `dist` from the distribution map""" """Remove `dist` from the distribution map"""
while dist.location in self.paths: while dist.location in self.paths:
self.paths.remove(dist.location); self.dirty = True self.paths.remove(dist.location); self.dirty = True
AvailableDistributions.remove(self,dist) Environment.remove(self,dist)
def main(argv, **kw): def main(argv, **kw):
......
...@@ -121,11 +121,11 @@ def interpret_distro_name(location, basename, metadata, ...@@ -121,11 +121,11 @@ def interpret_distro_name(location, basename, metadata,
class PackageIndex(AvailableDistributions): class PackageIndex(Environment):
"""A distribution index that scans web pages for download URLs""" """A distribution index that scans web pages for download URLs"""
def __init__(self,index_url="http://www.python.org/pypi",*args,**kw): def __init__(self,index_url="http://www.python.org/pypi",*args,**kw):
AvailableDistributions.__init__(self,*args,**kw) Environment.__init__(self,*args,**kw)
self.index_url = index_url + "/"[:not index_url.endswith('/')] self.index_url = index_url + "/"[:not index_url.endswith('/')]
self.scanned_urls = {} self.scanned_urls = {}
self.fetched_urls = {} self.fetched_urls = {}
......
...@@ -23,7 +23,7 @@ class DistroTests(TestCase): ...@@ -23,7 +23,7 @@ class DistroTests(TestCase):
def testCollection(self): def testCollection(self):
# empty path should produce no distributions # empty path should produce no distributions
ad = AvailableDistributions([], python=None) ad = Environment([], python=None)
self.assertEqual(list(ad), []) self.assertEqual(list(ad), [])
self.assertEqual(len(ad),0) self.assertEqual(len(ad),0)
self.assertEqual(ad.get('FooPkg'),None) self.assertEqual(ad.get('FooPkg'),None)
...@@ -122,7 +122,7 @@ class DistroTests(TestCase): ...@@ -122,7 +122,7 @@ class DistroTests(TestCase):
def testResolve(self): def testResolve(self):
ad = AvailableDistributions([]); ws = WorkingSet([]) ad = Environment([]); ws = WorkingSet([])
# Resolving no requirements -> nothing to install # Resolving no requirements -> nothing to install
self.assertEqual( list(ws.resolve([],ad)), [] ) self.assertEqual( list(ws.resolve([],ad)), [] )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment