Commits

tarek  committed 3951efb

cleaning up

  • Participants
  • Parent commits 1267515

Comments (0)

Files changed (12)

File distribute.resources/distribute/resources/__init__.py

         from StringIO import StringIO
     return StringIO(*args,**kw)
 
-
-
-
-
 def _mkstemp(*args,**kw):
     from tempfile import mkstemp
     old_open = os.open
     finally:
         os.open = old_open  # and then put it back
 
-
 # Set up global resource manager
 _manager = ResourceManager()
 def _initialize(g):

File distribute.resources/distribute/resources/dist.py

 CHECKOUT_DIST = 0
 DEVELOP_DIST = -1
 
-
 class Distribution(object):
     """Wrap an actual or potential sys.path entry w/metadata"""
 
         from distribute.resources.providers import empty_provider
         self._provider = metadata or empty_provider
 
-    #@classmethod
+    @classmethod
     def from_location(cls,location,basename,metadata=None,**kw):
         project_name, version, py_version, platform = [None]*4
         basename, ext = os.path.splitext(basename)
             location, metadata, project_name=project_name, version=version,
             py_version=py_version, platform=platform, **kw
         )
-    from_location = classmethod(from_location)
 
     @property
     def hashcmp(self):
     # metadata until/unless it's actually needed.  (i.e., some distributions
     # may not know their name or version without loading PKG-INFO)
 
-    #@property
+    @property
     def key(self):
         try:
             return self._key
         except AttributeError:
             self._key = key = self.project_name.lower()
             return key
-    key = property(key)
 
-    #@property
+    @property
     def parsed_version(self):
         try:
             return self._parsed_version
             self._parsed_version = pv = parse_version(self.version)
             return pv
 
-    parsed_version = property(parsed_version)
-
-    #@property
+    @property
     def version(self):
         try:
             return self._version
                 raise ValueError(
                     "Missing 'Version:' header and/or PKG-INFO file", self
                 )
-    version = property(version)
 
-
-
-
-    #@property
+    @property
     def _dep_map(self):
         try:
             return self.__dep_map
                     if extra: extra = safe_extra(extra)
                     dm.setdefault(extra,[]).extend(parse_requirements(reqs))
             return dm
-    _dep_map = property(_dep_map)
 
     def requires(self,extras=()):
         """List of Requirements needed for this distro if `extras` are used"""
             raise AttributeError,attr
         return getattr(self._provider, attr)
 
-    #@classmethod
+    @classmethod
     def from_filename(cls,filename,metadata=None, **kw):
         return cls.from_location(
             normalize_cached(filename), os.path.basename(filename), metadata,
             **kw
         )
-    from_filename = classmethod(from_filename)
 
     def as_requirement(self):
         """Return a ``Requirement`` that matches this distribution exactly"""
         """Return the EntryPoint object for `group`+`name`, or ``None``"""
         return self.get_entry_map(group).get(name)
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     def insert_on(self, path, loc = None):
         """Insert self.location in path before its nearest parent directory"""
 
             else:
                 del npath[np], path[np]
                 p = np  # ha!
-
         return
 
 
-
     def check_version_conflict(self):
         if self.key=='distribute':
             return      # ignore the inevitable setuptools self-conflicts  :(
         kw.setdefault('metadata', self._provider)
         return self.__class__(**kw)
 
-
-
-
-    #@property
+    @property
     def extras(self):
         return [dep for dep in self._dep_map if dep]
-    extras = property(extras)
 
-

File distribute.resources/distribute/resources/entrypoint.py

-__all__ = ['EntryPoint', 'load_entry_point',
-           'get_entry_map', 'get_entry_info']
-
 from distribute.resources.util import (MODULE, yield_lines, split_sections,
                                       compatible_platforms)
 from distribute.resources.requirement import Requirement
     """Return the EntryPoint object for `group`+`name`, or ``None``"""
     return get_distribution(dist).get_entry_info(group, name)
 
-
-
 class EntryPoint(object):
     """Object representing an advertised importable object"""
 
         for entry in entries:
             working_set.add(entry)
 
-    #@classmethod
+    @classmethod
     def parse(cls, src, dist=None):
         """Parse a single entry point from string `src`
 
         else:
             return cls(name.strip(), value.strip(), attrs, extras, dist)
 
-    parse = classmethod(parse)
-
-
-
-
-
-
-
-
-    #@classmethod
+    @classmethod
     def parse_group(cls, group, lines, dist=None):
         """Parse an entry point group"""
         if not MODULE(group):
             this[ep.name]=ep
         return this
 
-    parse_group = classmethod(parse_group)
-
-    #@classmethod
+    @classmethod
     def parse_map(cls, data, dist=None):
         """Parse a map of entry point groups"""
         if isinstance(data,dict):
             maps[group] = cls.parse_group(group, lines, dist)
         return maps
 
-    parse_map = classmethod(parse_map)
-
-
-
-

File distribute.resources/distribute/resources/environment.py

 from distribute.resources.util import compatible_platforms
 from distribute.resources.exceptions import VersionConflict
 
-
 def _sort_dists(dists):
     tmp = [(dist.hashcmp,dist) for dist in dists]
     tmp.sort()
     dists[::-1] = [d for hc,d in tmp]
 
-
-
 class Environment(object):
     """Searchable snapshot of distributions on a search path"""
 
-    def __init__(self, search_path=None, platform=get_supported_platform(), python=PY_MAJOR):
+    def __init__(self, search_path=None, platform=get_supported_platform(),
+                 python=PY_MAJOR):
         """Snapshot distributions available on a search path
 
         Any distributions found on `search_path` are added to the environment.
                 if dist.key in self._cache:
                     _sort_dists(self._cache[dist.key])
 
