Commits

Daniel Holth  committed 3ba6467 Draft

initial commit

  • Participants

Comments (0)

Files changed (6)

File CHANGES.txt

Empty file added.
+distlib2
+========
+
+distlib with a pkg_resources backend.
+
+pkg_resources implements .dist-info directories and the new packaging 
+standards. Why not implement the distlib API using pkg_resources as 
+the backend? The exercise should illuminate any incompatibilites between
+the two designs and make it easier to have a true separation between API
+and implementation.

File _distlib2/__init__.py

Empty file added.

File _distlib2/resources.py

+import pkg_resources
+
+class Resource(object):
+    def __init__(self, package, name):
+        self.package = package
+        self.name = name
+        
+    @property
+    def is_container(self):
+        return pkg_resources.resource_isdir(self.package, self.name)
+    
+    @property
+    def bytes(self):
+        return pkg_resources.resource_string(self.package, self.name)
+    
+    @property
+    def size(self):
+        return len(self.bytes)
+    
+    @property
+    def resources(self):
+        return pkg_resources.resource_listdir(self.package, self.name)
+    
+    def as_stream(self):
+        return pkg_resources.resource_stream(self.package, self.name)
+
+class ResourceFinder(object):
+    def __init__(self, package):
+        self.package = package
+    
+    def find(self, name):
+        if pkg_resources.resource_exists(self.package, name):
+            return Resource(name)
+        return None
+    
+    def is_container(self, rsc):
+        return rsc.is_container
+    
+    def get_stream(self, rsc):
+        return rsc.as_stream()
+    
+    def get_bytes(self, rsc):
+        return rsc.bytes
+    
+    def get_size(self, rsc):
+        return rsc.size
+        
+def finder(package):
+    return ResourceFinder(package)
+
+def register_finder(loader, finder_maker):
+    raise NotImplementedError()

File distlib/__init__.py

+import apipkg
+
+apipkg.initpkg(__name__, {
+        "resources": {
+                "Resource": "_distlib2.resources:Resource",
+                "Resource": "_distlib2.resources:ResourceFinder",
+                "finder": "_distlib2.resources:finder",
+                "register_finder": "_distlib2.resources:register_finder",
+            },
+        "database": {
+        }
+    }
+)
+import codecs
+import os
+
+from setuptools import setup
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = codecs.open(os.path.join(here, 'README.txt'), encoding='utf8').read()
+CHANGES = codecs.open(os.path.join(here, 'CHANGES.txt'), encoding='utf8').read()
+
+setup(name='distlib2',
+      version='0.0.0',
+      description='Another distlib',
+      long_description=README + '\n\n' +  CHANGES,
+      classifiers=[
+        "Intended Audience :: Developers",
+        "Programming Language :: Python",
+        "Programming Language :: Python :: 2",
+        "Programming Language :: Python :: 3",
+        ],
+      author='Daniel Holth',
+      author_email='dholth@fastmail.fm',
+      url='http://bitbucket.org/dholth/distlib2/',
+      keywords='packaging',
+      license='MIT',
+      packages=['distlib', '_distlib2'],
+      provides=['distlib'],
+      install_requires=['distribute', 'apipkg'],
+      include_package_data=True,
+      zip_safe=False,
+      test_suite = 'nose.collector',
+      )
+