[Checkins] SVN: z3c.recipe.autoinclude/t initial import

Nikolay Kim fafhrd at datacom.kz
Mon Apr 6 06:03:46 EDT 2009


Log message for revision 98914:
  initial import

Changed:
  A   z3c.recipe.autoinclude/tags/
  A   z3c.recipe.autoinclude/trunk/
  A   z3c.recipe.autoinclude/trunk/AUTHOR.txt
  A   z3c.recipe.autoinclude/trunk/CHANGES.txt
  A   z3c.recipe.autoinclude/trunk/LICENSE.txt
  A   z3c.recipe.autoinclude/trunk/bootstrap.py
  A   z3c.recipe.autoinclude/trunk/setup.py
  A   z3c.recipe.autoinclude/trunk/src/
  A   z3c.recipe.autoinclude/trunk/src/z3c/
  A   z3c.recipe.autoinclude/trunk/src/z3c/__init__.py
  A   z3c.recipe.autoinclude/trunk/src/z3c/recipe/
  A   z3c.recipe.autoinclude/trunk/src/z3c/recipe/__init__.py
  A   z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/
  A   z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/__init__.py
  A   z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/dependency.py
  A   z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/include.py

-=-
Added: z3c.recipe.autoinclude/trunk/AUTHOR.txt
===================================================================
--- z3c.recipe.autoinclude/trunk/AUTHOR.txt	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/AUTHOR.txt	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1 @@
+Nikolay Kim (fafhrd91 <at> gmail <dot> com)

Added: z3c.recipe.autoinclude/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.autoinclude/trunk/CHANGES.txt	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/CHANGES.txt	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1,9 @@
+=======
+CHANGES
+=======
+
+
+0.1.0 (2009-04-06)
+------------------
+
+- Initial release.

Added: z3c.recipe.autoinclude/trunk/LICENSE.txt
===================================================================
--- z3c.recipe.autoinclude/trunk/LICENSE.txt	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/LICENSE.txt	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1,54 @@
+Zope Public License (ZPL) Version 2.1
+-------------------------------------
+
+A copyright notice accompanies this license document that
+identifies the copyright holders.
+
+This license has been certified as open source. It has also
+been designated as GPL compatible by the Free Software
+Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions in source code must retain the
+   accompanying copyright notice, this list of conditions,
+   and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying
+   copyright notice, this list of conditions, and the
+   following disclaimer in the documentation and/or other
+   materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to
+   endorse or promote products derived from this software
+   without prior written permission from the copyright
+   holders.
+
+4. The right to distribute this software or to use it for
+   any purpose does not give you the right to use
+   Servicemarks (sm) or Trademarks (tm) of the copyright
+   holders. Use of them is covered by separate agreement
+   with the copyright holders.
+
+5. If any files are modified, you must cause the modified
+   files to carry prominent notices stating that you changed
+   the files and the date of any change.
+
+Disclaimer
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
+  AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+  NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+  NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+  DAMAGE.

Added: z3c.recipe.autoinclude/trunk/bootstrap.py
===================================================================
--- z3c.recipe.autoinclude/trunk/bootstrap.py	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/bootstrap.py	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+try:
+    import pkg_resources
+except ImportError:
+    ez = {}
+    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                         ).read() in ez
+    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+    import pkg_resources
+
+if sys.platform == 'win32':
+    def quote(c):
+        if ' ' in c:
+            return '"%s"' % c # work around spawn lamosity on windows
+        else:
+            return c
+else:
+    def quote (c):
+        return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws  = pkg_resources.working_set
+
+if is_jython:
+    import subprocess
+    
+    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd', 
+           quote(tmpeggs), 'zc.buildout'], 
+           env=dict(os.environ,
+               PYTHONPATH=
+               ws.find(pkg_resources.Requirement.parse('setuptools')).location
+               ),
+           ).wait() == 0
+
+else:
+    assert os.spawnle(
+        os.P_WAIT, sys.executable, quote (sys.executable),
+        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
+        dict(os.environ,
+            PYTHONPATH=
+            ws.find(pkg_resources.Requirement.parse('setuptools')).location
+            ),
+        ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)