-
     def best_match(self, req, working_set, installer=None):
         """Find distribution best matching `req` and usable on `working_set`
 
     def __iter__(self):
         """Yield the unique project names of the available distributions"""
         for key in self._distmap.keys():
-            if self[key]: yield key
-
-
-
+            if self[key]:
+                yield key
 
     def __iadd__(self, other):
         """In-place addition of a distribution or environment"""
             new += env
         return new
 
-
-AvailableDistributions = Environment    # XXX backward compatibility
-
-

File distribute.resources/distribute/resources/exceptions.py

-
-__all__ = ['ResolutionError', 'VersionConflict', 'DistributionNotFound',
-           'UnknownExtra', 'ExtractionError']
 
 class ResolutionError(Exception):
     """Abstract base for dependency resolution errors"""

File distribute.resources/distribute/resources/importers.py

-
-class ImpWrapper:
-    """PEP 302 Importer that wraps Python's "normal" import algorithm"""
-
-    def __init__(self, path=None):
-        self.path = path
-
-    def find_module(self, fullname, path=None):
-        subname = fullname.split(".")[-1]
-        if subname != fullname and self.path is None:
-            return None
-        if self.path is None:
-            path = None
-        else:
-            path = [self.path]
-        try:
-            file, filename, etc = imp.find_module(subname, path)
-        except ImportError:
-            return None
-        return ImpLoader(file, filename, etc)
-
-
-class ImpLoader:
-    """PEP 302 Loader that wraps Python's "normal" import algorithm"""
-
-    def __init__(self, file, filename, etc):
-        self.file = file
-        self.filename = filename
-        self.etc = etc
-
-    def load_module(self, fullname):
-        try:
-            mod = imp.load_module(fullname, self.file, self.filename, self.etc)
-        finally:
-            if self.file: self.file.close()
-        # Note: we don't set __loader__ because we want the module to look
-        # normal; i.e. this is just a wrapper for standard import machinery
-        return mod
-
-
-
-
-def get_importer(path_item):
-    """Retrieve a PEP 302 "importer" for the given path item
-
-    If there is no importer, this returns a wrapper around the builtin import
-    machinery.  The returned importer is only cached if it was created by a
-    path hook.
-    """
-    try:
-        importer = sys.path_importer_cache[path_item]
-    except KeyError:
-        for hook in sys.path_hooks:
-            try:
-                importer = hook(path_item)
-            except ImportError:
-                pass
-            else:
-                break
-        else:
-            importer = None
-
-    sys.path_importer_cache.setdefault(path_item,importer)
-    if importer is None:
-        try:
-            importer = ImpWrapper(path_item)
-        except ImportError:
-            pass
-    return importer
-
-try:
-    from pkgutil import get_importer, ImpImporter
-except ImportError:
-    pass    # Python 2.3 or 2.4, use our own implementation
-else:
-    ImpWrapper = ImpImporter    # Python 2.5, use pkgutil's implementation
-    del ImpLoader, ImpImporter
-
-

File distribute.resources/distribute/resources/manager.py

+
 class ResourceManager:
     """Manage resource extraction and packages"""
     extraction_path = None
         err.original_error = old_exc
         raise err
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     def get_cache_path(self, archive_name, names=()):
         """Return absolute location in cache for `archive_name` and `names`
 
         self.cached_files[target_path] = 1
         return target_path
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     def postprocess(self, tempname, filename):
         """Perform any platform-specific postprocessing of `tempname`
 
             mode = ((os.stat(tempname).st_mode) | 0555) & 07777
             os.chmod(tempname, mode)
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     def set_extraction_path(self, path):
         """Set the base path where resources will be extracted to, if needed.
 
         """
         # XXX
 
-
-
-

File distribute.resources/distribute/resources/namespace.py

 import sys
 import os
 
-from distribute.resources.importers import ImpWrapper, get_importer
+from pkgutil import get_importer, ImpImporter
 from distribute.resources.util import find_adapter, normalize_cached
 
 _namespace_handlers = {}
         # Only return the path if it's not already there
         return subpath
 
