[Python-checkins] python/nondist/sandbox/setuptools pkg_resources.py, 1.15, 1.16

pje@users.sourceforge.net pje at users.sourceforge.net
Mon May 23 04:17:55 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/setuptools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21643

Modified Files:
	pkg_resources.py 
Log Message:
Make AvailableDistributions check distributions for Python version
compatibility as well as platform compatibility.  Rename get_distro_source
to 'find_distributions', and get rid of intermediate distro-source objects.


Index: pkg_resources.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- pkg_resources.py	23 May 2005 02:00:42 -0000	1.15
+++ pkg_resources.py	23 May 2005 02:17:52 -0000	1.16
@@ -40,6 +40,7 @@
     """Invalid or unrecognized option name for a distribution"""
 
 _provider_factories = {}
+PY_MAJOR = sys.version[:3]
 
 def register_loader_type(loader_type, provider_factory):
     """Register `provider_factory` to make providers for `loader_type`
@@ -76,7 +77,6 @@
         return True     # easy case
 
     # XXX all the tricky cases go here
-
     return False
 
 
@@ -124,25 +124,16 @@
 class AvailableDistributions(object):
     """Searchable snapshot of distributions on a search path"""
 
-    def __init__(self, search_path=None, platform=get_platform()):
+    def __init__(self,search_path=None,platform=get_platform(),python=PY_MAJOR):
         """Snapshot distributions available on a search path
 
-        `search_path` should be a sequence of ``sys.path`` items.  If not
-        supplied, ``sys.path`` is used.
-
-        The `platform` is an optional string specifying the name of the
-        platform that platform-specific distributions must be compatible
-        with.  If not specified, it defaults to the current platform
-        (as defined by the result of ``get_platform()`` when ``pkg_resources``
-        was first imported.)
-
-        You may explicitly set `platform` to ``None`` if you wish to map *all*
-        distributions, not just those compatible with a single platform.
+        The constructor arguments are the same as those for the ``scan()``
+        method; see that method's documentation for details.
         """
 
         self._distmap = {}
         self._cache = {}
-        self.scan(search_path,platform)
+        self.scan(search_path,platform,python)
 
     def __iter__(self):
         """Iterate over distribution keys"""
@@ -162,7 +153,7 @@
         else:
             return default
 
-    def scan(self, search_path=None, platform=get_platform()):
+    def scan(self, search_path=None, platform=get_platform(), python=PY_MAJOR):
         """Scan `search_path` for distributions usable on `platform`
 
         Any distributions found are added to the distribution map.
@@ -170,19 +161,27 @@
         supplied, ``sys.path`` is used.  `platform` is an optional string
         specifying the name of the platform that platform-specific
         distributions must be compatible with.  If unspecified, it defaults to
-        the current platform.
+        the current platform.  `python` is an optional string naming the
+        desired version of Python (e.g. ``'2.4'``); it defaults to the current
+        version.
 
-        You may explicitly set `platform` to ``None`` if you wish to map *all*
-        distributions, not just those compatible with the running platform.
+        You may explicitly set `platform` (and/or `python`) to ``None`` if you
+        wish to map *all* distributions, not just those compatible with the
+        running platform or Python version.
         """
+
         if search_path is None:
             search_path = sys.path
+
         add = self.add
+
         for item in search_path:
-            source = get_distro_source(item)
-            for dist in source.iter_distributions(requirement):
+            for dist in find_distributions(item):
+                if python is not None and dist.py_version!=python:
+                    continue
                 if compatible_platforms(dist.platform, platform):
-                    add(dist)   # XXX should also check python version!
+                    add(dist)
+
 
     def __getitem__(self,key):
         """Return a newest-to-oldest list of distributions for the given key
@@ -190,6 +189,7 @@
         The returned list may be modified in-place, e.g. for narrowing down
         usable distributions.
         """
+
         try:
             return self._cache[key]
         except KeyError:
@@ -416,7 +416,7 @@
 
     XXX This doesn't work yet, because:
 
-        * get_distro_source() isn't implemented
+        * find_distributions() isn't implemented
         * AvailableDistributions.scan() is untested
 
     There may be other things missing as well, but this definitely won't work
@@ -641,8 +641,8 @@
     return StringIO(*args,**kw)
 
 
-def get_distro_source(path_item):
-    pass    # XXX
+def find_distributions(path_item):
+    return ()   # XXX
 
 
 
@@ -741,7 +741,7 @@
 
     def __init__(self,
         path_str, metadata=None, name=None, version=None,
-        py_version=sys.version[:3], platform=None
+        py_version=PY_MAJOR, platform=None
     ):
         if name:
             self.name = name.replace('_','-')



More information about the Python-checkins mailing list