z3c.autoinclude-0.3.5/.gitignore 0000644 0000000 0000000 00000000131 12214252576 014650 0 ustar 0000000 0000000 bin
build
develop-eggs
dist
lib
include
man
parts
__pycache__
.*
*.dll
*.pyc
*.pyo
*.so
z3c.autoinclude-0.3.5/.travis.yml 0000644 0000000 0000000 00000000224 12214252576 014774 0 ustar 0000000 0000000 language: python
python:
- 2.7
install:
- python bootstrap.py
- bin/buildout
script:
- bin/test -v1
notifications:
email: false
z3c.autoinclude-0.3.5/bootstrap.py 0000644 0000000 0000000 00000024435 12214252576 015264 0 ustar 0000000 0000000 ##############################################################################
#
# Copyright (c) 2006 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.
#
##############################################################################
"""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.
"""
import os, shutil, sys, tempfile, urllib, urllib2, subprocess
from optparse import OptionParser
if sys.platform == 'win32':
def quote(c):
if ' ' in c:
return '"%s"' % c # work around spawn lamosity on windows
else:
return c
else:
quote = str
# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
stdout, stderr = subprocess.Popen(
[sys.executable, '-Sc',
'try:\n'
' import ConfigParser\n'
'except ImportError:\n'
' print 1\n'
'else:\n'
' print 0\n'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
has_broken_dash_S = bool(int(stdout.strip()))
# In order to be more robust in the face of system Pythons, we want to
# run without site-packages loaded. This is somewhat tricky, in
# particular because Python 2.6's distutils imports site, so starting
# with the -S flag is not sufficient. However, we'll start with that:
if not has_broken_dash_S and 'site' in sys.modules:
# We will restart with python -S.
args = sys.argv[:]
args[0:0] = [sys.executable, '-S']
args = map(quote, args)
os.execv(sys.executable, args)
# Now we are running with -S. We'll get the clean sys.path, import site
# because distutils will do it later, and then reset the path and clean
# out any namespace packages from site-packages that might have been
# loaded by .pth files.
clean_path = sys.path[:]
import site # imported because of its side effects
sys.path[:] = clean_path
for k, v in sys.modules.items():
if k in ('setuptools', 'pkg_resources') or (
hasattr(v, '__path__') and
len(v.__path__) == 1 and
not os.path.exists(os.path.join(v.__path__[0], '__init__.py'))):
# This is a namespace package. Remove it.
sys.modules.pop(k)
is_jython = sys.platform.startswith('java')
setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
distribute_source = 'http://python-distribute.org/distribute_setup.py'
# parsing arguments
def normalize_to_url(option, opt_str, value, parser):
if value:
if '://' not in value: # It doesn't smell like a URL.
value = 'file://%s' % (
urllib.pathname2url(
os.path.abspath(os.path.expanduser(value))),)
if opt_str == '--download-base' and not value.endswith('/'):
# Download base needs a trailing slash to make the world happy.
value += '/'
else:
value = None
name = opt_str[2:].replace('-', '_')
setattr(parser.values, name, value)
usage = '''\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
Bootstraps a buildout-based project.
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
Note that by using --setup-source and --download-base to point to
local resources, you can keep this script from going over the network.
'''
parser = OptionParser(usage=usage)
parser.add_option("-v", "--version", dest="version",
help="use a specific zc.buildout version")
parser.add_option("-d", "--distribute",
action="store_true", dest="use_distribute", default=False,
help="Use Distribute rather than Setuptools.")
parser.add_option("--setup-source", action="callback", dest="setup_source",
callback=normalize_to_url, nargs=1, type="string",
help=("Specify a URL or file location for the setup file. "
"If you use Setuptools, this will default to " +
setuptools_source + "; if you use Distribute, this "
"will default to " + distribute_source + "."))
parser.add_option("--download-base", action="callback", dest="download_base",
callback=normalize_to_url, nargs=1, type="string",
help=("Specify a URL or directory for downloading "
"zc.buildout and either Setuptools or Distribute. "
"Defaults to PyPI."))
parser.add_option("--eggs",
help=("Specify a directory for storing eggs. Defaults to "
"a temporary directory that is deleted when the "
"bootstrap script completes."))
parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
help=("Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
parser.add_option("-c", None, action="store", dest="config_file",
help=("Specify the path to the buildout configuration "
"file to be used."))
options, args = parser.parse_args()
if options.eggs:
eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))
else:
eggs_dir = tempfile.mkdtemp()
if options.setup_source is None:
if options.use_distribute:
options.setup_source = distribute_source
else:
options.setup_source = setuptools_source
if options.accept_buildout_test_releases:
args.insert(0, 'buildout:accept-buildout-test-releases=true')
try:
import pkg_resources
import setuptools # A flag. Sometimes pkg_resources is installed alone.
if not hasattr(pkg_resources, '_distribute'):
raise ImportError
except ImportError:
ez_code = urllib2.urlopen(
options.setup_source).read().replace('\r\n', '\n')
ez = {}
exec ez_code in ez
setup_args = dict(to_dir=eggs_dir, download_delay=0)
if options.download_base:
setup_args['download_base'] = options.download_base
if options.use_distribute:
setup_args['no_fake'] = True
if sys.version_info[:2] == (2, 4):
setup_args['version'] = '0.6.32'
ez['use_setuptools'](**setup_args)
if 'pkg_resources' in sys.modules:
reload(sys.modules['pkg_resources'])
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)
cmd = [quote(sys.executable),
'-c',
quote('from setuptools.command.easy_install import main; main()'),
'-mqNxd',
quote(eggs_dir)]
if not has_broken_dash_S:
cmd.insert(1, '-S')
find_links = options.download_base
if not find_links:
find_links = os.environ.get('bootstrap-testing-find-links')
if not find_links and options.accept_buildout_test_releases:
find_links = 'http://downloads.buildout.org/'
if find_links:
cmd.extend(['-f', quote(find_links)])
if options.use_distribute:
setup_requirement = 'distribute'
else:
setup_requirement = 'setuptools'
ws = pkg_resources.working_set
setup_requirement_path = ws.find(
pkg_resources.Requirement.parse(setup_requirement)).location
env = dict(
os.environ,
PYTHONPATH=setup_requirement_path)
requirement = 'zc.buildout'
version = options.version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
import setuptools.package_index
_final_parts = '*final-', '*final'
def _final_version(parsed_version):
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True
index = setuptools.package_index.PackageIndex(
search_path=[setup_requirement_path])
if find_links:
index.add_find_links((find_links,))
req = pkg_resources.Requirement.parse(requirement)
if index.obtain(req) is not None:
best = []
bestv = None
for dist in index[req.project_name]:
distv = dist.parsed_version
if distv >= pkg_resources.parse_version('2dev'):
continue
if _final_version(distv):
if bestv is None or distv > bestv:
best = [dist]
bestv = distv
elif distv == bestv:
best.append(dist)
if best:
best.sort()
version = best[-1].version
if version:
requirement += '=='+version
else:
requirement += '<2dev'
cmd.append(requirement)
if is_jython:
import subprocess
exitcode = subprocess.Popen(cmd, env=env).wait()
else: # Windows prefers this, apparently; otherwise we would prefer subprocess
exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
if exitcode != 0:
sys.stdout.flush()
sys.stderr.flush()
print ("An error occurred when trying to install zc.buildout. "
"Look above this message for any errors that "
"were output by easy_install.")
sys.exit(exitcode)
ws.add_entry(eggs_dir)
ws.require(requirement)
import zc.buildout.buildout
# If there isn't already a command in the args, add bootstrap
if not [a for a in args if '=' not in a]:
args.append('bootstrap')
# if -c was provided, we push it back into args for buildout's main function
if options.config_file is not None:
args[0:0] = ['-c', options.config_file]
zc.buildout.buildout.main(args)
if not options.eggs: # clean up temporary egg directory
shutil.rmtree(eggs_dir)
z3c.autoinclude-0.3.5/buildout.cfg 0000644 0000000 0000000 00000000276 12214252576 015202 0 ustar 0000000 0000000 [buildout]
develop = .
parts = devpython test
[devpython]
recipe = zc.recipe.egg
interpreter = devpython
eggs = z3c.autoinclude
[test]
recipe = zc.recipe.testrunner
eggs = z3c.autoinclude
z3c.autoinclude-0.3.5/CHANGES.rst 0000644 0000000 0000000 00000006336 12214252576 014477 0 ustar 0000000 0000000 Changes
=======
0.3.5 (2013-09-12)
------------------
* If a module cannot be resolved, but raises ``ImportError``, log a
warn and continue. This fixes an issue where the determining the
includable packages would fail due to a problem with the importation
of one or potentially more modules. An example is the ``gobject``
module which provides a Python binding to ``GObject``. In a recent
API deprecation, one is no longer allowed to both import ``gi`` and
``gobject``.
0.3.4 (2011-03-11)
------------------
* Remove unnecessary distribution lookup in the PluginFinder.
0.3.3 (2010-05-06)
------------------
* Ignore case in tests in order to pass tests on Windows.
* Clearly specify license as ZPL (not public domain, as it was
claiming before).
0.3.2 (2009-12-19)
------------------
* Let `subpackageDottedNames` always return a sorted list of package names as
`os.listdir` doesn't on some platforms.
0.3.1 (2009-05-04)
------------------
* z3c.autoinclude no longer (spuriously) depends on PasteScript.
0.3 (2009-03-03)
----------------
* Allow virtual namespace packages like 'plone' to be specified for the
package. I think this may need more thought for the dependency case.
* Allow ZCML ``includePlugins`` directive to specify a particular ZCML file to
try to load from plugins, so that loading of meta, configure and overrides
can be split across three ZCML files if desired. You can specify a file like:
.
* Provide a separate ``includePluginsOverrides`` directive to be used when
loading overrides, and no longer look for 'overrides.zcml' files by default
with ``includePlugins``.
* Removed the deprecated ``autoinclude`` and ``autoincludeOverrides``
directives.
* Allow autoinclusion to be disabled by setting
`os.environ['Z3C_AUTOINCLUDE_PLUGINS_DISABLED']` and
`os.environ['Z3C_AUTOINCLUDE_DEPENDENCIES_DISABLED']`, potentially useful for
test runners or debugging sessions. See
http://lists.plone.org/pipermail/framework-team/2009-February/002689.html for
discussion.
0.2.2 (2008-04-22)
------------------
* Gracefully catch KeyErrors in ``namespaceForDottedName``; get_metadata_lines
will sometimes throw this for certain distribution types, apparently. In
particular, some systems' version of Python itself will be wrapped in a
distribution which throws this error, resulting in system-dependent
unresumable breakage of z3c.autoinclude prior to this fix.
0.2.1 (2008-04-21)
------------------
* Fixed bug which prevented proper inclusion of packages when the base
package's namespace has been extended by other installed packages.
* Rewrote ``distributionForPackage`` function.
* Added additional tests for ``includePlugins`` and utility functions.
* Fixed bug which made z3c.autoinclude look for ZCML in namespaces of nested
namespace packages (eg, if there happened to -- improperly -- be an
x/y/configure.zcml in a x.y.z package with an x.y namespace, it would have
been included; this is incorrect.)
0.2 (2008-04-18)
----------------
* Added new directive ``includePlugins``.
* Renamed ``autoinclude`` directive to ``includeDependencies``.
* Deprecated ``autoinclude`` directive.
0.1 (2008-02-25)
----------------
* Initial public release.
z3c.autoinclude-0.3.5/COPYRIGHT.rst 0000644 0000000 0000000 00000000040 12214252576 014761 0 ustar 0000000 0000000 Zope Foundation and Contributors z3c.autoinclude-0.3.5/LICENSE.rst 0000644 0000000 0000000 00000004026 12214252576 014503 0 ustar 0000000 0000000 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.
z3c.autoinclude-0.3.5/MANIFEST.in 0000644 0000000 0000000 00000000335 12214252576 014424 0 ustar 0000000 0000000 include *.rst
include *.txt
recursive-include src *
global-exclude *.pyc
global-exclude *.pyo
prune src/z3c/autoinclude/tests/*/build
prune src/z3c/autoinclude/tests/*/dist
prune src/z3c/autoinclude/tests/*/*.egg-info
z3c.autoinclude-0.3.5/PKG-INFO 0000644 0000000 0000000 00000021753 12214252610 013757 0 ustar 0000000 0000000 Metadata-Version: 1.1
Name: z3c.autoinclude
Version: 0.3.5
Summary: Automatically include ZCML
Home-page: http://pypi.python.org/pypi/z3c.autoinclude
Author: Zope Foundation and Contributors
Author-email: zope-dev@zope.org
License: ZPL
Description: Overview
========
This package adds two new ZCML directives to automatically detect
ZCML files to include: "includeDependencies" and "includePlugins".
When you want to include a Zope-based package in your application, you
have to repeat yourself in two places: you have to add the package
itself (in a setup.py, buildout, etc) and you also have to include its
ZCML with an directive or a package-includes slug. Because
you have to repeat yourself, you can easily make an error where you
add a new package but forget to include its ZCML.
z3c.autoinclude lets you circumvent this error-prone process with
automatic detection and inclusion of ZCML files.
includeDependencies
-------------------
The "includeDependencies" directive searches through the dependencies
in your setup.py file (install_requires), and includes the ZCML files
in those packages that it finds. Inclusion order matches the order in
the setup.py file. You can pass a path for the package you want to
include dependencies for, but typically you pass in the current
package, as follows::
With this directive, you no longer have to add an explicit ```` for every new dependency of your project.
Grok_ and grokproject_ use this functionality out of the box. The
grokproject command will automatically add the ``includeDependencies``
directive in the ZCML of the project it generates. You can then stop
worrying about manual ZCML inclusion in the vast majority of cases.
includePlugins
--------------
The "includePlugins" directive uses entry points to find installed
packages that broadcast themselves as plugins to a particular base
package. You can pass a path for the package you want to include
plugins for, but typically you pass in the current package, as
follows::
To broadcast a package as a plugin to a base package called "my_base",
add the following lines to the plugin package's ``setup.py``::
entry_points="""
[z3c.autoinclude.plugin]
target = my_base
"""
The Details
===========
Setup
-----
To make the z3c.autoinclude directives available for use in your
application or framework, you need to include it (in your
``meta.zcml`` for instance), like this::
Grok already does this for you automatically.
Disabling z3c.autoinclude
-------------------------
It is often useful to disable z3c.autoinclude's functionality for
debugging purposes or test runs. To disable autoinclusion, set
the environment variables "Z3C_AUTOINCLUDE_DEPENDENCIES_DISABLED" and
"Z3C_AUTOINCLUDE_PLUGINS_DISABLED".
When autoinclusion is disabled, the autoinclusion directives will
issue a warning to the log and do nothing.
ZCML Filenames
--------------
The includeDependencies directive automatically includes
``configure.zcml`` and ``meta.zcml`` files that live in the main
package directories. For automatic inclusion of dependencies'
overrides, there is an directive.
In some cases, a package may use unusual names or
locations for its ZCML files. In that case you will need to modify
your package's ``configure.zcml`` and ``meta.zcml`` yourself to
include the ZCML using the manual ``include`` directive.
The includePlugins directive automatically includes ``configure.zcml``
and ``meta.zcml`` files by default, and the includePluginsOverrides
directive automatically includes ``overrides.zcml`` files by default.
But, like "", these directives also have an optional "file"
parameter, so you can automatically include all ``foo.zcml`` files in
your package's plugins like this::
The includeDependencies directives will soon offer this option as well.
.. _Grok: http://grok.zope.org
.. _grokproject: http://pypi.python.org/pypi/grokproject
Changes
=======
0.3.5 (2013-09-12)
------------------
* If a module cannot be resolved, but raises ``ImportError``, log a
warn and continue. This fixes an issue where the determining the
includable packages would fail due to a problem with the importation
of one or potentially more modules. An example is the ``gobject``
module which provides a Python binding to ``GObject``. In a recent
API deprecation, one is no longer allowed to both import ``gi`` and
``gobject``.
0.3.4 (2011-03-11)
------------------
* Remove unnecessary distribution lookup in the PluginFinder.
0.3.3 (2010-05-06)
------------------
* Ignore case in tests in order to pass tests on Windows.
* Clearly specify license as ZPL (not public domain, as it was
claiming before).
0.3.2 (2009-12-19)
------------------
* Let `subpackageDottedNames` always return a sorted list of package names as
`os.listdir` doesn't on some platforms.
0.3.1 (2009-05-04)
------------------
* z3c.autoinclude no longer (spuriously) depends on PasteScript.
0.3 (2009-03-03)
----------------
* Allow virtual namespace packages like 'plone' to be specified for the
package. I think this may need more thought for the dependency case.
* Allow ZCML ``includePlugins`` directive to specify a particular ZCML file to
try to load from plugins, so that loading of meta, configure and overrides
can be split across three ZCML files if desired. You can specify a file like:
.
* Provide a separate ``includePluginsOverrides`` directive to be used when
loading overrides, and no longer look for 'overrides.zcml' files by default
with ``includePlugins``.
* Removed the deprecated ``autoinclude`` and ``autoincludeOverrides``
directives.
* Allow autoinclusion to be disabled by setting
`os.environ['Z3C_AUTOINCLUDE_PLUGINS_DISABLED']` and
`os.environ['Z3C_AUTOINCLUDE_DEPENDENCIES_DISABLED']`, potentially useful for
test runners or debugging sessions. See
http://lists.plone.org/pipermail/framework-team/2009-February/002689.html for
discussion.
0.2.2 (2008-04-22)
------------------
* Gracefully catch KeyErrors in ``namespaceForDottedName``; get_metadata_lines
will sometimes throw this for certain distribution types, apparently. In
particular, some systems' version of Python itself will be wrapped in a
distribution which throws this error, resulting in system-dependent
unresumable breakage of z3c.autoinclude prior to this fix.
0.2.1 (2008-04-21)
------------------
* Fixed bug which prevented proper inclusion of packages when the base
package's namespace has been extended by other installed packages.
* Rewrote ``distributionForPackage`` function.
* Added additional tests for ``includePlugins`` and utility functions.
* Fixed bug which made z3c.autoinclude look for ZCML in namespaces of nested
namespace packages (eg, if there happened to -- improperly -- be an
x/y/configure.zcml in a x.y.z package with an x.y namespace, it would have
been included; this is incorrect.)
0.2 (2008-04-18)
----------------
* Added new directive ``includePlugins``.
* Renamed ``autoinclude`` directive to ``includeDependencies``.
* Deprecated ``autoinclude`` directive.
0.1 (2008-02-25)
----------------
* Initial public release.
Platform: UNKNOWN
Classifier: Framework :: Zope3
Classifier: Programming Language :: Python
z3c.autoinclude-0.3.5/README.rst 0000644 0000000 0000000 00000007466 12214252576 014371 0 ustar 0000000 0000000 Overview
========
This package adds two new ZCML directives to automatically detect
ZCML files to include: "includeDependencies" and "includePlugins".
When you want to include a Zope-based package in your application, you
have to repeat yourself in two places: you have to add the package
itself (in a setup.py, buildout, etc) and you also have to include its
ZCML with an directive or a package-includes slug. Because
you have to repeat yourself, you can easily make an error where you
add a new package but forget to include its ZCML.
z3c.autoinclude lets you circumvent this error-prone process with
automatic detection and inclusion of ZCML files.
includeDependencies
-------------------
The "includeDependencies" directive searches through the dependencies
in your setup.py file (install_requires), and includes the ZCML files
in those packages that it finds. Inclusion order matches the order in
the setup.py file. You can pass a path for the package you want to
include dependencies for, but typically you pass in the current
package, as follows::
With this directive, you no longer have to add an explicit ```` for every new dependency of your project.
Grok_ and grokproject_ use this functionality out of the box. The
grokproject command will automatically add the ``includeDependencies``
directive in the ZCML of the project it generates. You can then stop
worrying about manual ZCML inclusion in the vast majority of cases.
includePlugins
--------------
The "includePlugins" directive uses entry points to find installed
packages that broadcast themselves as plugins to a particular base
package. You can pass a path for the package you want to include
plugins for, but typically you pass in the current package, as
follows::
To broadcast a package as a plugin to a base package called "my_base",
add the following lines to the plugin package's ``setup.py``::
entry_points="""
[z3c.autoinclude.plugin]
target = my_base
"""
The Details
===========
Setup
-----
To make the z3c.autoinclude directives available for use in your
application or framework, you need to include it (in your
``meta.zcml`` for instance), like this::
Grok already does this for you automatically.
Disabling z3c.autoinclude
-------------------------
It is often useful to disable z3c.autoinclude's functionality for
debugging purposes or test runs. To disable autoinclusion, set
the environment variables "Z3C_AUTOINCLUDE_DEPENDENCIES_DISABLED" and
"Z3C_AUTOINCLUDE_PLUGINS_DISABLED".
When autoinclusion is disabled, the autoinclusion directives will
issue a warning to the log and do nothing.
ZCML Filenames
--------------
The includeDependencies directive automatically includes
``configure.zcml`` and ``meta.zcml`` files that live in the main
package directories. For automatic inclusion of dependencies'
overrides, there is an directive.
In some cases, a package may use unusual names or
locations for its ZCML files. In that case you will need to modify
your package's ``configure.zcml`` and ``meta.zcml`` yourself to
include the ZCML using the manual ``include`` directive.
The includePlugins directive automatically includes ``configure.zcml``
and ``meta.zcml`` files by default, and the includePluginsOverrides
directive automatically includes ``overrides.zcml`` files by default.
But, like "", these directives also have an optional "file"
parameter, so you can automatically include all ``foo.zcml`` files in
your package's plugins like this::
The includeDependencies directives will soon offer this option as well.
.. _Grok: http://grok.zope.org
.. _grokproject: http://pypi.python.org/pypi/grokproject
z3c.autoinclude-0.3.5/setup.cfg 0000644 0000000 0000000 00000000073 12214252610 014473 0 ustar 0000000 0000000 [egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
z3c.autoinclude-0.3.5/setup.py 0000644 0000000 0000000 00000002062 12214252576 014377 0 ustar 0000000 0000000 from setuptools import setup, find_packages
__version__ = '0.3.5'
setup(
name='z3c.autoinclude',
version=__version__,
description="Automatically include ZCML",
long_description=(open('README.rst').read() + "\n" +
open('CHANGES.rst').read()),
classifiers=[
"Framework :: Zope3",
"Programming Language :: Python",
],
keywords='',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
url='http://pypi.python.org/pypi/z3c.autoinclude',
license='ZPL',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['z3c'],
include_package_data=True,
zip_safe=False,
install_requires=[
'setuptools',
'zope.dottedname',
'zope.interface',
'zope.configuration',
'zope.schema',
'zc.buildout',
],
extras_require={'test': ['zc.buildout', 'zope.testing']},
entry_points="""
[console_scripts]
autoinclude-test = z3c.autoinclude.tests.tests:interactive_testing_env
""",
)
z3c.autoinclude-0.3.5/TODO.rst 0000644 0000000 0000000 00000001576 12214252576 014175 0 ustar 0000000 0000000 in no particular order, some notes on things that I think ought to happen to this code:
* Profiling. As far as I know, none has been done, and I expect that the code is *very* slow. Then, obviously, optimizations should be considered.
* Documentation. It's still fairly poor; I think the whole damn thing is just so abstract that I can't figure out how to talk about it.
* May as well figure out how to make a PasteScript template to auto-generate the entry point.
* Better debugging tools/APIs: to see what will be autoincluded, turn on and off autoinclusion for individual packages, and freeze a ZCML file capturing autoinclusion information a la pip.
One day I also want to add another directive to autoinclude subpackages' ZCML; this is a frequent annoyance for me (see https://svn.openplans.org/svn/opencore/trunk/opencore/configuration/configure.zcml for an illustrative example)
z3c.autoinclude-0.3.5/src/z3c/__init__.py 0000644 0000000 0000000 00000000070 12214252576 016261 0 ustar 0000000 0000000 __import__('pkg_resources').declare_namespace(__name__)
z3c.autoinclude-0.3.5/src/z3c/autoinclude/__init__.py 0000644 0000000 0000000 00000000052 12214252576 020575 0 ustar 0000000 0000000 #
from dependency import package_includes
z3c.autoinclude-0.3.5/src/z3c/autoinclude/api.py 0000644 0000000 0000000 00000000736 12214252576 017620 0 ustar 0000000 0000000 import os
DEP_KEY = 'Z3C_AUTOINCLUDE_DEPENDENCIES_DISABLED'
PLUGIN_KEY = 'Z3C_AUTOINCLUDE_PLUGINS_DISABLED'
def dependencies_disabled():
return os.environ.has_key(DEP_KEY)
def disable_dependencies():
os.environ[DEP_KEY] = 'True'
def enable_dependencies():
del os.environ[DEP_KEY]
def plugins_disabled():
return os.environ.has_key(PLUGIN_KEY)
def disable_plugins():
os.environ[PLUGIN_KEY] = 'True'
def enable_dependencies():
del os.environ[PLUGIN_KEY]
z3c.autoinclude-0.3.5/src/z3c/autoinclude/dependency.py 0000644 0000000 0000000 00000003760 12214252576 021165 0 ustar 0000000 0000000 import os
import logging
from zope.dottedname.resolve import resolve
from pkg_resources import resource_exists
from pkg_resources import get_provider
from pkg_resources import get_distribution
from z3c.autoinclude.utils import DistributionManager
from z3c.autoinclude.utils import ZCMLInfo
class DependencyFinder(DistributionManager):
def includableInfo(self, zcml_to_look_for):
"""Return the packages in the dependencies which are includable.
zcml_to_look_for - a list of zcml filenames we are looking for
Returns a dictionary with the include candidates as keys, and lists
of dotted names of packages that contain the include candidates as
values.
"""
result = ZCMLInfo(zcml_to_look_for)
for req in self.context.requires():
dist_manager = DistributionManager(get_provider(req))
for dotted_name in dist_manager.dottedNames():
try:
module = resolve(dotted_name)
except ImportError, exc:
logging.getLogger("z3c.autoinclude").warn(
"resolve(%r) raised import error: %s" % (dotted_name, exc))
continue
for candidate in zcml_to_look_for:
candidate_path = os.path.join(
os.path.dirname(module.__file__), candidate)
if os.path.isfile(candidate_path):
result[candidate].append(dotted_name)
return result
def package_includes(project_name, zcml_filenames=None):
"""
Convenience function for finding zcml to load from requirements for
a given project. Takes a project name. DistributionNotFound errors
will be raised for uninstalled projects.
"""
if zcml_filenames is None:
zcml_filenames = ['meta.zcml', 'configure.zcml', 'overrides.zcml']
dist = get_distribution(project_name)
include_finder = DependencyFinder(dist)
return include_finder.includableInfo(zcml_filenames)
z3c.autoinclude-0.3.5/src/z3c/autoinclude/dependency.txt 0000644 0000000 0000000 00000013041 12214252576 021345 0 ustar 0000000 0000000 Automatic inclusion of package dependencies
===========================================
The z3c.autoinclude.dependency module uses an egg's install_requires
information (in the project's setup.py) to find and implicitly load
zcml from all dependencies of a project.
We have created a test environment to simulate setuptools
dependencies.
``APackage`` depends on ``BCPackage``
``BCPackage`` depends on ``SiblingPackage``
Given the distribution for the project named ``APackage``, we can ask
for the requirements of that distribution::
>>> import a
>>> from z3c.autoinclude.utils import distributionForPackage
>>> a_dist = distributionForPackage(a)
>>> reqs = a_dist.requires()
>>> pprint(sorted(reqs, key=lambda r:r.project_name))
[Requirement.parse('BCPackage'),
Requirement.parse('TestDirective'),
Requirement.parse('z3c.autoinclude')]
We can turn this requirement into a distribution::
>>> from pkg_resources import get_provider
>>> b_dist = get_provider(reqs[0])
We can adapt a distribution to a DependencyFinder::
>>> from z3c.autoinclude.dependency import DependencyFinder
>>> a_include_finder = DependencyFinder(a_dist)
>>> b_include_finder = DependencyFinder(b_dist)
>>> import x.y.z
>>> xyz_dist = distributionForPackage(x.y.z)
>>> xyz_include_finder = DependencyFinder(xyz_dist)
>>> import F.G
>>> sibling_dist = distributionForPackage(F.G)
>>> sibling_include_finder = DependencyFinder(sibling_dist)
The include finder provides functionality to determine what namespace
packages exist in the distribution. In the case of ``APackage``, there
are no namespace packages::
>>> a_include_finder.namespaceDottedNames()
[]
``BPackage`` does have a namespace package, ``b``::
>>> b_include_finder.namespaceDottedNames()
['b']
``XYZPackage`` has a namespace package too, ``x.y`` (``x`` is also
a namespace package)::
>>> xyz_include_finder.namespaceDottedNames()
['x', 'x.y']
We can also get the dotted names of the actual packages that we want
to inspect in a distribution. For a project without namespace packages,
this will be the packages directly in the packages::
>>> a_include_finder.dottedNames()
['a']
For a project with namespace packages, it will be the packages that
are in the namespace packages::
>>> b_include_finder.dottedNames()
['b.c']
For a nested namespace package, it should still be the innermost package::
>>> xyz_include_finder.dottedNames()
['x.y.z']
What we need to know in the end is which packages in the requirements
of a distribution have files we want to include (``configure.zcml``,
``meta.zcml``). So, given a distribution, let's retrieve all packages
that it depends on that have ``configure.zcml`` or ``meta.zcml``.
Note that the individual lists within ``includableInfo`` preserve the
package order defined in ``setup.py``::
>>> a_include_finder.includableInfo(['configure.zcml', 'meta.zcml'])
{'configure.zcml': ['b.c'], 'meta.zcml': ['z3c.autoinclude', 'testdirective']}
For a nested namespace package with two siblings ``SiblingPackage``,
we should get the same expected results. The sibling package
``SiblingPackage`` does have a namespace package::
>>> sibling_include_finder.namespaceDottedNames()
['F']
For a namespace package with 2 sibling namespaces, we get both sibling
packages::
>>> sibling_include_finder.dottedNames()
['F.G', 'F.H']
And we should be able to pick up the files we need to include from
both dotted names::
>>> pprint(b_include_finder.includableInfo(['configure.zcml',
... 'meta.zcml']))
{'configure.zcml': ['F.H'], 'meta.zcml': ['testdirective', 'F.G', 'F.H']}
``APackage`` depends on ``BCPackage``, which depends on
``SiblingPackage``. ``APackage`` and ``BCPackage`` both contain the
autoinclude directive, which will automatically include any meta.zcml
and configure.zcml files (in that order) that their dependencies
contain. These dependencies' zcml actually contain a test directive
that will append a logging message to a global variable in
testdirective.zcml. So let's trigger the loading of the configure.zcml
in ``APackage`` and see whether its ``BCPackage`` dependency, and
``BCPackage``'s dependencies, were indeed loaded and in the correct
order::
>>> from pkg_resources import resource_filename
>>> from zope.configuration import xmlconfig
>>> import a
>>> dummy = xmlconfig.file(resource_filename('a', 'configure.zcml'),
... package=a)
>>> from testdirective.zcml import test_log
>>> pprint(test_log)
[u'f.g meta has been loaded',
u'f.h has been loaded',
u'BCPackage has been loaded']
There is also a directive for including overrides, which calls
``autoIncludeOverridesDirective``; however, I have no idea how to test
this.
Finally, there is a convenience API for finding the files we need to
include from the requirements of a given package::
>>> from z3c.autoinclude import package_includes
>>> pprint(package_includes('BCPackage'))
{'configure.zcml': ['F.H'],
'meta.zcml': ['testdirective', 'F.G', 'F.H'],
'overrides.zcml': []}
As with ``includableInfo``, we can also supply a list of ZCML filenames to search for::
>>> pprint(package_includes('BCPackage', ['configure.zcml', 'silly.zcml']))
{'configure.zcml': ['F.H'], 'silly.zcml': []}
Note that it will not catch DistributionNotFound errors::
>>> package_includes('NonexistentPackage')
Traceback (most recent call last):
...
DistributionNotFound: NonexistentPackage
z3c.autoinclude-0.3.5/src/z3c/autoinclude/meta.zcml 0000644 0000000 0000000 00000001560 12214252576 020306 0 ustar 0000000 0000000