-register_namespace_handler(ImpWrapper, file_ns_handler)
+register_namespace_handler(ImpImporter, file_ns_handler)
 register_namespace_handler(zipimport.zipimporter,file_ns_handler)
 
 
         parent = '.'.join(parts)
         setattr(sys.modules[parent], name, sys.modules[packageName])
 
-
-

File distribute.resources/distribute/resources/providers.py

 
 import os
 import zipimport
-from distribute.resources.importers import ImpWrapper, get_importer
+
+from pkgutil import get_importer, ImpImporter
 from distribute.resources.util import normalize_path
 from distribute.resources.dist import Distribution, DEVELOP_DIST
 from distribute.resources.util import normalize_cached, yield_lines
     def run_script(script_name, namespace):
         """Execute the named script in the supplied namespace dictionary"""
 
-
-
-
-
-
-
-
-
-
 class IResourceProvider(IMetadataProvider):
     """An object that provides access to package resources"""
 
 register_loader_type(object, NullProvider)
 
 
-
 class EmptyProvider(NullProvider):
     """Provider that returns nothing for all requests"""
 
 register_finder(zipimport.zipimporter, find_in_zip)
 
 
-
-
 def find_nothing(importer, path_item, only=False):
     return ()
 
                             yield item
                         break
 
-register_finder(ImpWrapper, find_on_path)
+register_finder(ImpImporter, find_on_path)
 
 

File distribute.resources/distribute/resources/requirement.py

 
     def __repr__(self): return "Requirement.parse(%r)" % str(self)
 
-    #@staticmethod
+    @staticmethod
     def parse(s):
         reqs = list(parse_requirements(s))
         if reqs:
             raise ValueError("Expected only one requirement", s)
         raise ValueError("No requirements found", s)
 
-    parse = staticmethod(parse)
 
 def parse_requirements(strs):
     """Yield ``Requirement`` objects for each specification in `strs`
         specs = [(op,safe_version(val)) for op,val in specs]
         yield Requirement(project_name, specs, extras)
 
-
-

File distribute.resources/distribute/resources/util.py

             for s in yield_lines(ss):
                 yield s
 
-
 def safe_name(name):
     """Convert an arbitrary string to a standard distribution name
 
     """
     return re.sub('[^A-Za-z0-9.]+', '-', name)
 
-
 def safe_version(version):
     """Convert an arbitrary string to a standard version string
 
     version = version.replace(' ','.')
     return re.sub('[^A-Za-z0-9.]+', '-', version)
 
-
 def safe_extra(extra):
     """Convert an arbitrary string to a standard 'extra' name
 
     """
     return re.sub('[^A-Za-z0-9.]+', '_', extra).lower()
 
-
 def to_filename(name):
     """Convert a project or version name to its filename-escaped form
 
     """
     return name.replace('-','_')
 
-
 def ensure_directory(path):
     """Ensure that the parent directory of `path` exists"""
     dirname = os.path.dirname(path)
     from warnings import warn
     warn(stacklevel = level+1, *args, **kw)
 
-
-
 def get_default_cache():
     """Determine the default cache location
 
         )
 
 
-

File distribute.resources/distribute/resources/workingset.py

 
 
 import sys
+
 from distribute.resources.providers import find_distributions
 from distribute.resources.requirement import parse_requirements
 from distribute.resources.exceptions import DistributionNotFound
         for entry in entries:
             self.add_entry(entry)
 
-
     def add_entry(self, entry):
         """Add a path item to ``.entries``, finding any distributions on it
 
         for dist in find_distributions(entry, True):
             self.add(dist, entry, False)
 
-
     def __contains__(self,dist):
         """True if `dist` is the active distribution for its project"""
         return self.by_key.get(dist.key) == dist
 
-
-
-
-
     def find(self, req):
         """Find a distribution matching requirement `req`
 
         ns['__name__'] = name
         self.require(requires)[0].run_script(script_name, ns)
 
-
-
     def __iter__(self):
         """Yield distributions for non-duplicate projects in the working set
 
         already-installed distribution; it should return a ``Distribution`` or
         ``None``.
         """
-
         requirements = list(requirements)[::-1]  # set up the stack
         processed = {}  # set of processed requirements
         best = {}  # key -> dist
 
         distributions = list(distributions)
         distributions.sort()
-
         return distributions, error_info
 
-
-
-
-
     def require(self, *requirements):
         """Ensure that distributions matching `requirements` are activated
 
         activated to fulfill the requirements; all relevant distributions are
         included, even if they were already activated in this working set.
         """
-
         needed = self.resolve(parse_requirements(requirements))
-
         for dist in needed:
             self.add(dist)
-
         return needed
 
-
     def subscribe(self, callback):
         """Invoke `callback` for all distributions (including existing ones)"""
         if callback in self.callbacks:
         for dist in self:
             callback(dist)
 
-
     def _added_new(self, dist):
         for callback in self.callbacks:
             callback(dist)
 
 
-