Vinay Sajip avatar Vinay Sajip committed 38c4668

Tweaked DistPathLocator, updated documentation.

Comments (0)

Files changed (4)

distlib/locators.py

         return result
 
 class DistPathLocator(Locator):
-    def __init__(self, path, **kwargs):
+    def __init__(self, distpath, **kwargs):
         super(DistPathLocator, self).__init__(**kwargs)
-        assert isinstance(path, DistributionPath)
-        self.path = path
+        assert isinstance(distpath, DistributionPath)
+        self.distpath = distpath
 
     def _get_project(self, name):
-        dist = self.path.get_distribution(name)
+        dist = self.distpath.get_distribution(name)
         if dist is None:
-            result = None
+            result = {}
         else:
             result = { dist.version: dist }
         return result

docs/reference.rst

 
    The base class for locators. Implements logic common to multiple locators.
 
+   .. method:: __init__(scheme='default')
+
+      Initialise an instance of the locator.
+      :param scheme: The version scheme to use.
+      :type scheme: str
+
    .. method:: get_project(name)
 
       This method should be implemented in subclasses. It returns a
    This locator scans the file system under a base directory, looking for
    distribution archives.
 
-   .. method:: __init__(base_dir)
+   .. method:: __init__(base_dir, **kwargs)
 
       :param base_dir: The base directory to scan for distribution archives.
       :type base_dir: str
+      :param  kwargs: Passed to base class constructor.
 
 .. class:: PyPIRPCLocator(Locator)
 
    This locator uses the PyPI XML-RPC interface to locate distribution
    archives and other data about downloads.
 
-   .. method:: __init__(url)
+   .. method:: __init__(url, **kwargs)
 
       :param url: The base URL to use for the XML-RPC service.
       :type url: str
+      :param  kwargs: Passed to base class constructor.
 
     .. method:: get_project(name)
 
    information in a single call, so it should perform better than the
    XML-RPC locator.
 
-   .. method:: __init__(url)
+   .. method:: __init__(url, **kwargs)
 
       :param url: The base URL to use for the JSON service.
       :type url: str
+      :param  kwargs: Passed to base class constructor.
 
     .. method:: get_project(name)
 
    This locator uses the PyPI 'simple' interface -- a Web scraping interface --
    to locate distribution archives.
 
-   .. method:: __init__(url)
+   .. method:: __init__(url, timeout=None, num_workers=10, **kwargs)
 
       :param url: The base URL to use for the simple service HTML pages.
       :type url: str
+      :param timeout: How long (in seconds) to wait before giving up on a
+                      remote resource.
+      :type timeout: float
+      :param num_workers: The number of worker threads created to perform
+                          scraping activities.
+      :type num_workers: int
+      :param  kwargs: Passed to base class constructor.
+
+
+.. class:: DistPathLocator
+
+   This locator uses a :class:`DistributionPath` instance to locate installed
+   distributions.
+
+   .. method:: __init__(url, distpath, **kwargs)
+
+      :param distpath: The distribution path to use.
+      :type distpath: :class:`DistributionPath`
+      :param  kwargs: Passed to base class constructor.
 
 
 .. class:: AggregatingLocator(Locator)
    aggregator in the list provided which returns a non-empty result), or a
    merged result from all the aggregators in the list.
 
-   .. method:: __init__(*locators, merge=False)
+   .. method:: __init__(*locators, **kwargs)
 
       :param locators: A list of aggregators to delegate finding projects to.
       :type locators: sequence of locators
-      :param merge: If ``True``, each aggregator in the list is asked to
-                    provide results, which are aggregated into a results
-                    dictionary. If ``False``, the first non-empty return value
-                    from the list of aggregators is returned. The aggregators
-                    are consulted in the order in which they're passed in.
+      :param merge: If this *kwarg* is ``True``, each aggregator in the list is
+                    asked to provide results, which are aggregated into a
+                    results dictionary. If ``False``, the first non-empty
+                    return value from the list of aggregators is returned.
+                    The locators are consulted in the order in which they're
+                    passed in.
       :type merge: bool
 
 
+.. class:: DependencyFinder
+
+   This class allows you to recursively find all the distributions which a
+   particular distribution depends on.
+
+   .. method:: __init__(locator)
+
+      Initialise an instance with the locator to be used for locating
+      distributions.
+
+   .. method:: find(requirement)
+
 Functions
 ^^^^^^^^^
 

docs/tutorial.rst

 scripts based on Python callables.
 
 
-Using the dependency API
-^^^^^^^^^^^^^^^^^^^^^^^^
+Distribution dependencies
+^^^^^^^^^^^^^^^^^^^^^^^^^
 
-You can use the ``distlib.depgraph`` package to analyse the dependencies
-between various distributions and to create a graph representing these
-dependency relationships. The main interface is through the following
-functions:
+You can use the ``distlib.locators`` package to locate the dependencies that
+a distribution has. The ``distlib.database`` package has code which
+allow you to analyse the relationships between a set of distributions:
 
 * :func:`make_graph`, which generates a dependency graph from a list of
   distributions.
   ``PackageFinder`` class in ``pip``, or as documented in the ``setuptools``
   documentation as the approach used by ``easy_install``.
 
+* :class:`DistPathLocator` -- this takes a :class:`DistributionPath` instance
+  and locates installed distributions. This can be used with
+  :class:`AggregatingLocator` to satisfy requirements from installed
+  distributions before looking elsewhere for them.
+
 * :class:`AggregatingLocator` -- this takes a list of other aggregators and
   delegates finding projects to them. It can either return the first result
   found (i.e. from the first aggregator in the list provided which returns a

tests/test_locators.py

                 r = locator.get_project(name)
                 self.assertIsNotNone(d)
                 self.assertEqual(r, { d.version: d })
+            d = locator.locate('nonexistent')
+            r = locator.get_project('nonexistent')
+            self.assertIsNone(d)
+            self.assertFalse(r)
+
         finally:
             sys.path.pop(0)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.