Property changes on: z3c.recipe.autoinclude/trunk/bootstrap.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: z3c.recipe.autoinclude/trunk/setup.py
===================================================================
--- z3c.recipe.autoinclude/trunk/setup.py	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/setup.py	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Setup for z3c.recipe.autoinclude package
+
+$Id$
+"""
+import sys, os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+version='0.1.0dev'
+
+
+setup(name='z3c.recipe.autoinclude',
+      version=version,
+      description="Autoinclude packages zcml recipe",
+      long_description=(
+          'Detailed Documentation\n' +
+          '======================\n'
+          + '\n\n' +
+          read('CHANGES.txt')
+          ),
+      classifiers=[
+        'Development Status :: 5 - Production/Stable',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: Zope Public License',
+        'Programming Language :: Python',
+        'Natural Language :: English',
+        'Operating System :: OS Independent',
+        'Topic :: Internet :: WWW/HTTP',
+        'Framework :: Zope3'],
+      author='Nikolay Kim',
+      author_email='fafhrd91 at gmail.com',
+      license='ZPL 2.1',
+      packages=find_packages('src'),
+      package_dir = {'':'src'},
+      namespace_packages=['z3c', 'z3c.recipe'],
+      zip_safe = True,
+      install_requires = ['setuptools', 
+                          'zc.buildout',
+			  'zc.recipe.egg',
+                          ],
+      entry_points = {
+        'zc.buildout': [
+            'include = z3c.recipe.autoinclude.include:AutoIncludeSetup',
+            ]
+        },
+      )


Property changes on: z3c.recipe.autoinclude/trunk/setup.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:keywords
   + Id

Added: z3c.recipe.autoinclude/trunk/src/z3c/__init__.py
===================================================================
--- z3c.recipe.autoinclude/trunk/src/z3c/__init__.py	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/src/z3c/__init__.py	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1,6 @@
+# namespace package boilerplate
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError, e:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)


Property changes on: z3c.recipe.autoinclude/trunk/src/z3c/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: z3c.recipe.autoinclude/trunk/src/z3c/recipe/__init__.py
===================================================================
--- z3c.recipe.autoinclude/trunk/src/z3c/recipe/__init__.py	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/src/z3c/recipe/__init__.py	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1,6 @@
+# namespace package boilerplate
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError, e:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)


Property changes on: z3c.recipe.autoinclude/trunk/src/z3c/recipe/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/__init__.py
===================================================================
--- z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/__init__.py	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/__init__.py	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1 @@
+# make a package


Property changes on: z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/dependency.py
===================================================================
--- z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/dependency.py	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/dependency.py	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1,104 @@
+import os, sys, pkg_resources
+
+
+class DependencyFinder(object):
+
+    def __init__(self, dist, ws):
+        self.context = dist
+        self.ws = ws
+
+    def paths(self):
+        dist_path = self.context.location
+
+        ns_paths = []
+        for name in namespaceDottedNames(self.context):
+            ns_paths.append(os.path.join(*name.split('.')))
+
+        if not ns_paths:
+            return subpackageDottedNames(dist_path)
+
+        result = []
+        for ns_path in ns_paths:
+            path = os.path.join(dist_path, ns_path)
+            subpackages = subpackageDottedNames(path, ns_path)
+            for subpackage in subpackages:
+                if subpackage not in ns_paths:
+                    result.append(subpackage)
+        return result
+
+    def includableInfo(self, zcml_to_look_for, seen=None):
+        result = dict([(key, []) for key in zcml_to_look_for])
+        
+        if seen is None:
+            seen = set()
+
+        seen.add(self.context.project_name)
+
+        # process package requirenments
+        for req in self.context.requires():
+            pkg = req.project_name
+
+            if pkg in seen or pkg == 'setuptools':
+                continue
+
+            # get info from requirenments
+            dist = self.ws.find(req)
+            if dist is None:
+                continue
+
+            info = DependencyFinder(
+                self.ws.find(req), self.ws).includableInfo(zcml_to_look_for, seen)
+
+            for key, items in info.items():
+                data = result[key]
+                for item in items:
+                    if item not in data:
+                        data.append(item)
+
+        # get info for self
+        for path in self.paths():
+            for candidate in zcml_to_look_for:
+                candidate_path = os.path.join(
+                    self.context.location, path, candidate)
+
+                if os.path.isfile(candidate_path):
+                    result[candidate].append(self.context.project_name)
+
+        return result
+
+
+def subpackageDottedNames(package_path, ns_path=None):
+    # we do not look for subpackages in zipped eggs
+    if not os.path.isdir(package_path):
+        return []
+
+    result = []
+    for subpackage_name in os.listdir(package_path):
+        full_path = os.path.join(package_path, subpackage_name)
+        if isPythonPackage(full_path):
+            if ns_path:
+                result.append(os.path.join(ns_path, subpackage_name))
+            else:
+                result.append(subpackage_name)
+    return result
+
+
+def isPythonPackage(path):
+    if not os.path.isdir(path):
+        return False
+
+    for init_variant in ['__init__.py', '__init__.pyc', '__init__.pyo']:
+        if os.path.isfile(os.path.join(path, init_variant)):
+            return True
+
+    return False
+
+
+def namespaceDottedNames(dist):
+    try:
+        ns_dottednames = list(dist.get_metadata_lines('namespace_packages.txt'))
+    except IOError:
+        ns_dottednames = []
+    except KeyError:
+        ns_dottednames = []
+    return ns_dottednames


Property changes on: z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/dependency.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/include.py
===================================================================
--- z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/include.py	                        (rev 0)
+++ z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/include.py	2009-04-06 10:03:45 UTC (rev 98914)
@@ -0,0 +1,97 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""z3c autoinclude recipe
+
+$Id$
+"""
+import os
+import zc.buildout
+import zc.recipe.egg
+import pkg_resources
+from dependency import DependencyFinder
+
+
+class AutoIncludeSetup(object):
+
+    def __init__(self, buildout, name, options):
+        self.egg = None
+        self.buildout = buildout
+        self.name = name
+        self.options = options
+        self.location = options.get('location', 'packages.zcml')
+        self.egg = zc.recipe.egg.Eggs(buildout, name, options)
+
+    def install(self):
+        eggs, ws = self.egg.working_set()
+
+        dists = [ws.find(pkg_resources.Requirement.parse(spec)) for spec in eggs]
+
+        meta = []
+        configure = []
+        overrides = []
+
+        for dist in dists:
+            info = DependencyFinder(dist, ws).includableInfo(
+                ['meta.zcml', 'configure.zcml', 'overrides.zcml'])
+
+            for pkg in info['meta.zcml']:
+                if pkg not in meta:
+                    meta.append(pkg)
+
+            for pkg in info['configure.zcml']:
+                if pkg not in configure:
+                    configure.append(pkg)
+
+            for pkg in info['overrides.zcml']:
+                if pkg not in overrides:
+                    overrides.append(pkg)
+
+        meta = ''.join(
+            ['<include package="%s" file="meta.zcml" />\n'%pkg for pkg in meta])
+
+        configure = ''.join(
+            ['<include package="%s" />\n'%pkg for pkg in configure])
+
+        overrides = ''.join(
+            ['<includeOverrides package="%s" file="overrides.zcml" />\n'%pkg 
+             for pkg in overrides])
+
+        dest = []
+
+        location = self.location
+
+        if location and not os.path.exists(location):
+            os.mkdir(location)
+            dest.append(location)
+
+        open(os.path.join(location, 'packages-meta.zcml'), 'w').write(
+            packages_zcml_template % meta)
+
+        open(os.path.join(location, 'packages-configure.zcml'), 'w').write(
+            packages_zcml_template % configure)
+
+        open(os.path.join(location, 'packages-overrides.zcml'), 'w').write(
+            packages_zcml_template % overrides)
+
+        return dest
+
+    update = install
+
+
+packages_zcml_template = """\
+<configure xmlns="http://namespaces.zope.org/zope">
+
+%s
+</configure>
+"""


Property changes on: z3c.recipe.autoinclude/trunk/src/z3c/recipe/autoinclude/include.py
___________________________________________________________________
Added: svn:keywords
   + Id



More information about the Checkins mailing list